[cwpermission, cwgroup] convenience method on CWGroup to grant a local permission (ie CWPermission) on an entity
--- a/entities/authobjs.py Wed May 11 17:05:59 2011 +0200
+++ b/entities/authobjs.py Wed May 11 17:06:41 2011 +0200
@@ -29,6 +29,21 @@
fetch_attrs, fetch_order = fetch_config(['name'])
fetch_unrelated_order = fetch_order
+ def grant_permission(self, entity, pname, plabel=None):
+ """grant local `pname` permission on `entity` to this group using
+ :class:`CWPermission`.
+
+ If a similar permission already exists, add the group to it, else create
+ a new one.
+ """
+ if not self._cw.execute(
+ 'SET X require_group G WHERE E eid %(e)s, G eid %(g)s, '
+ 'E require_permission X, X name %(name)s, X label %(label)s',
+ {'e': entity.eid, 'g': self.eid,
+ 'name': pname, 'label': plabel}):
+ self._cw.create_entity('CWPermission', name=pname, label=plabel,
+ require_group=self,
+ reverse_require_permission=entity)
class CWUser(AnyEntity):