Delete workflow members when deleting workflow
Workflow owner can not delete a shared workflow if it has been used to create cron-triggers by the shared member. Implements: blueprint mistral-workflow-resource-sharing Change-Id: I063716f081085fda53c9ef3a871cffb570498161
This commit is contained in:
parent
7795df0d0a
commit
e6f9a44c33
|
@ -411,6 +411,9 @@ def delete_workflow_definition(identifier, session=None):
|
|||
(identifier, ', '.join(cron_triggers))
|
||||
)
|
||||
|
||||
# Delete workflow members first.
|
||||
delete_resource_members(resource_type='workflow', resource_id=wf_def.id)
|
||||
|
||||
session.delete(wf_def)
|
||||
|
||||
|
||||
|
|
|
@ -1799,3 +1799,80 @@ class WorkflowSharingTest(SQLAlchemyTest):
|
|||
fetched = db_api.get_workflow_definition(wf.id)
|
||||
|
||||
self.assertEqual(wf, fetched)
|
||||
|
||||
def test_owner_delete_shared_workflow(self):
|
||||
wf = db_api.create_workflow_definition(WF_DEFINITIONS[1])
|
||||
|
||||
workflow_sharing = {
|
||||
'resource_id': wf.id,
|
||||
'resource_type': 'workflow',
|
||||
'project_id': security.get_project_id(),
|
||||
'member_id': user_context.project_id,
|
||||
'status': 'pending',
|
||||
}
|
||||
|
||||
db_api.create_resource_member(workflow_sharing)
|
||||
|
||||
# Switch to another tenant, accept the sharing.
|
||||
auth_context.set_ctx(user_context)
|
||||
|
||||
db_api.update_resource_member(
|
||||
wf.id,
|
||||
'workflow',
|
||||
user_context.project_id,
|
||||
{'status': 'accepted'}
|
||||
)
|
||||
|
||||
fetched = db_api.get_workflow_definition(wf.id)
|
||||
|
||||
self.assertEqual(wf, fetched)
|
||||
|
||||
# Switch to original tenant, delete the workflow.
|
||||
auth_context.set_ctx(test_base.get_context())
|
||||
|
||||
db_api.delete_workflow_definition(wf.id)
|
||||
|
||||
# Switch to another tenant, can not see that workflow.
|
||||
auth_context.set_ctx(user_context)
|
||||
|
||||
self.assertRaises(
|
||||
exc.NotFoundException,
|
||||
db_api.get_workflow_definition,
|
||||
wf.id
|
||||
)
|
||||
|
||||
def test_owner_delete_shared_workflow_has_crontrigger(self):
|
||||
wf = db_api.create_workflow_definition(WF_DEFINITIONS[1])
|
||||
|
||||
workflow_sharing = {
|
||||
'resource_id': wf.id,
|
||||
'resource_type': 'workflow',
|
||||
'project_id': security.get_project_id(),
|
||||
'member_id': user_context.project_id,
|
||||
'status': 'pending',
|
||||
}
|
||||
|
||||
db_api.create_resource_member(workflow_sharing)
|
||||
|
||||
# Switch to another tenant, accept the sharing.
|
||||
auth_context.set_ctx(user_context)
|
||||
|
||||
db_api.update_resource_member(
|
||||
wf.id,
|
||||
'workflow',
|
||||
user_context.project_id,
|
||||
{'status': 'accepted'}
|
||||
)
|
||||
|
||||
# Create cron trigger using the shared workflow.
|
||||
CRON_TRIGGERS[0]['workflow_id'] = wf.id
|
||||
db_api.create_cron_trigger(CRON_TRIGGERS[0])
|
||||
|
||||
# Switch to original tenant, try to delete the workflow.
|
||||
auth_context.set_ctx(test_base.get_context())
|
||||
|
||||
self.assertRaises(
|
||||
exc.DBException,
|
||||
db_api.delete_workflow_definition,
|
||||
wf.id
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue