Skip to content

Commit

Permalink
feat: Add support for vanity_name when creating shared-links
Browse files Browse the repository at this point in the history
  • Loading branch information
arjankowski committed Mar 1, 2024
1 parent f7b1b44 commit c709f30
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/commands/files/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FilesShareCommand.aliases = [
];

FilesShareCommand.description = 'Create a shared link for a file';
FilesShareCommand.examples = ['box files:share 11111 --access company'];
FilesShareCommand.examples = ['box files:share 11111 --access company --vanity-name my-custom-name-123'];
FilesShareCommand._endpoint = 'put_files_id create_shared_link';

FilesShareCommand.flags = {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/folders/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FoldersShareCommand.aliases = [
];

FoldersShareCommand.description = 'Create a shared link for a folder';
FoldersShareCommand.examples = ['box folders:share 22222 --access company'];
FoldersShareCommand.examples = ['box folders:share 22222 --access company --vanity-name my-custom-name-123'];
FoldersShareCommand._endpoint = 'put_folders_id create_shared_link';

FoldersShareCommand.flags = {
Expand Down
7 changes: 5 additions & 2 deletions src/commands/shared-links/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SharedLinksCreateCommand extends BoxCommand {
SharedLinksCreateCommand.aliases = ['shared-links:update'];

SharedLinksCreateCommand.description = 'Create a shared link for a Box item';
SharedLinksCreateCommand.examples = ['box shared-links:create 22222 folder --access company'];
SharedLinksCreateCommand.examples = ['box shared-links:create 22222 folder --access company --vanity-name my-custom-name-123'];

const sharedLinkFlags = {
...BoxCommand.flags,
Expand All @@ -30,7 +30,10 @@ const sharedLinkFlags = {
'can-download': flags.boolean({
description: 'Whether the shared link allows downloads',
allowNo: true
})
}),
'vanity-name': flags.string({
description: 'Defines a custom vanity name to use in the shared link URL. It should be between 12 and 30 characters. This field can contains only letters, numbers and hyphens.'
}),
};

const sharedLinkFileFlags = {
Expand Down
3 changes: 3 additions & 0 deletions src/modules/shared-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class SharedLinksModule {
if (flags.hasOwnProperty('can-download')) {
updates.shared_link.permissions.can_download = flags['can-download'];
}
if (flags['vanity-name']) {
updates.shared_link.vanity_name = flags['vanity-name'];
}

if (args.itemType === 'file') {
if (flags.hasOwnProperty('can-edit')) {
Expand Down
5 changes: 4 additions & 1 deletion test/commands/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ describe('Files', () => {
], function(command) {
describe(command, () => {
let fileId = '1234567890',
vanityName = 'my-custom-name-123',
unsharedDate = '2030-11-18T19:44:17+00:00',
createSharedLinkFixture = getFixture('files/put_files_id_shared_link'),
jsonOutput = getFixture('output/files_share_json.txt'),
Expand All @@ -1044,7 +1045,8 @@ describe('Files', () => {
shared_link: {
permissions: {can_download: true, can_edit: true},
access: 'test',
password: 'test'
password: 'test',
vanity_name: vanityName
}
};
test
Expand All @@ -1059,6 +1061,7 @@ describe('Files', () => {
'--access=test',
'--password=test',
'--can-download',
`--vanity-name=${vanityName}`,
'--can-edit',
'--json',
'--token=test'
Expand Down
5 changes: 4 additions & 1 deletion test/commands/folders.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ describe('Folders', () => {

describe(command, () => {
let folderId = '0',
vanityName = 'my-custom-name-123',
createSharedLinkFixture = getFixture('folders/put_folders_id_shared_link'),
unshareDate = '2030-03-04T12:34:56+00:00',
jsonOutput = getFixture('output/folders_share_json.txt'),
Expand All @@ -902,7 +903,8 @@ describe('Folders', () => {
shared_link: {
permissions: { can_download: true },
access: 'test',
password: 'test'
password: 'test',
vanity_name: vanityName
}
};

Expand All @@ -918,6 +920,7 @@ describe('Folders', () => {
'--access=test',
'--password=test',
'--can-download',
`--vanity-name=${vanityName}`,
'--json',
'--token=test'
])
Expand Down
3 changes: 3 additions & 0 deletions test/commands/shared-links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('Shared-Links', () => {

describe('shared-links:create', () => {
let fileId = '1234567890',
vanityName = 'my-custom-name-123',
createFileSharedLinkFixture = getFixture(
'files/put_files_id_shared_link'
),
Expand All @@ -59,6 +60,7 @@ describe('Shared-Links', () => {
let fileSharedLinkBody = {
shared_link: {
permissions: { can_download: true, can_edit: true },
vanity_name: vanityName
},
};

Expand All @@ -75,6 +77,7 @@ describe('Shared-Links', () => {
'file',
'--can-download',
'--can-edit',
`--vanity-name=${vanityName}`,
'--token=test',
])
.it('should create a shared link for a Box file (YAML Output)', (ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/files/put_files_id_shared_link.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"shared_link": {
"url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p",
"download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png",
"vanity_url": null,
"vanity_url": "https://app.box.com/v/my-custom-name-123",
"effective_access": "open",
"is_password_enabled": true,
"unshared_at": null,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/folders/put_folders_id_shared_link.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"shared_link": {
"url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p",
"download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png",
"vanity_url": null,
"vanity_url": "https://app.box.com/v/my-custom-name-123",
"effective_access": "open",
"is_password_enabled": true,
"unshared_at": null,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/files_share_json.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"shared_link": {
"url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p",
"download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png",
"vanity_url": null,
"vanity_url": "https://app.box.com/v/my-custom-name-123",
"effective_access": "open",
"is_password_enabled": true,
"unshared_at": null,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/files_share_yaml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Shared Link:
URL: 'https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p'
Download URL: >-
https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png
Vanity URL: null
Vanity URL: 'https://app.box.com/v/my-custom-name-123'
Effective Access: open
Is Password Enabled: true
Unshared At: null
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/folders_share_json.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"shared_link": {
"url": "https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p",
"download_url": "https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png",
"vanity_url": null,
"vanity_url": "https://app.box.com/v/my-custom-name-123",
"effective_access": "open",
"is_password_enabled": true,
"unshared_at": null,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/folders_share_yaml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Shared Link:
URL: 'https://blosserdemoaccount.box.com/s/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p'
Download URL: >-
https://blosserdemoaccount.box.com/shared/static/7mcmdlavtye5o5i0ue8xmtwh2sx5bv8p.png
Vanity URL: null
Vanity URL: 'https://app.box.com/v/my-custom-name-123'
Effective Access: open
Is Password Enabled: true
Unshared At: null
Expand Down

0 comments on commit c709f30

Please sign in to comment.