merge
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 07 Dec 2009 17:17:22 +0100
changeset 4009 fa4189f2cf98
parent 4008 fce83937a885 (current diff)
parent 4007 91d11fda4aa0 (diff)
child 4010 b2d0b14a365d
merge
--- a/hooks/integrity.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/hooks/integrity.py	Mon Dec 07 17:17:22 2009 +0100
@@ -167,7 +167,7 @@
         entity = self.entity
         for attr in entity.edited_attributes:
             if schema.rschema(attr).final:
-                constraints = [c for c in entity.rdef(attr).constraints
+                constraints = [c for c in entity.e_schema.rdef(attr).constraints
                                if isinstance(c, (RQLUniqueConstraint, RQLConstraint))]
                 if constraints:
                     _CheckConstraintsOp(self._cw, constraints=constraints,
--- a/hooks/security.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/hooks/security.py	Mon Dec 07 17:17:22 2009 +0100
@@ -119,7 +119,7 @@
                                            eidfrom=self.eidfrom,
                                            eidto=self.eidto)
             else:
-                rdef = rschema.rdef(session.describe(self.eidfrom)[0],
-                                    session.describe(self.eidto)[0])
-                rdef.check_perm(session, 'add', fromeid=self.eidfrom, toeid=self.eidto)
+                rdef = rschema.rdef(self._cw.describe(self.eidfrom)[0],
+                                    self._cw.describe(self.eidto)[0])
+                rdef.check_perm(self._cw, 'add', fromeid=self.eidfrom, toeid=self.eidto)
 
--- a/hooks/syncschema.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/hooks/syncschema.py	Mon Dec 07 17:17:22 2009 +0100
@@ -781,7 +781,6 @@
     * register an operation to add the entity type to the instance's
       schema on commit
     """
-<<<<<<< /home/syt/src/fcubicweb/cubicweb/hooks/syncschema.py
     __regid__ = 'syncaddcwetype'
     events = ('after_add_entity',)
 
--- a/hooks/workflow.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/hooks/workflow.py	Mon Dec 07 17:17:22 2009 +0100
@@ -227,7 +227,7 @@
                     msg = session._("transition %s isn't allowed from %s") % (
                         _(tr.name), _(fromstate.name))
                     raise ValidationError(entity.eid, {'by_transition': msg})
-                 if not tr.may_be_fired(foreid):
+                if not tr.may_be_fired(foreid):
                     msg = session._("transition may not be fired")
                     raise ValidationError(entity.eid, {'by_transition': msg})
             if entity.get('to_state'):
--- a/schema.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/schema.py	Mon Dec 07 17:17:22 2009 +0100
@@ -425,28 +425,28 @@
     def has_perm(self, session, action, **kwargs):
         """return true if the action is granted globaly or localy"""
         if 'fromeid' in kwargs:
-            subjtype = session.describe(kwargs['fromeid'])
+            subjtype = session.describe(kwargs['fromeid'])[0]
         else:
             subjtype = None
         if 'toeid' in kwargs:
-            objtype = session.describe(kwargs['toeid'])
+            objtype = session.describe(kwargs['toeid'])[0]
         else:
             objtype = Nono
         if objtype and subjtype:
             return self.rdef(subjtype, objtype).has_perm(session, action, **kwargs)
         elif subjtype:
-            for tschema in rschema.targets(subjtype, 'subject'):
-                rdef = rschema.rdef(subjtype, tschema)
+            for tschema in self.targets(subjtype, 'subject'):
+                rdef = self.rdef(subjtype, tschema)
                 if not rdef.has_perm(action, req, **kwargs):
                     return False
         elif objtype:
-            for tschema in rschema.targets(objtype, 'object'):
-                rdef = rschema.rdef(tschema, objtype)
-                if not rdef.has_perm(action, req, **kwargs):
+            for tschema in self.targets(objtype, 'object'):
+                rdef = self.rdef(tschema, objtype)
+                if not rdef.has_perm(session, action, **kwargs):
                     return False
         else:
             for rdef in self.rdefs.itervalues():
-                if not rdef.has_perm(action, req, **kwargs):
+                if not rdef.has_perm(session, action, **kwargs):
                     return False
 
     @deprecated('use .rdef(subjtype, objtype).role_cardinality(role)')
@@ -527,6 +527,7 @@
                 self._eid_index[rdef.eid] = rdefs
             except AttributeError:
                 pass # not a serialized schema
+        return rdefs
 
     def del_relation_type(self, rtype):
         rschema = self.rschema(rtype)
--- a/schemas/base.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/schemas/base.py	Mon Dec 07 17:17:22 2009 +0100
@@ -135,30 +135,6 @@
     object = 'String'
 
 
-class CWProperty(EntityType):
-    """used for cubicweb configuration. Once a property has been created you
-    can't change the key.
-    """
-    __permissions__ = {
-        'read':   ('managers', 'users', 'guests'),
-        'add':    ('managers', 'users',),
-        'update': ('managers', 'owners',),
-        'delete': ('managers', 'owners',),
-        }
-    # key is a reserved word for mysql
-    pkey = String(required=True, internationalizable=True, maxsize=256,
-                  description=_('defines what\'s the property is applied for. '
-                                'You must select this first to be able to set '
-                                'value'))
-    value = String(internationalizable=True, maxsize=256)
-
-    for_user = SubjectRelation('CWUser', cardinality='?*', composite='object',
-                               description=_('user for which this property is '
-                                             'applying. If this relation is not '
-                                             'set, the property is considered as'
-                                             ' a global property'))
-
-
 # XXX find a better relation name
 class for_user(RelationType):
     """link a property to the user which want this property customization. Unless
--- a/schemas/bootstrap.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/schemas/bootstrap.py	Mon Dec 07 17:17:22 2009 +0100
@@ -177,7 +177,7 @@
     """used for cubicweb configuration. Once a property has been created you
     can't change the key.
     """
-    permissions = {
+    __permissions__ = {
         'read':   ('managers', 'users', 'guests'),
         'add':    ('managers', 'users',),
         'update': ('managers', 'owners',),
--- a/schemas/workflow.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/schemas/workflow.py	Mon Dec 07 17:17:22 2009 +0100
@@ -187,7 +187,7 @@
 
 class transition_of(RelationType):
     """link a transition to one or more workflow"""
-    permissions = META_RTYPE_PERMS
+    __permissions__ = META_RTYPE_PERMS
     inlined = True
 
 class subworkflow(RelationType):
--- a/server/schemaserial.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/server/schemaserial.py	Mon Dec 07 17:17:22 2009 +0100
@@ -183,7 +183,6 @@
                                  fulltext_container=ft_container, eid=eid)
         rschema = schema.add_relation_type(rtype)
         index[eid] = rschema
-        set_perms(rschema, permsdict.get(eid, {}))
     cstrsdict = deserialize_rdef_constraints(session)
     for values in session.execute(
         'Any X,SE,RT,OE,CARD,ORD,DESC,IDX,FTIDX,I18N,DFLT WHERE X is CWAttribute,'
@@ -202,7 +201,8 @@
                                   indexed=idx, fulltextindexed=ftidx,
                                   internationalizable=i18n,
                                   default=default, eid=rdefeid)
-        schema.add_relation_def(rdef)
+        rdefs = schema.add_relation_def(rdef)
+        set_perms(rdefs, permsdict.get(rdefeid, {}))
     for values in session.execute(
         'Any X,SE,RT,OE,CARD,ORD,DESC,C WHERE X is CWRelation, X relation_type RT,'
         'X cardinality CARD, X ordernum ORD, X description DESC, '
@@ -216,7 +216,8 @@
                                   order=ord, description=desc,
                                   composite=c, constraints=constraints,
                                   eid=rdefeid)
-        schema.add_relation_def(rdef)
+        rdefs = schema.add_relation_def(rdef)
+        set_perms(rdefs, permsdict.get(rdefeid, {}))
     schema.infer_specialization_rules()
     if _3_2_migration:
         _update_database(schema, sqlcu)
@@ -363,7 +364,7 @@
     amap = {'order': 'ordernum'}
     values = {}
     for prop, default in rschema.rproperty_defs(objtype).iteritems():
-        if prop in ('eid', 'constraints', 'uid', 'infered'):
+        if prop in ('eid', 'constraints', 'uid', 'infered', 'permissions'):
             continue
         value = props.get(prop, default)
         if prop in ('indexed', 'fulltextindexed', 'internationalizable'):
@@ -536,7 +537,7 @@
     else:
         # entity schema
         for rql, args in _erperms2rql(erschema, groupmapping):
-            args['name'] = str(eschema)
+            args['name'] = str(erschema)
             yield rql + 'X is CWEType, X name %(name)s', args
 
 def _erperms2rql(erschema, groupmapping):
@@ -550,7 +551,7 @@
             if isinstance(group_or_rqlexpr, basestring):
                 # group
                 try:
-                    yield ('SET X %s_permission Y WHERE Y eid %%(g)s' % action,
+                    yield ('SET X %s_permission Y WHERE Y eid %%(g)s, ' % action,
                            {'g': groupmapping[group_or_rqlexpr]})
                 except KeyError:
                     continue
--- a/server/session.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/server/session.py	Mon Dec 07 17:17:22 2009 +0100
@@ -242,7 +242,8 @@
         rschema = self.repo.schema[rtype]
         subjtype = self.describe(eidfrom)[0]
         objtype = self.describe(eidto)[0]
-        return rschema.rproperty(subjtype, objtype, rprop)
+        rdef = rschema.rdef(subjtype, objtype)
+        return rdef.get(rprop)
 
     # connection management ###################################################
 
--- a/sobjects/textparsers.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/sobjects/textparsers.py	Mon Dec 07 17:17:22 2009 +0100
@@ -21,7 +21,7 @@
     """analyze and extract information from plain text by calling registered
     text parsers
     """
-    id = 'textanalyzer'
+    __regid__ = 'textanalyzer'
 
     def parse(self, caller, text):
         for parsercls in self.req.vreg['components'].get('textparser', ()):
@@ -36,7 +36,7 @@
 
     method on the caller.
     """
-    id = 'textparser'
+    __regid__ = 'textparser'
     __abstract__ = True
 
     def parse(self, caller, text):
--- a/web/form.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/form.py	Mon Dec 07 17:17:22 2009 +0100
@@ -36,8 +36,6 @@
         return False
 
 
-<<<<<<< /home/syt/src/fcubicweb/cubicweb/web/form.py
-=======
 # XXX should disappear
 class FormMixIn(object):
     """abstract form mix-in
@@ -192,7 +190,6 @@
 
 ###############################################################################
 
->>>>>>> /tmp/form.py~other.xdns1y
 class metafieldsform(type):
     """metaclass for FieldsForm to retrieve fields defined as class attributes
     and put them into a single ordered list: '_fields_'.
--- a/web/request.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/request.py	Mon Dec 07 17:17:22 2009 +0100
@@ -87,7 +87,6 @@
         self.next_tabindex = self.tabindexgen.next
         # page id, set by htmlheader template
         self.pageid = None
-        self.varmaker = rqlvar_maker()
         self.datadir_url = self._datadir_url()
         self._set_pageid()
 
--- a/web/uicfg.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/uicfg.py	Mon Dec 07 17:17:22 2009 +0100
@@ -233,12 +233,13 @@
     return result
 
 def _card_and_comp(sschema, rschema, oschema, role):
+    rdef = rschema.rdef(sschema, oschema)
     if role == 'subject':
-        card = rschema.rproperty(sschema, oschema, 'cardinality')[0]
-        composed = rschema.rproperty(sschema, oschema, 'composite') == 'object'
+        card = rdef.cardinality[0]
+        composed = not rschema.final and rdef.composite == 'object'
     else:
-        card = rschema.rproperty(sschema, oschema, 'cardinality')[1]
-        composed = rschema.rproperty(sschema, oschema, 'composite') == 'subject'
+        card = rdef.cardinality[1]
+        composed = not rschema.final and rdef.composite == 'subject'
     return card, composed
 
 class AutoformSectionRelationTags(RelationTagsSet):
@@ -355,13 +356,13 @@
             # permission which may imply rql queries
             _targetschemas = []
             for tschema in targetschemas:
-                if not rtags.etype_get(eschema, rschema, role, tschema) in categories:
-                        continue
-                    rdef = rschema.role_rdef(eschema, tschema, role)
-                    if not ((not strict and rdef.has_local_role(permission)) or
-                            rdef.has_perm(entity.req, permission, fromeid=eid)):
-                        continue
-                    _targetschemas.append(tschema)
+                if not tag in self.etype_get(eschema, rschema, role, tschema):
+                    continue
+                rdef = rschema.role_rdef(eschema, tschema, role)
+                if not ((not strict and rdef.has_local_role(permission)) or
+                        rdef.has_perm(entity.req, permission, fromeid=eid)):
+                    continue
+                _targetschemas.append(tschema)
             if not _targetschemas:
                 continue
             targetschemas = _targetschemas
@@ -373,7 +374,7 @@
                     yield (rschema, targetschemas, role)
                     continue
                 if rschema.final:
-                    if not eschema.rdef(rschema).has_perm(entity._cw, permission, eid):
+                    if not eschema.rdef(rschema).has_perm(entity._cw, permission, fromeid=eid):
                         continue
                 elif role == 'subject':
                     # on relation with cardinality 1 or ?, we need delete perm as well
--- a/web/views/autoform.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/views/autoform.py	Mon Dec 07 17:17:22 2009 +0100
@@ -50,94 +50,6 @@
 
     # class methods mapping schema relations to fields in the form ############
 
-<<<<<<< /home/syt/src/fcubicweb/cubicweb/web/views/autoform.py
-=======
-    @classmethod
-    def erelations_by_category(cls, entity, categories=None, permission=None,
-                               rtags=None, strict=False):
-        """return a list of (relation schema, target schemas, role) matching
-        categories and permission
-
-        `strict`:
-          bool telling if having local role is enough (strict = False) or not
-        """
-        if categories is not None:
-            if not isinstance(categories, (list, tuple, set, frozenset)):
-                categories = (categories,)
-            if not isinstance(categories, (set, frozenset)):
-                categories = frozenset(categories)
-        eschema  = entity.e_schema
-        if rtags is None:
-            rtags = cls.rcategories
-        permsoverrides = cls.rpermissions_overrides
-        if entity.has_eid():
-            eid = entity.eid
-        else:
-            eid = None
-            strict = False
-        for rschema, targetschemas, role in eschema.relation_definitions(True):
-            # check category first, potentially lower cost than checking
-            # permission which may imply rql queries
-            if categories is not None:
-                _targetschemas = []
-                for tschema in targetschemas:
-                    if not rtags.etype_get(eschema, rschema, role, tschema) in categories:
-                        continue
-                    rdef = rschema.role_rdef(eschema, tschema, role)
-                    if not ((not strict and rdef.has_local_role(permission)) or
-                            rdef.has_perm(entity.req, permission, fromeid=eid)):
-                        continue
-                    _targetschemas.append(tschema)
-                if not _targetschemas:
-                    continue
-                targetschemas = _targetschemas
-            if permission is not None:
-                # tag allowing to hijack the permission machinery when
-                # permission is not verifiable until the entity is actually
-                # created...
-                if eid is None and '%s_on_new' % permission in permsoverrides.etype_get(eschema, rschema, role):
-                    yield (rschema, targetschemas, role)
-                    continue
-                if rschema.final:
-                    if not eschema.rdef(rschema).has_perm(entity.req, permission, eid=eid):
-                        continue
-                elif role == 'subject':
-                    # on relation with cardinality 1 or ?, we need delete perm as well
-                    # if the relation is already set
-                    if (permission == 'add'
-                        and rschema.rdef(eschema, targetschemas[0]).role_cardinality(role) in '1?'
-                        and eid and entity.related(rschema.type, role)
-                        and not rschema.has_perm(entity.req, 'delete', fromeid=eid,
-                                                 toeid=entity.related(rschema.type, role)[0][0])):
-                        continue
-                elif role == 'object':
-                    # on relation with cardinality 1 or ?, we need delete perm as well
-                    # if the relation is already set
-                    if (permission == 'add'
-                        and rschema.rdef(targetschemas[0], eschema).role_cardinality(role) in '1?'
-                        and eid and entity.related(rschema.type, role)
-                        and not rschema.has_perm(entity.req, 'delete', toeid=eid,
-                                                 fromeid=entity.related(rschema.type, role)[0][0])):
-                        continue
-            yield (rschema, targetschemas, role)
-
-    @classmethod
-    def esrelations_by_category(cls, entity, categories=None, permission=None,
-                                strict=False):
-        """filter out result of relations_by_category(categories, permission) by
-        removing final relations
-
-        return a sorted list of (relation's label, relation'schema, role)
-        """
-        result = []
-        for rschema, ttypes, role in cls.erelations_by_category(
-            entity, categories, permission, strict=strict):
-            if rschema.final:
-                continue
-            result.append((rschema.display_name(entity.req, role), rschema, role))
-        return sorted(result)
-
->>>>>>> /tmp/autoform.py~other.rHDQ-C
     @iclassmethod
     def field_by_name(cls_or_self, name, role='subject', eschema=None):
         """return field with the given name and role. If field is not explicitly
--- a/web/views/basecomponents.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/views/basecomponents.py	Mon Dec 07 17:17:22 2009 +0100
@@ -218,12 +218,11 @@
 
 class PdfViewComponent(component.EntityVComponent):
     __regid__ = 'pdfview'
-    __select__ = yes()
 
     context = 'ctxtoolbar'
 
     def cell_call(self, row, col, view):
-        entity = self.entity(row, col)
+        entity = self.cw_rset.get_entity(row, col)
         url = entity.absolute_url(vid=view.id, __template='pdf-main-template')
         iconurl = self.req.build_url('data/pdf_icon.gif')
         label = self.req._('Download page as pdf')
@@ -232,7 +231,7 @@
 
 
 class MetaDataComponent(component.EntityVComponent):
-    id = 'metadata'
+    __regid__ = 'metadata'
     context = 'navbottom'
     order = 1
 
--- a/web/views/basecontrollers.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/views/basecontrollers.py	Mon Dec 07 17:17:22 2009 +0100
@@ -249,12 +249,7 @@
         note: it's the responsability of js_* methods to set the correct
         response content type
         """
-<<<<<<< /home/syt/src/fcubicweb/cubicweb/web/views/basecontrollers.py
         self._cw.json_request = True
-        self._cw.pageid = self._cw.form.get('pageid')
-=======
-        self.req.json_request = True
->>>>>>> /tmp/basecontrollers.py~other.K2YVFx
         try:
             fname = self._cw.form['fname']
             func = getattr(self, 'js_%s' % fname)
--- a/web/views/editcontroller.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/views/editcontroller.py	Mon Dec 07 17:17:22 2009 +0100
@@ -70,6 +70,7 @@
         req = self._cw
         self.errors = []
         self.relations_rql = []
+        form = req.form
         # so we're able to know the main entity from the repository side
         if '__maineid' in form:
             req.set_shared_data('__maineid', form['__maineid'], querydata=True)
--- a/web/views/editforms.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/views/editforms.py	Mon Dec 07 17:17:22 2009 +0100
@@ -169,8 +169,8 @@
 
     def should_edit_attribute(self, entity, rschema, role, form):
         rtype = str(rschema)
-        ttype = rschema.targets(entity.id, role)[0]
-        afs = uicfg.autoform_section.etype_get(entity.id, rtype, role, ttype)
+        ttype = rschema.targets(entity.__regid__, role)[0]
+        afs = uicfg.autoform_section.etype_get(entity.__regid__, rtype, role, ttype)
         if 'main_hidden' in afs or not entity.has_perm('update'):
             return False
         try:
--- a/web/views/owl.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/views/owl.py	Mon Dec 07 17:17:22 2009 +0100
@@ -71,15 +71,9 @@
         if writeprefix:
             self.w(OWL_CLOSING_ROOT)
 
-<<<<<<< /home/syt/src/fcubicweb/cubicweb/web/views/owl.py
-    def should_display_rschema(self, rschema):
-        return not rschema in self.skiptypes and (
-            rschema.has_local_role('read') or
-            rschema.has_perm(self._cw, 'read'))
-=======
     def should_display_rschema(self, eschema, rschema, tschemas, role):
-        return rschema.may_have_permissions('read', self.req, eschema, role)
->>>>>>> /tmp/owl.py~other.-maWGS
+        return not rschema in self.skiptypes and ( 
+            rschema.may_have_permissions('read', self._cw, eschema, role))
 
     def visit_schema(self, skiptypes):
         """get a layout for a whole schema"""
--- a/web/views/primary.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/views/primary.py	Mon Dec 07 17:17:22 2009 +0100
@@ -283,7 +283,7 @@
     """use this view for attributes whose value is an url and that you want
     to display as clickable link
     """
-    id = 'urlattr'
+    __regid__ = 'urlattr'
     __select__ = EntityView.__select__ & match_kwargs('rtype')
 
     def cell_call(self, row, col, rtype, **kwargs):
--- a/web/views/wdoc.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/views/wdoc.py	Mon Dec 07 17:17:22 2009 +0100
@@ -238,7 +238,7 @@
 
 
 class HelpAction(action.Action):
-    id = 'help'
+    __regid__ = 'help'
     __select__ = yes()
 
     category = 'footer'
--- a/web/views/workflow.py	Mon Dec 07 17:16:55 2009 +0100
+++ b/web/views/workflow.py	Mon Dec 07 17:17:22 2009 +0100
@@ -219,10 +219,10 @@
 # workflow entity types edition ################################################
 
 _afs = uicfg.autoform_section
-_afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'generated')
-_afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'generated')
-_afs.tag_object_of(('State', 'allowed_transition', '*'), 'primary')
-_afs.tag_subject_of(('State', 'allowed_transition', '*'), 'primary')
+_afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'main', 'hidden')
+_afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'main', 'hidden')
+_afs.tag_object_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
+_afs.tag_subject_of(('State', 'allowed_transition', '*'), 'main', 'attributes')
 
 def workflow_items_for_relation(req, wfeid, wfrelation, targetrelation):
     wf = req.entity_from_eid(wfeid)