From 3302b58cc35b3b8492f74cbde175ecba93ee958a Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 10 Dec 2013 15:49:34 -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=20(#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- endpoints/api.py | 2 +- static/directives/entity-search.html | 5 +++-- static/js/app.js | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/endpoints/api.py b/endpoints/api.py index 786393810..ed85e6e35 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -1658,7 +1658,7 @@ def get_user_robots(): @app.route('/api/organization//robots', methods=['GET']) @api_login_required def get_org_robots(orgname): - permission = AdministerOrganizationPermission(orgname) + permission = OrganizationMemberPermission(orgname) if permission.can(): robots = model.list_entity_robots(orgname) return jsonify({ diff --git a/static/directives/entity-search.html b/static/directives/entity-search.html index eddd44916..fb4a6cf24 100644 --- a/static/directives/entity-search.html +++ b/static/directives/entity-search.html @@ -14,7 +14,7 @@ - +
  • @@ -22,7 +22,8 @@
  • - + +
  • Create team diff --git a/static/js/app.js b/static/js/app.js index 4105e206b..597bd5845 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -1275,6 +1275,8 @@ quayApp.directive('entitySearch', function () { $scope.lazyLoad = function() { if (!$scope.namespace || !$scope.lazyLoading) { return; } + $scope.isAdmin = UserService.isNamespaceAdmin($scope.namespace); + if ($scope.isOrganization && $scope.includeTeams) { var url = getRestUrl('organization', $scope.namespace); var getOrganization = Restangular.one(url); @@ -1283,23 +1285,19 @@ quayApp.directive('entitySearch', function () { }); } - 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 { + 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; + }); }; $scope.createTeam = function() { + if (!$scope.isAdmin) { return; } + bootbox.prompt('Enter the name of the new team', function(teamname) { if (!teamname) { return; } @@ -1317,6 +1315,8 @@ quayApp.directive('entitySearch', function () { }; $scope.createRobot = function() { + if (!$scope.isAdmin) { return; } + bootbox.prompt('Enter the name of the new robot account', function(robotname) { if (!robotname) { return; }