1216 def cmd_synchronize_permissions(self, ertype, commit=True): |
1216 def cmd_synchronize_permissions(self, ertype, commit=True): |
1217 self.cmd_sync_schema_props_perms(ertype, syncprops=False, commit=commit) |
1217 self.cmd_sync_schema_props_perms(ertype, syncprops=False, commit=commit) |
1218 |
1218 |
1219 # Workflows handling ###################################################### |
1219 # Workflows handling ###################################################### |
1220 |
1220 |
|
1221 def cmd_make_workflowable(self, etype): |
|
1222 """add workflow relations to an entity type to make it workflowable""" |
|
1223 self.cmd_add_relation_definition(etype, 'in_state', 'State') |
|
1224 self.cmd_add_relation_definition(etype, 'custom_workflow', 'Workflow') |
|
1225 self.cmd_add_relation_definition('TrInfo', 'wf_info_for', etype) |
|
1226 |
1221 def cmd_add_workflow(self, name, wfof, default=True, commit=False, |
1227 def cmd_add_workflow(self, name, wfof, default=True, commit=False, |
1222 **kwargs): |
1228 **kwargs): |
1223 """ |
1229 """ |
1224 create a new workflow and links it to entity types |
1230 create a new workflow and links it to entity types |
1225 :type name: unicode |
1231 :type name: unicode |
1237 """ |
1243 """ |
1238 wf = self.cmd_create_entity('Workflow', name=unicode(name), |
1244 wf = self.cmd_create_entity('Workflow', name=unicode(name), |
1239 **kwargs) |
1245 **kwargs) |
1240 if not isinstance(wfof, (list, tuple)): |
1246 if not isinstance(wfof, (list, tuple)): |
1241 wfof = (wfof,) |
1247 wfof = (wfof,) |
|
1248 def _missing_wf_rel(etype): |
|
1249 return 'missing workflow relations, see make_workflowable(%s)' % etype |
1242 for etype in wfof: |
1250 for etype in wfof: |
|
1251 eschema = self.repo.schema[etype] |
|
1252 assert 'in_state' in eschema.subjrels, _missing_wf_rel(etype) |
|
1253 assert 'custom_workflow' in eschema.subjrels, _missing_wf_rel(etype) |
|
1254 assert 'wf_info_for' in eschema.objrels, _missing_wf_rel(etype) |
1243 rset = self.rqlexec( |
1255 rset = self.rqlexec( |
1244 'SET X workflow_of ET WHERE X eid %(x)s, ET name %(et)s', |
1256 'SET X workflow_of ET WHERE X eid %(x)s, ET name %(et)s', |
1245 {'x': wf.eid, 'et': etype}, ask_confirm=False) |
1257 {'x': wf.eid, 'et': etype}, ask_confirm=False) |
1246 assert rset, 'unexistant entity type %s' % etype |
1258 assert rset, 'unexistant entity type %s' % etype |
1247 if default: |
1259 if default: |