This repository has been archived by the owner on Jul 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 180
/
group.js
189 lines (172 loc) · 6.83 KB
/
group.js
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
"use strict";
module.exports = GroupClient;
/**
* Used to access Jira REST endpoints in '/rest/api/2/group'
*
* These are considered experimental according to the Jira Docs, use at your own risk.
*
* @param {JiraClient} jiraClient
* @constructor GroupClient
*/
function GroupClient(jiraClient) {
this.jiraClient = jiraClient;
/**
* Creates a group by given group parameter Returns REST representation for the requested group.
*
* @method createGroup
* @memberOf GroupClient#
* @param opts The request options sent to jira
* @param opts.group The group to create. See {@link https://docs.atlassian.com/jira/REST/latest/#d2e2011}
* @param [callback] Called when the group is created
* @return {Promise} Resolved when the group is created
*/
this.createGroup = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('/group'),
method: 'POST',
json: true,
followAllRedirects: true,
body: opts.group
};
return this.jiraClient.makeRequest(options, callback);
};
/**
* Returns REST representation for the requested group. Allows to get list of active users belonging to the
* specified group and its subgroups if "users" expand option is provided. You can page through users list by using
* indexes in expand param. For example to get users from index 10 to index 15 use "users[10:15]" expand value.
* This will return 6 users (if there are at least 16 users in this group). Indexes are 0-based and inclusive.
* DEPRECATED. This resource is deprecated, please use group/member API instead. (15-Feb-2018)
*
* @method getGroup
* @memberOf GroupClient#
* @param opts The request options sent to the Jira API
* @param opts.groupName A name of requested group.
* @param opts.expand Array of fields to expand. Currently only available expand is "users".
* @param [callback] Called when the group is retrieved.
* @return {Promise} Resolved when the group is retrieved.
*/
this.getGroup = function (opts, callback) {
var qs = {
groupname: opts.groupName
};
if (opts.expand) {
qs.expand = '';
opts.expand.forEach(function (ex) {
qs.expand += ex + ','
});
}
var options = {
uri: this.jiraClient.buildURL('/group'),
method: 'GET',
json: true,
followAllRedirects: true,
qs: qs
};
return this.jiraClient.makeRequest(options, callback);
};
/**
* This resource returns a paginated list of users who are members of the specified group and its subgroups.
* Users in the page are ordered by user names.
* User of this resource is required to have sysadmin or admin permissions.
*
* @method getMembers
* @memberOf GroupClient#
* @param {Object} opts The request options sent to the Jira API
* @param {String} opts.groupName A name of requested group.
* @param {Boolean} opts.includeInactiveUsers inactive users will be included in the response if set to true. Default false.
* @param {Number} opts.startAt the index of the first user in group to return (0 based).
* @param {Number} opts.maxResults the maximum number of users to return (max 50).
* @param [callback] Called when the group is retrieved.
* @return {Promise} Resolved when the group is retrieved.
*/
this.getMembers = function (opts, callback) {
var qs = {
groupname: opts.groupName,
includeInactiveUsers: opts.includeInactiveUsers,
startAt: opts.startAt,
maxResults: opts.maxResults,
};
var options = {
uri: this.jiraClient.buildURL('/group/member'),
method: 'GET',
json: true,
followAllRedirects: true,
qs: qs
};
return this.jiraClient.makeRequest(options, callback);
};
/**
* Adds given user to a group. Returns the current state of the group.
*
* @method addUserToGroup
* @memberOf GroupClient#
* @param {Object} opts The request options sent to the Jira API
* @param {string} opts.groupName A name of requested group.
* @param {string} opts.userName The name of the user to add to the group.
* @param [callback] Called when the user has been added to the group.
* @return {Promise} Resolved when the user has been added to the group.
*/
this.addUserToGroup = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('/group/user'),
method: 'POST',
json: true,
followAllRedirects: true,
qs: {
groupname: opts.groupName
},
body: {
name: opts.userName
}
};
return this.jiraClient.makeRequest(options, callback);
};
/**
* Removes given user from a group. Returns no content
*
* @method removeUserFromGroup
* @memberOf GroupClient#
* @param {Object} opts The request options sent to the Jira API
* @param {string} opts.groupName A name of requested group.
* @param {string} opts.userName The name of the user to add to the group.
* @param [callback] Called when the user has been added to the group.
* @return {Promise} Resolved when the user has been added to the group.
*/
this.removeUserFromGroup = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('/group/user'),
method: 'DELETE',
json: true,
followAllRedirects: true,
qs: {
groupname: opts.groupName,
username: opts.userName
}
};
return this.jiraClient.makeRequest(options, callback, 'User Removed from Group');
};
/**
* Deletes a group by given group parameter. Returns no content
*
* @method deleteGroup
* @memberOf GroupClient#
* @param {Object} opts The request options sent to the Jira API
* @param {string} opts.groupName A group to delete.
* @param {string} [opts.swapGroup] A group to transfer visibility restrictions of the group that is being deleted
* @param [callback] Called when the group has been deleted.
* @return {Promise} Resolved when the group has been deleted.
*/
this.deleteGroup = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('/group'),
method: 'DELETE',
json: true,
followAllRedirects: true,
qs: {
groupname: opts.groupName,
swapGroup: opts.swapGroup
}
};
return this.jiraClient.makeRequest(options, callback, 'Group Deleted');
};
}