-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathupdate.js
161 lines (153 loc) · 4.24 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
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
'use strict';
const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
class UsersUpdateCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(UsersUpdateCommand);
let updates = {};
if (flags.hasOwnProperty('sync-enable')) {
updates.is_sync_enabled = flags['sync-enable'];
}
if (flags['password-reset']) {
updates.is_password_reset_required = true;
}
if (flags.hasOwnProperty('exempt-from-device-limits')) {
updates.is_exempt_from_device_limits = flags['exempt-from-device-limits'];
}
if (flags.hasOwnProperty('exempt-from-2fa')) {
updates.is_exempt_login_verification = flags['exempt-from-2fa'];
}
if (flags.hasOwnProperty('restrict-external-collab')) {
updates.is_external_collab_restricted = flags['restrict-external-collab'];
}
if (flags.hasOwnProperty('can-see-managed-users')) {
updates.can_see_managed_users = flags['can-see-managed-users'];
}
if (flags.role) {
updates.role = flags.role;
}
if (flags.language) {
updates.language = flags.language;
}
if (flags['job-title']) {
updates.job_title = flags['job-title'];
}
if (flags['phone-number']) {
updates.phone = flags['phone-number'];
}
if (flags.address) {
updates.address = flags.address;
}
if (flags['disk-space']) {
updates.space_amount = parseInt(flags['disk-space'], 10);
}
if (flags.status) {
updates.status = flags.status;
}
if (flags.timezone) {
updates.timezone = flags.timezone;
}
if (flags.remove) {
updates.enterprise = null;
}
if (flags.login) {
updates.login = flags.login;
}
if (flags.name) {
updates.name = flags.name;
}
if (flags['external-id']) {
updates.external_app_user_id = flags['external-id'];
}
let user = await this.client.users.update(args.id, updates);
await this.output(user);
}
}
UsersUpdateCommand.description = 'Update a Box User';
UsersUpdateCommand.examples = ['box users:update 33333 --status inactive'];
UsersUpdateCommand._endpoint = 'put_users_id';
UsersUpdateCommand.flags = {
...BoxCommand.flags,
remove: flags.boolean({
description: 'Remove the user from the enterprise, convert to free account'
}),
name: flags.string({
char: 'n',
description: 'Set the user\'s name',
}),
'sync-enable': flags.boolean({
description: 'Enable Box Sync for this user',
allowNo: true,
}),
'exempt-from-device-limits': flags.boolean({
description: 'Exempt user from device limits',
allowNo: true
}),
'exempt-from-2fa': flags.boolean({
description: 'Exempt user from two-factor auth',
allowNo: true
}),
'restrict-external-collab': flags.boolean({
description: 'Restrict user from external collaboration',
allowNo: true
}),
'can-see-managed-users': flags.boolean({
description: 'User can see managed users',
allowNo: true
}),
'password-reset': flags.boolean({
description: 'Force the user to reset password'
}),
role: flags.string({
char: 'r',
description: 'Role of user. Enter user or coadmin',
options: [
'user',
'coadmin'
]
}),
language: flags.string({
char: 'l',
description: 'Language of the user (ISO 639-1 Language Code). https://developer.box.com/v2.0/docs/api-language-codes'
}),
'job-title': flags.string({
char: 'j',
description: 'Job title of the user'
}),
'phone-number': flags.string({
char: 'p',
description: 'Phone number of the user'
}),
address: flags.string({
char: 'a',
description: 'Address of the user'
}),
'disk-space': flags.string({
char: 'd',
description: 'User\'s available storage in bytes. Value of -1 grants unlimited storage'
}),
status: flags.string({
char: 'S',
description: 'User status. Enter active, inactive, cannot_delete_edit, or cannot_delete_edit_upload',
options: [
'active',
'inactive',
'cannot_delete_edit',
'cannot_delete_edit_upload'
]
}),
timezone: flags.string({ description: 'The user\'s timezone. Input format follows tz database timezones' }),
login: flags.string({ description: 'Change the user\'s primary email address used for logging into Box '}),
'external-id': flags.string({
description: 'External ID for app users',
}),
};
UsersUpdateCommand.args = [
{
name: 'id',
required: true,
hidden: false,
description: 'User ID to update',
}
];
module.exports = UsersUpdateCommand;