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:
parent
9197a20a77
commit
df1500b6d0
4 changed files with 37 additions and 18 deletions
|
@ -828,8 +828,7 @@ def get_repo_api(namespace, repository):
|
||||||
'can_admin': can_admin,
|
'can_admin': can_admin,
|
||||||
'is_public': is_public,
|
'is_public': is_public,
|
||||||
'is_building': len(active_builds) > 0,
|
'is_building': len(active_builds) > 0,
|
||||||
'is_organization': bool(organization),
|
'is_organization': bool(organization)
|
||||||
'is_org_admin': bool(organization) and AdministerOrganizationPermission(namespace).can()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
abort(404) # Not found
|
abort(404) # Not found
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<i class="fa fa-user" ng-show="!team && !isrobot" title="User" bs-tooltip="tooltip.title" data-container="body"></i>
|
<i class="fa fa-user" ng-show="!team && !isrobot" title="User" bs-tooltip="tooltip.title" data-container="body"></i>
|
||||||
<i class="fa fa-wrench" ng-show="!team && isrobot" title="Robot Account" bs-tooltip="tooltip.title" data-container="body"></i>
|
<i class="fa fa-wrench" ng-show="!team && isrobot" title="Robot Account" bs-tooltip="tooltip.title" data-container="body"></i>
|
||||||
<i class="fa fa-group" ng-show="team" title="Team" bs-tooltip="tooltip.title" data-container="body"></i>
|
<i class="fa fa-group" ng-show="team" title="Team" bs-tooltip="tooltip.title" data-container="body"></i>
|
||||||
<span ng-show="team && isorgadmin"><a href="/organization/{{ orgname }}/teams/{{ team }}">{{team}}</a></span>
|
<span ng-show="team && getIsAdmin(orgname)"><a href="/organization/{{ orgname }}/teams/{{ team }}">{{team}}</a></span>
|
||||||
<span ng-show="team && !isorgadmin">{{team}}</span>
|
<span ng-show="team && !getIsAdmin(orgname)">{{team}}</span>
|
||||||
<span ng-show="isrobot" class="prefix">{{getPrefix(name)}}</span><span>{{getShortenedName(name)}}</span>
|
<span ng-show="isrobot" class="prefix">{{getPrefix(name)}}</span><span>{{getShortenedName(name)}}</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -137,6 +137,19 @@ quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'an
|
||||||
return null;
|
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() {
|
userService.currentUser = function() {
|
||||||
return userResponse;
|
return userResponse;
|
||||||
};
|
};
|
||||||
|
@ -516,10 +529,13 @@ quayApp.directive('entityReference', function () {
|
||||||
'name': '=name',
|
'name': '=name',
|
||||||
'orgname': '=orgname',
|
'orgname': '=orgname',
|
||||||
'team': '=team',
|
'team': '=team',
|
||||||
'isrobot': '=isrobot',
|
'isrobot': '=isrobot'
|
||||||
'isorgadmin': '=isorgadmin'
|
|
||||||
},
|
},
|
||||||
controller: function($scope, $element) {
|
controller: function($scope, $element, UserService) {
|
||||||
|
$scope.getIsAdmin = function(orgname) {
|
||||||
|
return UserService.isNamespaceAdmin(orgname);
|
||||||
|
};
|
||||||
|
|
||||||
$scope.getPrefix = function(name) {
|
$scope.getPrefix = function(name) {
|
||||||
if (!name) { return ''; }
|
if (!name) { return ''; }
|
||||||
var plus = name.indexOf('+');
|
var plus = name.indexOf('+');
|
||||||
|
@ -1252,7 +1268,7 @@ quayApp.directive('entitySearch', function () {
|
||||||
'includeTeams': '=includeTeams',
|
'includeTeams': '=includeTeams',
|
||||||
'isOrganization': '=isOrganization'
|
'isOrganization': '=isOrganization'
|
||||||
},
|
},
|
||||||
controller: function($scope, $element, Restangular) {
|
controller: function($scope, $element, Restangular, UserService) {
|
||||||
$scope.lazyLoading = true;
|
$scope.lazyLoading = true;
|
||||||
$scope.isAdmin = false;
|
$scope.isAdmin = false;
|
||||||
|
|
||||||
|
@ -1267,16 +1283,20 @@ quayApp.directive('entitySearch', function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = $scope.isOrganization ? getRestUrl('organization', $scope.namespace, 'robots') : 'user/robots';
|
if (UserService.isNamespaceAdmin($scope.namespace)) {
|
||||||
var getRobots = Restangular.one(url);
|
|
||||||
getRobots.customGET().then(function(resp) {
|
|
||||||
$scope.robots = resp.robots;
|
|
||||||
$scope.isAdmin = true;
|
$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;
|
$scope.lazyLoading = false;
|
||||||
}, function() {
|
}
|
||||||
$scope.isAdmin = false;
|
|
||||||
$scope.lazyLoading = false;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.createTeam = function() {
|
$scope.createTeam = function() {
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
<!-- Team Permissions -->
|
<!-- Team Permissions -->
|
||||||
<tr ng-repeat="(name, permission) in permissions['team']">
|
<tr ng-repeat="(name, permission) in permissions['team']">
|
||||||
<td class="team entity">
|
<td class="team entity">
|
||||||
<span class="entity-reference" orgname="repo.namespace" team="name" isorgadmin="repo.is_org_admin"></span>
|
<span class="entity-reference" orgname="repo.namespace" team="name"></span>
|
||||||
</td>
|
</td>
|
||||||
<td class="user-permissions">
|
<td class="user-permissions">
|
||||||
<span class="role-group" current-role="permission.role" role-changed="setRole(role, name, 'team')" roles="roles"></span>
|
<span class="role-group" current-role="permission.role" role-changed="setRole(role, name, 'team')" roles="roles"></span>
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
<!-- User Permissions -->
|
<!-- User Permissions -->
|
||||||
<tr ng-repeat="(name, permission) in permissions['user']">
|
<tr ng-repeat="(name, permission) in permissions['user']">
|
||||||
<td class="{{ 'user entity ' + (permission.is_org_member ? '' : 'outside') }}">
|
<td class="{{ 'user entity ' + (permission.is_org_member ? '' : 'outside') }}">
|
||||||
<span class="entity-reference" name="name" isrobot="permission.is_robot" isorgadmin="repo.is_org_admin"></span>
|
<span class="entity-reference" name="name" isrobot="permission.is_robot"></span>
|
||||||
<i class="fa fa-exclamation-triangle" ng-show="permission.is_org_member === false" data-trigger="hover" bs-popover="{'content': 'This user is not a member of the organization'}"></i>
|
<i class="fa fa-exclamation-triangle" ng-show="permission.is_org_member === false" data-trigger="hover" bs-popover="{'content': 'This user is not a member of the organization'}"></i>
|
||||||
</td>
|
</td>
|
||||||
<td class="user-permissions">
|
<td class="user-permissions">
|
||||||
|
|
Reference in a new issue