48 'relation_type', 'from_entity', 'to_entity', |
48 'relation_type', 'from_entity', 'to_entity', |
49 'constrained_by', 'cstrtype', |
49 'constrained_by', 'cstrtype', |
50 )) |
50 )) |
51 |
51 |
52 WORKFLOW_TYPES = set(('Transition', 'State', 'TrInfo', 'Workflow', |
52 WORKFLOW_TYPES = set(('Transition', 'State', 'TrInfo', 'Workflow', |
53 'WorkflowTransition', 'BaseTransition', |
53 'WorkflowTransition', 'BaseTransition', |
54 'SubWorkflowExitPoint')) |
54 'SubWorkflowExitPoint')) |
|
55 |
55 INTERNAL_TYPES = set(('CWProperty', 'CWPermission', 'CWCache', 'ExternalUri')) |
56 INTERNAL_TYPES = set(('CWProperty', 'CWPermission', 'CWCache', 'ExternalUri')) |
56 |
57 |
57 |
58 |
58 _LOGGER = getLogger('cubicweb.schemaloader') |
59 _LOGGER = getLogger('cubicweb.schemaloader') |
59 |
60 |
60 # schema entities created from serialized schema have an eid rproperty |
61 # schema entities created from serialized schema have an eid rproperty |
61 ybo.ETYPE_PROPERTIES += ('eid',) |
62 ybo.ETYPE_PROPERTIES += ('eid',) |
62 ybo.RTYPE_PROPERTIES += ('eid',) |
63 ybo.RTYPE_PROPERTIES += ('eid',) |
63 ybo.RDEF_PROPERTIES += ('eid',) |
64 ybo.RDEF_PROPERTIES += ('eid',) |
64 |
65 |
|
66 |
|
67 PUB_SYSTEM_ENTITY_PERMS = { |
|
68 'read': ('managers', 'users', 'guests',), |
|
69 'add': ('managers',), |
|
70 'delete': ('managers',), |
|
71 'update': ('managers',), |
|
72 } |
|
73 PUB_SYSTEM_REL_PERMS = { |
|
74 'read': ('managers', 'users', 'guests',), |
|
75 'add': ('managers',), |
|
76 'delete': ('managers',), |
|
77 } |
|
78 PUB_SYSTEM_ATTR_PERMS = { |
|
79 'read': ('managers', 'users', 'guests',), |
|
80 'update': ('managers',), |
|
81 } |
|
82 RO_REL_PERMS = { |
|
83 'read': ('managers', 'users', 'guests',), |
|
84 'add': (), |
|
85 'delete': (), |
|
86 } |
|
87 RO_ATTR_PERMS = { |
|
88 'read': ('managers', 'users', 'guests',), |
|
89 'update': (), |
|
90 } |
65 |
91 |
66 # XXX same algorithm as in reorder_cubes and probably other place, |
92 # XXX same algorithm as in reorder_cubes and probably other place, |
67 # may probably extract a generic function |
93 # may probably extract a generic function |
68 def order_eschemas(eschemas): |
94 def order_eschemas(eschemas): |
69 """return entity schemas ordered such that entity types which specializes an |
95 """return entity schemas ordered such that entity types which specializes an |
367 else: |
393 else: |
368 need_has_text = False |
394 need_has_text = False |
369 if need_has_text is None: |
395 if need_has_text is None: |
370 need_has_text = may_need_has_text |
396 need_has_text = may_need_has_text |
371 if need_has_text and not has_has_text and not deletion: |
397 if need_has_text and not has_has_text and not deletion: |
372 rdef = ybo.RelationDefinition(self.type, 'has_text', 'String') |
398 rdef = ybo.RelationDefinition(self.type, 'has_text', 'String', |
|
399 __permissions__=RO_ATTR_PERMS) |
373 self.schema.add_relation_def(rdef) |
400 self.schema.add_relation_def(rdef) |
374 elif not need_has_text and has_has_text: |
401 elif not need_has_text and has_has_text: |
375 self.schema.del_relation_def(self.type, 'has_text', 'String') |
402 self.schema.del_relation_def(self.type, 'has_text', 'String') |
376 |
403 |
377 def schema_entity(self): |
404 def schema_entity(self): |
489 assert re.match(r'[A-Z][A-Za-z0-9]*[a-z]+[0-9]*$', edef.name), repr(edef.name) |
516 assert re.match(r'[A-Z][A-Za-z0-9]*[a-z]+[0-9]*$', edef.name), repr(edef.name) |
490 eschema = super(CubicWebSchema, self).add_entity_type(edef) |
517 eschema = super(CubicWebSchema, self).add_entity_type(edef) |
491 if not eschema.final: |
518 if not eschema.final: |
492 # automatically add the eid relation to non final entity types |
519 # automatically add the eid relation to non final entity types |
493 rdef = ybo.RelationDefinition(eschema.type, 'eid', 'Int', |
520 rdef = ybo.RelationDefinition(eschema.type, 'eid', 'Int', |
494 cardinality='11', uid=True) |
521 cardinality='11', uid=True, |
|
522 __permissions__=RO_ATTR_PERMS) |
495 self.add_relation_def(rdef) |
523 self.add_relation_def(rdef) |
496 rdef = ybo.RelationDefinition(eschema.type, 'identity', eschema.type) |
524 rdef = ybo.RelationDefinition(eschema.type, 'identity', eschema.type, |
|
525 __permissions__=RO_REL_PERMS) |
497 self.add_relation_def(rdef) |
526 self.add_relation_def(rdef) |
498 self._eid_index[eschema.eid] = eschema |
527 self._eid_index[eschema.eid] = eschema |
499 return eschema |
528 return eschema |
500 |
529 |
501 def add_relation_type(self, rdef): |
530 def add_relation_type(self, rdef): |
1052 cw = None |
1081 cw = None |
1053 if form is None and entity is not None: |
1082 if form is None and entity is not None: |
1054 cw = entity._cw |
1083 cw = entity._cw |
1055 elif form is not None: |
1084 elif form is not None: |
1056 cw = form._cw |
1085 cw = form._cw |
1057 if cw is not None and cw.user.has_permission(PERM_USE_TEMPLATE_FORMAT): |
1086 if cw is not None: |
1058 return self.regular_formats + tuple(NEED_PERM_FORMATS) |
1087 if hasattr(cw, 'is_super_session'): |
|
1088 # cw is a server session |
|
1089 hasperm = cw.is_super_session or \ |
|
1090 not cw.vreg.config.is_hook_category_activated('integrity') or \ |
|
1091 cw.user.has_permission(PERM_USE_TEMPLATE_FORMAT) |
|
1092 else: |
|
1093 hasperm = cw.user.has_permission(PERM_USE_TEMPLATE_FORMAT) |
|
1094 if hasperm: |
|
1095 return self.regular_formats + tuple(NEED_PERM_FORMATS) |
1059 return self.regular_formats |
1096 return self.regular_formats |
1060 |
1097 |
1061 # XXX monkey patch PyFileReader.import_erschema until bw_normalize_etype is |
1098 # XXX monkey patch PyFileReader.import_erschema until bw_normalize_etype is |
1062 # necessary |
1099 # necessary |
1063 orig_import_erschema = PyFileReader.import_erschema |
1100 orig_import_erschema = PyFileReader.import_erschema |