-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathupdate.js
100 lines (91 loc) · 2.76 KB
/
update.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
'use strict';
const BoxCommand = require('../../../box-command');
const { flags } = require('@oclif/command');
class GroupsUpdateMembershipCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(GroupsUpdateMembershipCommand);
let options = { configurable_permissions: {} };
if (flags.hasOwnProperty('can-run-reports')) {
options.configurable_permissions.can_run_reports = flags['can-run-reports'];
}
if (flags.hasOwnProperty('can-instant-login')) {
options.configurable_permissions.can_instant_login = flags['can-instant-login'];
}
if (flags.hasOwnProperty('can-create-accounts')) {
options.configurable_permissions.can_create_accounts = flags['can-create-accounts'];
}
if (flags.hasOwnProperty('can-edit-accounts')) {
options.configurable_permissions.can_edit_accounts = flags['can-edit-accounts'];
}
if (flags['set-admin']) {
options.role = this.client.groups.userRoles.ADMIN;
} else if (flags['set-member']) {
options.role = this.client.groups.userRoles.MEMBER;
}
if (flags.role) {
options.role = flags.role;
}
let membership = await this.client.groups.updateMembership(args.id, options);
await this.output(membership);
}
}
GroupsUpdateMembershipCommand.aliases = [ 'groups:membership:update' ];
GroupsUpdateMembershipCommand.description = 'Update a user\'s membership to a group';
GroupsUpdateMembershipCommand.examples = ['box groups:memberships:update'];
GroupsUpdateMembershipCommand._endpoint = 'put_group_memberships_id';
GroupsUpdateMembershipCommand.flags = {
...BoxCommand.flags,
role: flags.string({
char: 'r',
description: 'Set the user\'s role in the group',
options: [
'member',
'admin'
],
exclusive: [
'set-admin',
'set-member'
],
}),
'set-admin': flags.boolean({
description: 'Set the user\'s role to Group Admin',
exclusive: [
'set-member',
'role'
],
hidden: true,
}),
'set-member': flags.boolean({
description: 'Set the user\'s role to Group Member',
exclusive: [
'set-admin',
'role'
],
hidden: true,
}),
'can-run-reports': flags.boolean({
description: 'If the user is a group admin, allow them to run reports',
allowNo: true,
}),
'can-instant-login': flags.boolean({
description: 'If the user is a group admin, allow them to instant login',
allowNo: true,
}),
'can-create-accounts': flags.boolean({
description: 'If the user is a group admin, allow them to create new users',
allowNo: true,
}),
'can-edit-accounts': flags.boolean({
description: 'If the user is a group admin, allow them to edit user accounts',
allowNo: true,
}),
};
GroupsUpdateMembershipCommand.args = [
{
name: 'id',
required: true,
hidden: false,
description: 'ID of the group membership to update',
}
];
module.exports = GroupsUpdateMembershipCommand;