Skip to content
Draft
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
1 change: 1 addition & 0 deletions src/common/types/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ type SharedLink = {

type SharedLinkFeatures = {
download_url: boolean,
expiration?: boolean,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't expiration always exist now since we have added the field in the response

password: boolean,
vanity_name: boolean,
};
Expand Down
1 change: 1 addition & 0 deletions src/elements/content-sharing/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export type ContentSharingItemAPIResponse = {
shared_link?: APISharedLink,
shared_link_features: {
download_url: boolean,
expiration?: boolean,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

password: boolean,
vanity_name: boolean,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const DEFAULT_ITEM_API_RESPONSE = {
owned_by: mockOwner,
permissions: MOCK_PERMISSIONS,
shared_link: null,
shared_link_features: { download_url: true, password: true, vanity_name: true },
shared_link_features: { download_url: true, expiration: true, password: true, vanity_name: true },
shared_link_permission_options: ['can_edit', 'can_download', 'can_preview'],
type: MOCK_ITEM.type,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('convertItemResponse', () => {
const result = convertItemResponse(MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK_WITH_PERMISSIONS);
expect(result.sharedLink.settings.canChangeDownload).toEqual(false);
expect(result.sharedLink.settings.canChangePassword).toEqual(false);
expect(result.sharedLink.settings.canChangeExpiration).toEqual(false);
expect(result.sharedLink.settings.canChangeExpiration).toEqual(true);
});

test('should convert shared link settings correctly if user does not have permissions', () => {
Expand All @@ -138,7 +138,7 @@ describe('convertItemResponse', () => {
...MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK.shared_link,
effective_access: 'collaborators',
},
shared_link_features: { download_url: false, password: false, vanity_name: false },
shared_link_features: { download_url: false, expiration: false, password: false, vanity_name: false },
permissions: {
...MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK.permissions,
},
Expand All @@ -150,6 +150,20 @@ describe('convertItemResponse', () => {
expect(result.sharedLink.settings.isDirectLinkAvailable).toEqual(false);
expect(result.sharedLink.settings.isVanityNameAvailable).toEqual(false);
});

test.each([
['expiration false greys the switch', false, false],
['expiration true leaves the switch on', true, true],
])('%s', (_name, expiration, expected) => {
const result = convertItemResponse({
...MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK,
shared_link_features: {
...MOCK_ITEM_API_RESPONSE_WITH_SHARED_LINK.shared_link_features,
expiration,
},
});
expect(result.sharedLink.settings.canChangeExpiration).toEqual(expected);
});
});

describe('direct link availability', () => {
Expand Down
5 changes: 2 additions & 3 deletions src/elements/content-sharing/utils/convertItemResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const convertItemResponse = (itemApiData: ContentSharingItemAPIResponse):

const {
download_url: isDirectLinkAvailable,
expiration: canChangeExpirationFromServer,
password: isPasswordAvailable,
vanity_name: isVanityNameAvailable,
} = shared_link_features;
Expand All @@ -47,8 +48,6 @@ export const convertItemResponse = (itemApiData: ContentSharingItemAPIResponse):
};
}

const isEditAllowed = allowed_invitee_roles.includes(INVITEE_ROLE_EDITOR);

let sharedLink;
if (shared_link) {
const {
Expand All @@ -65,7 +64,7 @@ export const convertItemResponse = (itemApiData: ContentSharingItemAPIResponse):
const isDownloadAllowed = permission === PERMISSION_CAN_DOWNLOAD || permission === PERMISSION_CAN_EDIT;
const canChangeDownload = canChangeAccessLevel && isDownloadSettingAvailable && access !== ACCESS_COLLAB; // access must be "company" or "open"
const canChangePassword = canChangeAccessLevel && isPasswordAvailable;
const canChangeExpiration = canChangeAccessLevel && isEditAllowed;
const canChangeExpiration = canChangeExpirationFromServer;

sharedLink = {
access,
Expand Down
Loading