diff --git a/endpoints/api/team.py b/endpoints/api/team.py index 2b9564ae9..1c9d6e61b 100644 --- a/endpoints/api/team.py +++ b/endpoints/api/team.py @@ -68,7 +68,7 @@ def handle_addinvite_team(inviter, team, user=None, email=None): orgname, team.name, inviter.username, invite.invite_token) return invite -def team_view(orgname, team): +def team_view(orgname, team, is_new_team=False): view_permission = ViewTeamPermission(orgname, team.name) role = model.team.get_team_org_role(team).name return { @@ -76,7 +76,8 @@ def team_view(orgname, team): 'description': team.description, 'can_view': view_permission.can(), 'role': role, - 'avatar': avatar.get_data_for_team(team) + 'avatar': avatar.get_data_for_team(team), + 'new_team': is_new_team, } def member_view(member, invited=False): @@ -192,7 +193,7 @@ class OrganizationTeam(ApiResource): get_authenticated_user().username) log_action('org_set_team_role', orgname, {'team': teamname, 'role': details['role']}) - return team_view(orgname, team), 200 + return team_view(orgname, team, is_new_team=not is_existing), 200 raise Unauthorized() diff --git a/static/js/directives/ui/create-team-dialog.js b/static/js/directives/ui/create-team-dialog.js index d66f1bc44..92add507f 100644 --- a/static/js/directives/ui/create-team-dialog.js +++ b/static/js/directives/ui/create-team-dialog.js @@ -35,6 +35,11 @@ angular.module('quay').directive('createTeamDialog', function () { }); ApiService.updateOrganizationTeam(data, params).then(function(resp) { + if (!resp.new_team) { + callback(null); + bootbox.alert('Team with name "' + resp.name + '" already exists') + return; + } callback(resp); }, errorDisplay); }; diff --git a/static/js/directives/ui/entity-search.js b/static/js/directives/ui/entity-search.js index d768c46f6..dc1f602e9 100644 --- a/static/js/directives/ui/entity-search.js +++ b/static/js/directives/ui/entity-search.js @@ -151,7 +151,9 @@ angular.module('quay').directive('entitySearch', function () { $scope.handleTeamCreated = function(created) { $scope.setEntity(created.name, 'team', false, created.avatar); - $scope.teams.push(created); + if (created.new_team) { + $scope.teams.push(created); + } }; $scope.handleRobotCreated = function(created) { diff --git a/static/js/directives/ui/teams-manager.js b/static/js/directives/ui/teams-manager.js index ba093b596..63ef68540 100644 --- a/static/js/directives/ui/teams-manager.js +++ b/static/js/directives/ui/teams-manager.js @@ -101,6 +101,10 @@ angular.module('quay').directive('teamsManager', function () { }; $scope.handleTeamCreated = function(created) { + if (!created.new_team) { + return; + } + var teamname = created.name; created['member_count'] = 0;