This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/services/roles-service.js

58 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-04-20 21:42:33 +00:00
/**
* Service which defines the various role groups.
*/
angular.module('quay').factory('RolesService', ['UtilService', 'Restangular', 'ApiService', function(UtilService, Restangular, ApiService) {
2015-04-20 21:42:33 +00:00
var roleService = {};
roleService.repoRolesOrNone = [
{ 'id': 'none', 'title': 'None', 'kind': 'default', 'description': 'No permissions on the repository' },
2015-04-20 21:42:33 +00:00
{ 'id': 'read', 'title': 'Read', 'kind': 'success', 'description': 'Can view and pull from the repository' },
{ 'id': 'write', 'title': 'Write', 'kind': 'success', 'description': 'Can view, pull and push to the repository' },
{ 'id': 'admin', 'title': 'Admin', 'kind': 'primary', 'description': 'Full admin access, pull and push on the repository' }
];
roleService.repoRoles = roleService.repoRolesOrNone.slice(1);
2015-04-20 21:42:33 +00:00
roleService.teamRoles = [
{ 'id': 'member', 'title': 'Member', 'kind': 'default', 'description': 'Inherits all permissions of the team' },
{ 'id': 'creator', 'title': 'Creator', 'kind': 'success', 'description': 'Member and can create new repositories' },
{ 'id': 'admin', 'title': 'Admin', 'kind': 'primary', 'description': 'Full admin access to the organization' }
];
var getPermissionEndpoint = function(repository, entityName, kind) {
var namespace = repository.namespace;
var name = repository.name;
var url = UtilService.getRestUrl('repository', namespace, name, 'permissions', kind, entityName);
return Restangular.one(url);
};
roleService.deleteRepositoryRole = function(repository, entityKind, entityName, callback) {
var errorDisplay = ApiService.errorDisplay('Cannot change permission', function(resp) {
callback(false);
});
var endpoint = getPermissionEndpoint(repository, entityName, entityKind);
endpoint.customDELETE().then(function() {
callback(true);
}, errorDisplay);
};
roleService.setRepositoryRole = function(repository, role, entityKind, entityName, callback) {
var errorDisplay = ApiService.errorDisplay('Cannot change permission', function(resp) {
callback(false);
});
var permission = {
'role': role
};
var endpoint = getPermissionEndpoint(repository, entityName, entityKind);
endpoint.customPUT(permission).then(function(resp) {
callback(true, resp);
}, errorDisplay);
};
2015-04-20 21:42:33 +00:00
return roleService;
}]);