Skip to content

Commit

Permalink
Project owners can not be no admin
Browse files Browse the repository at this point in the history
  • Loading branch information
bameda authored and superalex committed Mar 18, 2016
1 parent 5ccb7a2 commit af588be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions taiga/projects/serializers.py
Expand Up @@ -190,9 +190,13 @@ def validate_is_admin(self, attrs, source):
if project is None:
project = self.object.project

if (self.object and
not services.project_has_valid_admins(project, exclude_user=self.object.user)):
raise serializers.ValidationError(_("In this project at least one of the users must be an active admin."))
if (self.object):
if self.object.user.id == project.owner_id and attrs[source] != True:
raise serializers.ValidationError(_("Project owner must be admin."))

if not services.project_has_valid_admins(project, exclude_user=self.object.user):
raise serializers.ValidationError(_("In this project at least one of the users "
"must be an active admin."))

return attrs

Expand Down
14 changes: 14 additions & 0 deletions tests/integration/test_memberships.py
Expand Up @@ -347,6 +347,20 @@ def test_api_edit_membership(client):

assert response.status_code == 200

def test_api_change_owner_membership_to_no_admin_return_error(client):
project = f.ProjectFactory()
membership_owner = f.MembershipFactory(project=project, user=project.owner, is_admin=True)
membership = f.MembershipFactory(project=project, is_admin=True)

url = reverse("memberships-detail", args=[membership_owner.id])
data = {"is_admin": False}

client.login(membership.user)
response = client.json.patch(url, json.dumps(data))

assert response.status_code == 400
assert 'is_admin' in response.data


def test_api_delete_membership(client):
membership = f.MembershipFactory(is_admin=True)
Expand Down

0 comments on commit af588be

Please sign in to comment.