entities/authobjs.py
brancholdstable
changeset 7676 cc3987eb793c
parent 7371 233b761201e4
child 7780 a1d5365fefc1
--- a/entities/authobjs.py	Mon May 16 16:24:00 2011 +0200
+++ b/entities/authobjs.py	Wed Jul 20 18:21:47 2011 +0200
@@ -29,9 +29,21 @@
     fetch_attrs, fetch_order = fetch_config(['name'])
     fetch_unrelated_order = fetch_order
 
-    def db_key_name(self):
-        """XXX goa specific"""
-        return self.get('name')
+    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):
@@ -156,10 +168,6 @@
 
     dc_long_title = name
 
-    def db_key_name(self):
-        """XXX goa specific"""
-        return self.get('login')
-
 from logilab.common.deprecation import class_renamed
 EUser = class_renamed('EUser', CWUser)
 EGroup = class_renamed('EGroup', CWGroup)