Switch to using the UserService’s cache of org information for whether a user is an admin of a namespace/org (#2)

This commit is contained in:
Joseph Schorr 2013-12-10 15:49:34 -05:00
parent df1500b6d0
commit 3302b58cc3
3 changed files with 17 additions and 16 deletions

View file

@ -1658,7 +1658,7 @@ def get_user_robots():
@app.route('/api/organization/<orgname>/robots', methods=['GET']) @app.route('/api/organization/<orgname>/robots', methods=['GET'])
@api_login_required @api_login_required
def get_org_robots(orgname): def get_org_robots(orgname):
permission = AdministerOrganizationPermission(orgname) permission = OrganizationMemberPermission(orgname)
if permission.can(): if permission.can():
robots = model.list_entity_robots(orgname) robots = model.list_entity_robots(orgname)
return jsonify({ return jsonify({

View file

@ -14,7 +14,7 @@
</a> </a>
</li> </li>
<li role="presentation" class="divider" ng-show="includeTeams && !lazyLoading && teams && isAdmin"></li> <li role="presentation" class="divider" ng-show="!lazyLoading && teams && (isAdmin || robots)"></li>
<li role="presentation" ng-repeat="robot in robots" ng-show="!lazyLoading"> <li role="presentation" ng-repeat="robot in robots" ng-show="!lazyLoading">
<a role="menuitem" tabindex="-1" href="javascript:void(0)" ng-click="setEntity(robot.name, 'user', true)"> <a role="menuitem" tabindex="-1" href="javascript:void(0)" ng-click="setEntity(robot.name, 'user', true)">
@ -22,7 +22,8 @@
</a> </a>
</li> </li>
<li role="presentation" class="divider" ng-show="!lazyLoading && robots"></li> <li role="presentation" class="divider" ng-show="!lazyLoading && robots && isAdmin"></li>
<li role="presentation" ng-show="includeTeams && isOrganization && !lazyLoading && isAdmin"> <li role="presentation" ng-show="includeTeams && isOrganization && !lazyLoading && isAdmin">
<a role="menuitem" class="new-action" tabindex="-1" href="javascript:void(0)" ng-click="createTeam()"> <a role="menuitem" class="new-action" tabindex="-1" href="javascript:void(0)" ng-click="createTeam()">
<i class="fa fa-group"></i> Create team <i class="fa fa-group"></i> Create team

View file

@ -1275,6 +1275,8 @@ quayApp.directive('entitySearch', function () {
$scope.lazyLoad = function() { $scope.lazyLoad = function() {
if (!$scope.namespace || !$scope.lazyLoading) { return; } if (!$scope.namespace || !$scope.lazyLoading) { return; }
$scope.isAdmin = UserService.isNamespaceAdmin($scope.namespace);
if ($scope.isOrganization && $scope.includeTeams) { if ($scope.isOrganization && $scope.includeTeams) {
var url = getRestUrl('organization', $scope.namespace); var url = getRestUrl('organization', $scope.namespace);
var getOrganization = Restangular.one(url); var getOrganization = Restangular.one(url);
@ -1283,23 +1285,19 @@ quayApp.directive('entitySearch', function () {
}); });
} }
if (UserService.isNamespaceAdmin($scope.namespace)) { var url = $scope.isOrganization ? getRestUrl('organization', $scope.namespace, 'robots') : 'user/robots';
$scope.isAdmin = true; var getRobots = Restangular.one(url);
getRobots.customGET().then(function(resp) {
var url = $scope.isOrganization ? getRestUrl('organization', $scope.namespace, 'robots') : 'user/robots'; $scope.robots = resp.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; $scope.lazyLoading = false;
} }, function() {
$scope.lazyLoading = false;
});
}; };
$scope.createTeam = function() { $scope.createTeam = function() {
if (!$scope.isAdmin) { return; }
bootbox.prompt('Enter the name of the new team', function(teamname) { bootbox.prompt('Enter the name of the new team', function(teamname) {
if (!teamname) { return; } if (!teamname) { return; }
@ -1317,6 +1315,8 @@ quayApp.directive('entitySearch', function () {
}; };
$scope.createRobot = function() { $scope.createRobot = function() {
if (!$scope.isAdmin) { return; }
bootbox.prompt('Enter the name of the new robot account', function(robotname) { bootbox.prompt('Enter the name of the new robot account', function(robotname) {
if (!robotname) { return; } if (!robotname) { return; }