From 224256870df6c26bf193dcfe608f6f7b04b56a17 Mon Sep 17 00:00:00 2001 From: yilmazbekdemir Date: Wed, 18 Apr 2018 14:47:53 +0200 Subject: [PATCH] Close #1075- Make unable to create workflowteam with OrgAdmin role --- workflow/models.py | 6 ++++++ workflow/signals.py | 1 + workflow/tests/test_models.py | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/workflow/models.py b/workflow/models.py index ac153cc5a..d49983b37 100755 --- a/workflow/models.py +++ b/workflow/models.py @@ -723,6 +723,12 @@ class Meta: verbose_name = "Workflow Team" verbose_name_plural = "Workflow Teams" + def clean(self): + if self.role and self.role.name == ROLE_ORGANIZATION_ADMIN: + raise ValidationError( + 'Workflowteam role can not be ROLE_ORGANIZATION_ADMIN' + ) + def save(self, *args, **kwargs): if self.create_date == None: self.create_date = timezone.now() diff --git a/workflow/signals.py b/workflow/signals.py index 709f54ee3..ce0dd017c 100644 --- a/workflow/signals.py +++ b/workflow/signals.py @@ -87,6 +87,7 @@ def check_seats_save_team(sender, instance, **kwargs): Validate, increase or decrease the amount of used seats based on the roles """ + instance.full_clean() if os.getenv('APP_BRANCH') == DEMO_BRANCH: return diff --git a/workflow/tests/test_models.py b/workflow/tests/test_models.py index 93505f6d2..fa83e6a7c 100644 --- a/workflow/tests/test_models.py +++ b/workflow/tests/test_models.py @@ -3,7 +3,7 @@ from django.test import TestCase, override_settings, tag import factories -from workflow.models import TolaUser, Office +from workflow.models import TolaUser, Office, ROLE_ORGANIZATION_ADMIN @tag('pkg') @@ -55,6 +55,13 @@ def test_print_instance(self): (u'Thom Yorke - ProgramAdmin ')) + def test_save_role_org_admin_fails(self): + wfteam = factories.WorkflowTeam.build( + role=factories.Group(name=ROLE_ORGANIZATION_ADMIN), + workflow_user=factories.TolaUser(), + workflowlevel1=factories.WorkflowLevel1()) + self.assertRaises(ValidationError, wfteam.save) + @tag('pkg') class ProductTest(TestCase):