# HG changeset patch # User Sylvain Thénault # Date 1304344770 -7200 # Node ID e559ade02665d72823694e17a6ca5801f949511c # Parent 2af1a4cecda55b7ad238cb8c84b225f2c44a0883# Parent b6fd14ee491e16502f25a07de12258a3fe266b17 backport stable diff -r 2af1a4cecda5 -r e559ade02665 doc/book/en/tutorials/advanced/part02_security.rst --- a/doc/book/en/tutorials/advanced/part02_security.rst Mon May 02 15:07:13 2011 +0200 +++ b/doc/book/en/tutorials/advanced/part02_security.rst Mon May 02 15:59:30 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 2af1a4cecda5 -r e559ade02665 entity.py --- a/entity.py Mon May 02 15:07:13 2011 +0200 +++ b/entity.py Mon May 02 15:59:30 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 2af1a4cecda5 -r e559ade02665 server/hook.py --- a/server/hook.py Mon May 02 15:07:13 2011 +0200 +++ b/server/hook.py Mon May 02 15:59:30 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 diff -r 2af1a4cecda5 -r e559ade02665 server/migractions.py --- a/server/migractions.py Mon May 02 15:07:13 2011 +0200 +++ b/server/migractions.py Mon May 02 15:59:30 2011 +0200 @@ -1249,6 +1249,12 @@ self.commit() return wf + def cmd_get_workflow_for(self, etype): + """return default workflow for the given entity type""" + rset = self.rqlexec('Workflow X WHERE ET default_workflow X, ET name %(et)s', + {'et': etype}) + return rset.get_entity(0, 0) + # XXX remove once cmd_add_[state|transition] are removed def _get_or_create_wf(self, etypes): if not isinstance(etypes, (list, tuple)): diff -r 2af1a4cecda5 -r e559ade02665 server/msplanner.py --- a/server/msplanner.py Mon May 02 15:07:13 2011 +0200 +++ b/server/msplanner.py Mon May 02 15:59:30 2011 +0200 @@ -483,7 +483,7 @@ else: var = vref.variable for rel in var.stinfo['relations'] - var.stinfo['rhsrelations']: - if rel.r_type in ('eid', 'name'): + if rel.r_type in ('eid', 'name') and not rel.neged(strict=True): if rel.r_type == 'eid': slist = sourceeids else: diff -r 2af1a4cecda5 -r e559ade02665 web/facet.py --- a/web/facet.py Mon May 02 15:07:13 2011 +0200 +++ b/web/facet.py Mon May 02 15:59:30 2011 +0200 @@ -451,11 +451,6 @@ return False -def encode(obj, encoding): - if isinstance(obj, unicode): - return obj.encode(encoding) - return unicode(obj).encode(encoding) - class RelationFacet(VocabularyFacet): """Base facet to filter some entities according to other entities to which they are related. Create concret facet by inheriting from this class an then @@ -610,8 +605,7 @@ insert_attr_select_relation( rqlst, self.filtered_variable, self.rtype, self.role, self.target_attr, select_target_entity=False) - encoding = self._cw.encoding - values = [encode(x, encoding) for x, in self.rqlexec(rqlst.as_string())] + values = [unicode(x) for x, in self.rqlexec(rqlst.as_string())] except: self.exception('while computing values for %s', self) return [] @@ -1022,6 +1016,7 @@ rtype = 'has_image' role = 'subject' """ + __select__ = partial_relation_possible() & match_context_prop() rtype = None # override me in subclass role = 'subject' # role of filtered entity in the relation diff -r 2af1a4cecda5 -r e559ade02665 web/views/baseviews.py --- a/web/views/baseviews.py Mon May 02 15:07:13 2011 +0200 +++ b/web/views/baseviews.py Mon May 02 15:59:30 2011 +0200 @@ -201,8 +201,15 @@ self.w(u'%s' % self._cw.format_date(entity.creation_date)) if entity.creator: - self.w(u' %s ' % _('by')) + if entity.creation_date: + self.w(u' %s ' % _('by')) + else: + self.w(u' %s ' % _('created by')) self.w(u'%s' % entity.creator.name()) + meta = entity.cw_metainformation() + if meta['source']['uri'] != 'system': + self.w(u' (%s' % _('from source')) + self.w(u' %s)' % meta['source']['uri']) self.w(u'') diff -r 2af1a4cecda5 -r e559ade02665 web/views/cwuser.py --- a/web/views/cwuser.py Mon May 02 15:07:13 2011 +0200 +++ b/web/views/cwuser.py Mon May 02 15:59:30 2011 +0200 @@ -170,7 +170,11 @@ class CWUserManagementView(StartupView): __regid__ = 'cw.user-management' - rql = ('Any U, F, S, U, L ORDERBY L WHERE U is CWUser, U login L, U firstname F, U surname S') + rql = ('Any U,USN,F,S,U,UAA,UDS, L,UAA,UDSN ORDERBY L WHERE U is CWUser, ' + 'U login L, U firstname F, U surname S, ' + 'U in_state US, US name USN, ' + 'U primary_email UA?, UA address UAA, ' + 'U cw_source UDS, US name UDSN') title = _('users and groups management') def call(self, **kwargs): @@ -191,10 +195,14 @@ def call(self, **kwargs): headers = (display_name(self._cw, 'CWUser', 'plural'), + display_name(self._cw, 'in_state'), self._cw._('firstname'), self._cw._('surname'), - display_name(self._cw, 'CWGroup', 'plural')) + display_name(self._cw, 'CWGroup', 'plural'), + display_name(self._cw, 'primary_email'), + display_name(self._cw, 'CWSource')) super(CWUserTable, self).call( - paginate=True, cellvids={3: 'cw.user-table.group-cell'}, + paginate=True, displayfilter=True, + cellvids={4: 'cw.user-table.group-cell'}, headers=headers, **kwargs)