From df1500b6d04e0496bd7952b30df01d9662acd035 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 10 Dec 2013 15:22:22 -0500 Subject: [PATCH] =?UTF-8?q?Switch=20to=20using=20the=20UserService?= =?UTF-8?q?=E2=80=99s=20cache=20of=20org=20information=20for=20whether=20a?= =?UTF-8?q?=20user=20is=20an=20admin=20of=20a=20namespace/org?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- endpoints/api.py | 3 +- static/directives/entity-reference.html | 4 +-- static/js/app.js | 44 ++++++++++++++++++------- static/partials/repo-admin.html | 4 +-- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/endpoints/api.py b/endpoints/api.py index 2cd7e208d..786393810 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -828,8 +828,7 @@ def get_repo_api(namespace, repository): 'can_admin': can_admin, 'is_public': is_public, 'is_building': len(active_builds) > 0, - 'is_organization': bool(organization), - 'is_org_admin': bool(organization) and AdministerOrganizationPermission(namespace).can() + 'is_organization': bool(organization) }) abort(404) # Not found diff --git a/static/directives/entity-reference.html b/static/directives/entity-reference.html index e1380800c..509f4b03c 100644 --- a/static/directives/entity-reference.html +++ b/static/directives/entity-reference.html @@ -2,7 +2,7 @@ - {{team}} - {{team}} + {{team}} + {{team}} {{getPrefix(name)}}{{getShortenedName(name)}} diff --git a/static/js/app.js b/static/js/app.js index 719bb9953..4105e206b 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -137,6 +137,19 @@ quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'an return null; }; + userService.isNamespaceAdmin = function(namespace) { + if (namespace == userResponse.username) { + return true; + } + + var org = userService.getOrganization(namespace); + if (!org) { + return false; + } + + return org.is_org_admin; + }; + userService.currentUser = function() { return userResponse; }; @@ -516,10 +529,13 @@ quayApp.directive('entityReference', function () { 'name': '=name', 'orgname': '=orgname', 'team': '=team', - 'isrobot': '=isrobot', - 'isorgadmin': '=isorgadmin' + 'isrobot': '=isrobot' }, - controller: function($scope, $element) { + controller: function($scope, $element, UserService) { + $scope.getIsAdmin = function(orgname) { + return UserService.isNamespaceAdmin(orgname); + }; + $scope.getPrefix = function(name) { if (!name) { return ''; } var plus = name.indexOf('+'); @@ -1252,7 +1268,7 @@ quayApp.directive('entitySearch', function () { 'includeTeams': '=includeTeams', 'isOrganization': '=isOrganization' }, - controller: function($scope, $element, Restangular) { + controller: function($scope, $element, Restangular, UserService) { $scope.lazyLoading = true; $scope.isAdmin = false; @@ -1267,16 +1283,20 @@ quayApp.directive('entitySearch', function () { }); } - var url = $scope.isOrganization ? getRestUrl('organization', $scope.namespace, 'robots') : 'user/robots'; - var getRobots = Restangular.one(url); - getRobots.customGET().then(function(resp) { - $scope.robots = resp.robots; + if (UserService.isNamespaceAdmin($scope.namespace)) { $scope.isAdmin = true; + + var url = $scope.isOrganization ? getRestUrl('organization', $scope.namespace, 'robots') : 'user/robots'; + var getRobots = Restangular.one(url); + getRobots.customGET().then(function(resp) { + $scope.robots = resp.robots; + $scope.lazyLoading = false; + }, function() { + $scope.lazyLoading = false; + }); + } else { $scope.lazyLoading = false; - }, function() { - $scope.isAdmin = false; - $scope.lazyLoading = false; - }); + } }; $scope.createTeam = function() { diff --git a/static/partials/repo-admin.html b/static/partials/repo-admin.html index 9ca4e8686..50adf5744 100644 --- a/static/partials/repo-admin.html +++ b/static/partials/repo-admin.html @@ -58,7 +58,7 @@ - + @@ -74,7 +74,7 @@ - +