Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for vanity_name when creating shared-links #524

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 5 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 All @@ -1078,6 +1081,7 @@ describe('Files', () => {
'--access=test',
'--password=test',
'--can-download',
`--vanity-name=${vanityName}`,
'--can-edit',
'--token=test'
])
Expand Down
6 changes: 5 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 All @@ -937,6 +940,7 @@ describe('Folders', () => {
'--access=test',
'--password=test',
'--can-download',
`--vanity-name=${vanityName}`,
'--token=test'
])
.it('should create a shared link for a Box item with access, password and can-download flags passed (YAML Output)', ctx => {
Expand Down
4 changes: 4 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 All @@ -94,6 +97,7 @@ describe('Shared-Links', () => {
'file',
'--can-download',
'--can-edit',
`--vanity-name=${vanityName}`,
'--token=test',
'--json',
])
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
Loading