[pyramid] Retrieve user's groups using a custom RQL instead of user's groups property
With cubicweb 3.24, user.groups is set lazily and so retrieving it at this point
will cause a traceback because the connection is not yet entered.
Also, user doesn't accept anymore groups and properties arguments.
--- a/cubicweb/pyramid/core.py Mon Jun 06 16:08:03 2016 +0200
+++ b/cubicweb/pyramid/core.py Mon Jun 06 15:37:01 2016 +0200
@@ -348,7 +348,11 @@
log.exception("Failed")
raise
- return session.user.groups
+ with session.new_cnx() as cnx:
+ with cnx.security_enabled(read=False):
+ return set(group for group, in cnx.execute(
+ 'Any GN WHERE U in_group G, G name GN, U eid %(userid)s',
+ {'userid': login}))
def includeme(config):
--- a/cubicweb/pyramid/tools.py Mon Jun 06 16:08:03 2016 +0200
+++ b/cubicweb/pyramid/tools.py Mon Jun 06 15:37:01 2016 +0200
@@ -27,10 +27,7 @@
None,
rset=user.cw_rset.copy(),
row=user.cw_row,
- col=user.cw_col,
- groups=set(user._groups) if hasattr(user, '_groups') else None,
- properties=dict(user._properties)
- if hasattr(user, '_properties') else None)
+ col=user.cw_col)
clone.cw_attr_cache = dict(user.cw_attr_cache)
return clone