1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/*
* SonarQube
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import $ from 'jquery';
import _ from 'underscore';
import { getJSON, post } from '../helpers/request';
function request (options) {
return $.ajax(options);
}
function typeError (method, message) {
throw new TypeError(`permissions#${method}: ${message}`);
}
export function getUsers (data) {
const url = window.baseUrl + '/api/permissions/users';
return request({ type: 'GET', url, data });
}
export function grantToUser (permission, user, project) {
if (typeof permission !== 'string' || !permission.length) {
return typeError('grantToUser', 'please provide permission');
}
if (typeof user !== 'string' || !user.length) {
return typeError('grantToUser', 'please provide user login');
}
const url = window.baseUrl + '/api/permissions/add_user';
const data = { permission, login: user };
if (project) {
data.projectId = project;
}
return request({ type: 'POST', url, data });
}
export function revokeFromUser (permission, user, project) {
if (typeof permission !== 'string' || !permission.length) {
return typeError('revokeFromUser', 'please provide permission');
}
if (typeof user !== 'string' || !user.length) {
return typeError('revokeFromUser', 'please provide user login');
}
const url = window.baseUrl + '/api/permissions/remove_user';
const data = { permission, login: user };
if (project) {
data.projectId = project;
}
return request({ type: 'POST', url, data });
}
export function getGroups (data) {
const url = window.baseUrl + '/api/permissions/groups';
return request({ type: 'GET', url, data });
}
export function grantToGroup (permission, group, project) {
if (typeof permission !== 'string' || !permission.length) {
return typeError('grantToGroup', 'please provide permission');
}
if (typeof group !== 'string' || !group.length) {
return typeError('grantToGroup', 'please provide group name');
}
const url = window.baseUrl + '/api/permissions/add_group';
const data = { permission, groupName: group };
if (project) {
data.projectId = project;
}
return request({ type: 'POST', url, data });
}
export function revokeFromGroup (permission, group, project) {
if (typeof permission !== 'string' || !permission.length) {
return typeError('revokeFromGroup', 'please provide permission');
}
if (typeof group !== 'string' || !group.length) {
return typeError('revokeFromGroup', 'please provide group name');
}
const url = window.baseUrl + '/api/permissions/remove_group';
const data = { permission, groupName: group };
if (project) {
data.projectId = project;
}
return request({ type: 'POST', url, data });
}
/**
* Get list of permission templates
* @returns {Promise}
*/
export function getPermissionTemplates () {
const url = window.baseUrl + '/api/permissions/search_templates';
return getJSON(url);
}
export function createPermissionTemplate (options) {
const url = window.baseUrl + '/api/permissions/create_template';
return request(_.extend({ type: 'POST', url }, options));
}
export function updatePermissionTemplate (options) {
const url = window.baseUrl + '/api/permissions/update_template';
return request(_.extend({ type: 'POST', url }, options));
}
export function deletePermissionTemplate (options) {
const url = window.baseUrl + '/api/permissions/delete_template';
return request(_.extend({ type: 'POST', url }, options));
}
/**
* Set default permission template for a given qualifier
* @param {string} templateName
* @param {string} qualifier
* @returns {Promise}
*/
export function setDefaultPermissionTemplate (templateName, qualifier) {
const url = window.baseUrl + '/api/permissions/set_default_template';
const data = { templateName, qualifier };
return post(url, data);
}
export function applyTemplateToProject (options) {
const url = window.baseUrl + '/api/permissions/apply_template';
return request(_.extend({ type: 'POST', url }, options));
}
export function bulkApplyTemplateToProject (options) {
const url = window.baseUrl + '/api/permissions/bulk_apply_template';
return request(_.extend({ type: 'POST', url }, options));
}
|