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

This commit is contained in:
Joseph Schorr 2013-12-10 15:22:22 -05:00
parent 9197a20a77
commit df1500b6d0
4 changed files with 37 additions and 18 deletions

View file

@ -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() {