-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathadd.js
More file actions
108 lines (97 loc) · 2.9 KB
/
add.js
File metadata and controls
108 lines (97 loc) · 2.9 KB
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
'use strict';
const BoxCommand = require('../../../box-command');
const { Flags, Args } = require('@oclif/core');
class GroupsAddMembershipCommand extends BoxCommand {
async run() {
const { flags, args } = await this.parse(GroupsAddMembershipCommand);
let options = { configurable_permissions: {} };
if (Object.hasOwn(flags, 'can-run-reports')) {
options.configurable_permissions.can_run_reports =
flags['can-run-reports'];
}
if (Object.hasOwn(flags, 'can-instant-login')) {
options.configurable_permissions.can_instant_login =
flags['can-instant-login'];
}
if (Object.hasOwn(flags, 'can-create-accounts')) {
options.configurable_permissions.can_create_accounts =
flags['can-create-accounts'];
}
if (Object.hasOwn(flags, 'can-edit-accounts')) {
options.configurable_permissions.can_edit_accounts =
flags['can-edit-accounts'];
}
// Set role from the "role" flag first, since it has a default value
options.role = flags.role;
if (flags['set-admin']) {
options.role = this.client.groups.userRoles.ADMIN;
} else if (flags['set-member']) {
options.role = this.client.groups.userRoles.MEMBER;
}
let membership = await this.client.groups.addUser(
args.groupID,
args.userID,
options
);
await this.output(membership);
}
}
GroupsAddMembershipCommand.aliases = ['groups:membership:add'];
GroupsAddMembershipCommand.description = 'Add a user to a group';
GroupsAddMembershipCommand.examples = [
'box groups:memberships:add 33333 12345',
];
GroupsAddMembershipCommand._endpoint = 'post_group_memberships';
GroupsAddMembershipCommand.flags = {
...BoxCommand.flags,
role: Flags.string({
char: 'r',
description: "Set the user's role in the group",
default: 'member',
options: ['member', 'admin'],
}),
'set-admin': Flags.boolean({
description: "Set the user's role to Group Admin",
exclusive: ['set-member'],
hidden: true,
}),
'set-member': Flags.boolean({
description: "Set the user's role to Group Member",
exclusive: ['set-admin'],
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,
}),
};
GroupsAddMembershipCommand.args = {
userID: Args.string({
name: 'userID',
required: true,
hidden: false,
description: 'ID of the user to add to the group',
}),
groupID: Args.string({
name: 'groupID',
required: true,
hidden: false,
description: 'ID of the group to add the user to',
}),
};
module.exports = GroupsAddMembershipCommand;