--- a/hooks/security.py Sat Oct 09 00:05:49 2010 +0200
+++ b/hooks/security.py Sat Oct 09 00:05:50 2010 +0200
@@ -45,23 +45,20 @@
rdef.check_perm(session, 'update', eid=eid)
-class _CheckEntityPermissionOp(hook.LateOperation):
+class CheckEntityPermissionOp(hook.DataOperationMixIn, hook.LateOperation):
def precommit_event(self):
- #print 'CheckEntityPermissionOp', self.session.user, self.entity, self.action
session = self.session
- for values in session.transaction_data.pop('check_entity_perm_op'):
- eid, action, edited = values
+ for eid, action, edited in self.get_data():
entity = session.entity_from_eid(eid)
entity.cw_check_perm(action)
check_entity_attributes(session, entity, edited,
- creation=self.creation)
+ creation=(action == 'add'))
-class _CheckRelationPermissionOp(hook.LateOperation):
+class CheckRelationPermissionOp(hook.DataOperationMixIn, hook.LateOperation):
def precommit_event(self):
session = self.session
- for args in session.transaction_data.pop('check_relation_perm_op'):
- action, rschema, eidfrom, eidto = args
+ for action, rschema, eidfrom, eidto in self.get_data():
rdef = rschema.rdef(session.describe(eidfrom)[0],
session.describe(eidto)[0])
rdef.check_perm(session, action, fromeid=eidfrom, toeid=eidto)
@@ -85,9 +82,8 @@
events = ('after_add_entity',)
def __call__(self):
- hook.set_operation(self._cw, 'check_entity_perm_op',
- (self.entity.eid, 'add', self.entity.cw_edited),
- _CheckEntityPermissionOp, creation=True)
+ CheckEntityPermissionOp.get_instance(self._cw).add_data(
+ (self.entity.eid, 'add', self.entity.cw_edited) )
class AfterUpdateEntitySecurityHook(SecurityHook):
@@ -104,9 +100,8 @@
# save back editedattrs in case the entity is reedited later in the
# same transaction, which will lead to cw_edited being
# overwritten
- hook.set_operation(self._cw, 'check_entity_perm_op',
- (self.entity.eid, 'update', self.entity.cw_edited),
- _CheckEntityPermissionOp, creation=False)
+ CheckEntityPermissionOp.get_instance(self._cw).add_data(
+ (self.entity.eid, 'update', self.entity.cw_edited) )
class BeforeDelEntitySecurityHook(SecurityHook):
@@ -143,9 +138,8 @@
return
rschema = self._cw.repo.schema[self.rtype]
if self.rtype in ON_COMMIT_ADD_RELATIONS:
- hook.set_operation(self._cw, 'check_relation_perm_op',
- ('add', rschema, self.eidfrom, self.eidto),
- _CheckRelationPermissionOp)
+ CheckRelationPermissionOp.get_instance(self._cw).add_data(
+ ('add', rschema, self.eidfrom, self.eidto) )
else:
rdef = rschema.rdef(self._cw.describe(self.eidfrom)[0],
self._cw.describe(self.eidto)[0])