Skip to content

Commit

Permalink
Merge pull request #1078 from yilmazbekdemir/prevent-role-organizatio…
Browse files Browse the repository at this point in the history
…n-admin-on-workflowteam

Make unable to create workflowteam with OrgAdmin role
  • Loading branch information
Rafael Muñoz Cárdenas authored Apr 18, 2018
2 parents 31a046a + 2242568 commit 96b59aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions workflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions workflow/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion workflow/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -55,6 +55,13 @@ def test_print_instance(self):
(u'Thom Yorke - ProgramAdmin <Health and Survival '
u'for Syrians in Affected Regions>'))

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):
Expand Down

0 comments on commit 96b59aa

Please sign in to comment.