# HG changeset patch # User Nicolas Chauvat # Date 1304098285 -7200 # Node ID b156200ebc9dc83d888c36a68f8b3d94625b8490 # Parent 571b29842ef1dcddb78795894b7c118fff47b8bc# Parent 601ad29268ab431f13501fd5a55e032454fffa71 merge changes from oldstable diff -r 571b29842ef1 -r b156200ebc9d doc/book/en/tutorials/advanced/part02_security.rst --- a/doc/book/en/tutorials/advanced/part02_security.rst Fri Apr 29 10:29:25 2011 +0200 +++ b/doc/book/en/tutorials/advanced/part02_security.rst Fri Apr 29 19:31:25 2011 +0200 @@ -190,9 +190,10 @@ from cubicweb.selectors import is_instance from cubicweb.server import hook - class SetVisibilityOp(hook.Operation): + class SetVisibilityOp(hook.DataOperationMixIn, hook.Operation): + def precommit_event(self): - for eid in self.session.transaction_data.pop('pending_visibility'): + for eid in self.get_data(): entity = self.session.entity_from_eid(eid) if entity.visibility == 'parent': entity.set_attributes(visibility=u'authenticated') @@ -201,9 +202,9 @@ __regid__ = 'sytweb.setvisibility' __select__ = hook.Hook.__select__ & is_instance('Folder', 'File', 'Comment') events = ('after_add_entity',) + def __call__(self): - hook.set_operation(self._cw, 'pending_visibility', self.entity.eid, - SetVisibilityOp) + SetVisibilityOp.get_instance(self._cw).add_data(self.entity.eid) class SetParentVisibilityHook(hook.Hook): __regid__ = 'sytweb.setparentvisibility' @@ -240,7 +241,7 @@ - `self.entity` is the newly added entity on 'after_add_entity' events - `self.eidfrom` / `self.eidto` are the eid of the subject / object entity on - 'after_add_relatiohn' events (you may also get the relation type using + 'after_add_relation' events (you may also get the relation type using `self.rtype`) The `parent` visibility value is used to tell "propagate using parent security" @@ -381,7 +382,7 @@ test instance. The second one will be much quicker: .. sourcecode:: bash - + $ pytest unittest_sytweb.py ======================== unittest_sytweb.py ======================== . diff -r 571b29842ef1 -r b156200ebc9d entity.py --- a/entity.py Fri Apr 29 10:29:25 2011 +0200 +++ b/entity.py Fri Apr 29 19:31:25 2011 +0200 @@ -272,7 +272,7 @@ role = 'object' else: role = 'subject' - assert eschema.has_relation(attr, role) + assert eschema.has_relation(attr, role), '%s %s not found on %s' % (attr, role, eschema) rschema = eschema.subjrels[attr] if role == 'subject' else eschema.objrels[attr] if not rschema.final and isinstance(value, (tuple, list, set, frozenset)): if len(value) == 1: diff -r 571b29842ef1 -r b156200ebc9d server/hook.py --- a/server/hook.py Fri Apr 29 10:29:25 2011 +0200 +++ b/server/hook.py Fri Apr 29 19:31:25 2011 +0200 @@ -812,9 +812,9 @@ by redefining :meth:`_build_container` and :meth:`add_data` More optional parameters can be given to the `get_instance` operation, that - will be given to the operation constructer (though those parameters should - not vary accross different calls to this method for a same operation for - obvious reason). + will be given to the operation constructor (for obvious reasons those + parameters should not vary accross different calls to this method for a + given operation). .. Note:: For sanity reason `get_data` will reset the operation, so that once