-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathcreate.js
166 lines (158 loc) · 4.39 KB
/
create.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
'use strict';
const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');
const BoxCLIError = require('../../cli-error');
class UsersCreateCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(UsersCreateCommand);
let options = {};
let user;
if (flags.hasOwnProperty('sync-enable')) {
options.is_sync_enabled = flags['sync-enable'];
}
if (flags['password-reset']) {
options.is_password_reset_required = true;
}
if (flags.hasOwnProperty('exempt-from-device-limits')) {
options.is_exempt_from_device_limits = flags['exempt-from-device-limits'];
}
if (flags.hasOwnProperty('exempt-from-2fa')) {
options.is_exempt_login_verification = flags['exempt-from-2fa'];
}
if (flags.hasOwnProperty('restrict-external-collab')) {
options.is_external_collab_restricted = flags['restrict-external-collab'];
}
if (flags.hasOwnProperty('can-see-managed-users')) {
options.can_see_managed_users = flags['can-see-managed-users'];
}
if (flags.role) {
options.role = flags.role;
}
if (flags.language) {
options.language = flags.language;
}
if (flags['job-title']) {
options.job_title = flags['job-title'];
}
if (flags['phone-number']) {
options.phone = flags['phone-number'];
}
if (flags.address) {
options.address = flags.address;
}
if (flags['disk-space']) {
options.space_amount = parseInt(flags['disk-space'], 10);
}
if (flags.status) {
options.status = flags.status;
}
if (flags.timezone) {
options.timezone = flags.timezone;
}
if (flags['external-id']) {
options.external_app_user_id = flags['external-id'];
}
if (flags['app-user']) {
user = await this.client.enterprise.addAppUser(args.name, options);
} else if (args.login) {
user = await this.client.enterprise.addUser(args.login, args.name, options);
} else {
throw new BoxCLIError('Either the login argument or the --app-user flag is required');
}
await this.output(user);
}
}
UsersCreateCommand.description = 'Create a new Box User';
UsersCreateCommand.examples = ['box users:create "John Doe" jdoe@example.com'];
UsersCreateCommand._endpoint = 'post_users';
UsersCreateCommand.flags = {
...BoxCommand.flags,
'app-user': flags.boolean({
description: 'Set this user as an app user'
}),
'external-id': flags.string({
description: 'External ID for app users',
dependsOn: ['app-user'],
}),
'id-only': flags.boolean({
description: 'Return only an ID to output from this command'
}),
'sync-enable': flags.boolean({
description: 'Enable Box Sync for this user',
exclusive: ['sync-disable'],
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',
options: [
'active',
'inactive',
'cannot_delete_edit',
'cannot_delete_edit_upload'
]
}),
timezone: flags.string({ description: 'The user\'s timezone. Input format follows tz database timezones' }),
};
UsersCreateCommand.args = [
{
name: 'name',
required: true,
hidden: false,
description: 'The user\'s name'
},
{
name: 'login',
required: false,
hidden: false,
description: 'The user\'s email address, not required when creating app users'
}
];
module.exports = UsersCreateCommand;