From c1e4bf79b7e34b320657a9c8e1719e20b578f28a Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 11 Jul 2016 15:47:05 -0400 Subject: [PATCH] Fix delete team error message for admin teams --- data/model/team.py | 8 +++----- test/test_api_usage.py | 9 +++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/data/model/team.py b/data/model/team.py index c3c071d31..ce1f782b4 100644 --- a/data/model/team.py +++ b/data/model/team.py @@ -97,12 +97,10 @@ def remove_team(org_name, team_name, removed_by_username): team = found[0] if team.role.name == 'admin': admin_teams = list(__get_user_admin_teams(org_name, removed_by_username)) - if len(admin_teams) <= 1: - # The team we are trying to remove is the only admin team for this user - msg = ('Deleting team \'%s\' would remove all admin from user \'%s\'' % - (team_name, removed_by_username)) - raise DataModelException(msg) + # The team we are trying to remove is the only admin team containing this user. + msg = "Deleting team '%s' would remove admin ability for user '%s' in organization '%s'" + raise DataModelException(msg % (team_name, removed_by_username, org_name)) team.delete_instance(recursive=True, delete_nullable=True) diff --git a/test/test_api_usage.py b/test/test_api_usage.py index a037cc3fd..d0cf90589 100644 --- a/test/test_api_usage.py +++ b/test/test_api_usage.py @@ -1146,8 +1146,13 @@ class TestDeleteOrganizationTeam(ApiTestCase): def test_attemptdeleteowners(self): self.login(ADMIN_ACCESS_USER) - self.deleteResponse(OrganizationTeam, params=dict(orgname=ORGANIZATION, teamname='owners'), - expected_code=400) + resp = self.deleteResponse(OrganizationTeam, + params=dict(orgname=ORGANIZATION, teamname='owners'), + expected_code=400) + data = py_json.loads(resp) + msg = ("Deleting team 'owners' would remove admin ability for user " + + "'devtable' in organization 'buynlarge'") + self.assertEquals(msg, data['message']) class TestGetOrganizationTeamMembers(ApiTestCase):