143 |
143 |
144 def __init__(self, session): |
144 def __init__(self, session): |
145 hook.SingleLastOperation.__init__(self, session) |
145 hook.SingleLastOperation.__init__(self, session) |
146 |
146 |
147 def commit_event(self): |
147 def commit_event(self): |
148 self.session.repo.set_schema(self.session.repo.schema) |
148 rebuildinfered = self.session.data.get('rebuild-infered', True) |
|
149 self.session.repo.set_schema(self.repo.schema, rebuildinfered=rebuildinfered) |
149 |
150 |
150 |
151 |
151 class MemSchemaOperation(hook.Operation): |
152 class MemSchemaOperation(hook.Operation): |
152 """base class for schema operations""" |
153 """base class for schema operations""" |
153 def __init__(self, session, kobj=None, **kwargs): |
154 def __init__(self, session, kobj=None, **kwargs): |
725 self.perm, erschema.type, self.expr) |
726 self.perm, erschema.type, self.expr) |
726 return |
727 return |
727 erschema.set_rqlexprs(self.perm, rqlexprs) |
728 erschema.set_rqlexprs(self.perm, rqlexprs) |
728 |
729 |
729 |
730 |
|
731 class MemSchemaSpecializesAdd(MemSchemaOperation): |
|
732 |
|
733 def commit_event(self): |
|
734 eschema = self.session.schema.schema_by_eid(self.etypeeid) |
|
735 parenteschema = self.session.schema.schema_by_eid(self.parentetypeeid) |
|
736 eschema._specialized_type = parenteschema.type |
|
737 parenteschema._specialized_by.append(eschema.type) |
|
738 |
|
739 |
|
740 class MemSchemaSpecializesDel(MemSchemaOperation): |
|
741 |
|
742 def commit_event(self): |
|
743 try: |
|
744 eschema = self.session.schema.schema_by_eid(self.etypeeid) |
|
745 parenteschema = self.session.schema.schema_by_eid(self.parentetypeeid) |
|
746 except KeyError: |
|
747 # etype removed, nothing to do |
|
748 return |
|
749 eschema._specialized_type = None |
|
750 parenteschema._specialized_by.remove(eschema.type) |
|
751 |
|
752 |
730 class SyncSchemaHook(hook.Hook): |
753 class SyncSchemaHook(hook.Hook): |
731 __abstract__ = True |
754 __abstract__ = True |
732 category = 'syncschema' |
755 category = 'syncschema' |
|
756 |
733 |
757 |
734 # CWEType hooks ################################################################ |
758 # CWEType hooks ################################################################ |
735 |
759 |
736 class DelCWETypeHook(SyncSchemaHook): |
760 class DelCWETypeHook(SyncSchemaHook): |
737 """before deleting a CWEType entity: |
761 """before deleting a CWEType entity: |
758 __id__ = 'wfcleanup' |
782 __id__ = 'wfcleanup' |
759 events = ('after_delete_entity',) |
783 events = ('after_delete_entity',) |
760 |
784 |
761 def __call__(self): |
785 def __call__(self): |
762 # workflow cleanup |
786 # workflow cleanup |
763 self._cw.execute('DELETE State X WHERE NOT X state_of Y') |
787 self._cw.execute('DELETE Workflow X WHERE NOT X workflow_of Y') |
764 self._cw.execute('DELETE Transition X WHERE NOT X transition_of Y') |
|
765 |
788 |
766 |
789 |
767 class AfterAddCWETypeHook(DelCWETypeHook): |
790 class AfterAddCWETypeHook(DelCWETypeHook): |
768 """after adding a CWEType entity: |
791 """after adding a CWEType entity: |
769 * create the necessary table |
792 * create the necessary table |
1050 objtype=objtype, cstr=cstr) |
1073 objtype=objtype, cstr=cstr) |
1051 |
1074 |
1052 |
1075 |
1053 # permissions synchronization hooks ############################################ |
1076 # permissions synchronization hooks ############################################ |
1054 |
1077 |
1055 |
|
1056 class AfterAddPermissionHook(SyncSchemaHook): |
1078 class AfterAddPermissionHook(SyncSchemaHook): |
1057 """added entity/relation *_permission, need to update schema""" |
1079 """added entity/relation *_permission, need to update schema""" |
1058 __id__ = 'syncaddperm' |
1080 __id__ = 'syncaddperm' |
1059 __select__ = SyncSchemaHook.__select__ & hook.match_rtype( |
1081 __select__ = SyncSchemaHook.__select__ & hook.match_rtype( |
1060 'read_permission', 'add_permission', 'delete_permission', |
1082 'read_permission', 'add_permission', 'delete_permission', |
1087 else: # RQLExpression |
1109 else: # RQLExpression |
1088 expr = self._cw.entity_from_eid(self.eidto).expression |
1110 expr = self._cw.entity_from_eid(self.eidto).expression |
1089 MemSchemaPermRQLExpressionDel(self._cw, perm, self.eidfrom, expr) |
1111 MemSchemaPermRQLExpressionDel(self._cw, perm, self.eidfrom, expr) |
1090 |
1112 |
1091 |
1113 |
1092 |
1114 # specializes synchronization hooks ############################################ |
1093 class ModifySpecializesHook(SyncSchemaHook): |
1115 |
1094 __id__ = 'syncspecializes' |
1116 |
|
1117 class AfterAddSpecializesHook(SyncSchemaHook): |
|
1118 __id__ = 'syncaddspecializes' |
1095 __select__ = SyncSchemaHook.__select__ & hook.match_rtype('specializes') |
1119 __select__ = SyncSchemaHook.__select__ & hook.match_rtype('specializes') |
1096 events = ('after_add_relation', 'after_delete_relation') |
1120 events = ('after_add_relation',) |
1097 |
1121 |
1098 def __call__(self): |
1122 def __call__(self): |
1099 # registering a schema operation will trigger a call to |
1123 MemSchemaSpecializesAdd(session, etypeeid=self.eidfrom, |
1100 # repo.set_schema() on commit which will in turn rebuild |
1124 parentetypeeid=self.eidto) |
1101 # infered relation definitions |
1125 |
1102 MemSchemaNotifyChanges(self._cw) |
1126 |
|
1127 class AfterAddSpecializesHook(SyncSchemaHook): |
|
1128 __id__ = 'syncdelspecializes' |
|
1129 __select__ = SyncSchemaHook.__select__ & hook.match_rtype('specializes') |
|
1130 events = ('after_delete_relation',) |
|
1131 |
|
1132 def __call__(self): |
|
1133 MemSchemaSpecializesDel(session, etypeeid=self.eidfrom, |
|
1134 parentetypeeid=self.eidto) |