-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathupdate.js
99 lines (90 loc) · 3.1 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
'use strict';
const BoxCommand = require('../../box-command');
const { Flags, Args } = require('@oclif/core');
const utils = require('../../util');
class FoldersUpdateCommand extends BoxCommand {
async run() {
const { flags, args } = await this.parse(FoldersUpdateCommand);
let updates = {};
if (flags.name) {
updates.name = flags.name;
}
if (flags.hasOwnProperty('can-non-owners-invite') ) {
updates.can_non_owners_invite = flags['can-non-owners-invite'];
}
if (flags.hasOwnProperty('can-non-owners-view-collaborators')) {
updates.can_non_owners_view_collaborators = flags['can-non-owners-view-collaborators'];
}
if (flags.hasOwnProperty('description')) {
updates.description = flags.description;
}
if (flags['upload-email-access']) {
updates.folder_upload_email = {
access: flags['upload-email-access']
};
}
if (flags.hasOwnProperty('restrict-collaboration')) {
updates.can_non_owners_invite = !flags['restrict-collaboration'];
}
if (flags.hasOwnProperty('restrict-to-enterprise')) {
updates.is_collaboration_restricted_to_enterprise = flags['restrict-to-enterprise'];
}
if (flags.tags) {
updates.tags = (flags.tags).split(',');
}
if (flags.hasOwnProperty('sync')) {
updates.sync_state = flags.sync ? 'synced' : 'not_synced';
}
if (flags.etag) {
updates.etag = flags.etag;
}
let updatedFolder = await this.client.folders.update(args.id, updates);
await this.output(updatedFolder);
}
}
FoldersUpdateCommand.description = 'Update a folder';
FoldersUpdateCommand.examples = ['box folders:update 22222 --name "New Folder Name"'];
FoldersUpdateCommand._endpoint = 'put_folders_id';
FoldersUpdateCommand.flags = {
...BoxCommand.flags,
name: Flags.string({ description: 'New name for folder' }),
'can-non-owners-invite': Flags.boolean({
description: 'Specifies if users who are not the owner of the folder can invite new collaborators to the folder.',
allowNo: true
}),
'can-non-owners-view-collaborators': Flags.boolean({
description: 'Restricts collaborators who are not the owner of this folder from viewing other collaborations on this folder.',
allowNo: true,
}),
description: Flags.string({ description: 'New description for folder', parse: utils.unescapeSlashes }),
'upload-email-access': Flags.string({
description: 'Upload email access level',
options: [
'open',
'collaborators'
],
}),
tags: Flags.string({ description: 'Comma seperated tags' }),
sync: Flags.boolean({
description: 'Whether the folder is synced to desktop',
allowNo: true
}),
'restrict-collaboration': Flags.boolean({
description: 'Restrict collaboration so only owners can invite new collaborators',
allowNo: true
}),
'restrict-to-enterprise': Flags.boolean({
description: 'Restrict collaboration so only users in the folder owner\'s enterprise can be added',
allowNo: true
}),
etag: Flags.string({ description: 'Only apply updates if the etag value matches' }),
};
FoldersUpdateCommand.args = {
id: Args.string({
name: 'id',
required: true,
hidden: false,
description: 'ID of the folder to update',
})
};
module.exports = FoldersUpdateCommand;