From d831ffc5fe8fd3785ae54567fdeac030d5321d3d Mon Sep 17 00:00:00 2001 From: lethemanh Date: Fri, 16 May 2025 20:19:20 +0700 Subject: [PATCH] Add flag to always allow share by link --- tdrive/backend/node/src/services/documents/services/index.ts | 4 ++-- .../node/src/services/documents/web/controllers/documents.ts | 2 +- .../frontend/src/app/features/drive/api-client/api-client.ts | 2 +- .../src/app/features/drive/hooks/use-drive-actions.tsx | 2 +- .../frontend/src/app/features/drive/hooks/use-drive-item.tsx | 2 +- .../app/views/client/body/drive/modals/public-link/index.tsx | 5 ++++- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tdrive/backend/node/src/services/documents/services/index.ts b/tdrive/backend/node/src/services/documents/services/index.ts index a9464970..3dc04bf7 100644 --- a/tdrive/backend/node/src/services/documents/services/index.ts +++ b/tdrive/backend/node/src/services/documents/services/index.ts @@ -550,7 +550,7 @@ export class DocumentsService { */ update = async ( id: string, - content: Partial, + content: Partial & { is_update_access_to_share_link?: boolean }, context: CompanyExecutionContext, ): Promise => { if (!context) { @@ -614,7 +614,7 @@ export class DocumentsService { } if (key === "access_info") { // if manage access is disabled, we don't allow changing access level - if (!this.manageAccessEnabled) { + if (!this.manageAccessEnabled && !content.is_update_access_to_share_link) { delete content.access_info; } else if (content.access_info) { const sharedWith = content.access_info.entities.filter( diff --git a/tdrive/backend/node/src/services/documents/web/controllers/documents.ts b/tdrive/backend/node/src/services/documents/web/controllers/documents.ts index e382bf78..6dcc15b4 100644 --- a/tdrive/backend/node/src/services/documents/web/controllers/documents.ts +++ b/tdrive/backend/node/src/services/documents/web/controllers/documents.ts @@ -257,7 +257,7 @@ export class DocumentsController { update = async ( request: FastifyRequest<{ Params: ItemRequestParams; - Body: Partial; + Body: Partial & { is_update_access_to_share_link?: boolean }; Querystring: { public_token?: string }; }>, ): Promise => { diff --git a/tdrive/frontend/src/app/features/drive/api-client/api-client.ts b/tdrive/frontend/src/app/features/drive/api-client/api-client.ts index fe4e562e..81054002 100644 --- a/tdrive/frontend/src/app/features/drive/api-client/api-client.ts +++ b/tdrive/frontend/src/app/features/drive/api-client/api-client.ts @@ -114,7 +114,7 @@ export class DriveApiClient { ); } - static async update(companyId: string, id: string, update: Partial) { + static async update(companyId: string, id: string, update: Partial & { is_update_access_to_share_link?: boolean }) { return await Api.post, DriveItem>( `/internal/services/documents/v1/companies/${companyId}/item/${id}${appendTdriveToken()}`, update, diff --git a/tdrive/frontend/src/app/features/drive/hooks/use-drive-actions.tsx b/tdrive/frontend/src/app/features/drive/hooks/use-drive-actions.tsx index f009250c..5e98d7bf 100644 --- a/tdrive/frontend/src/app/features/drive/hooks/use-drive-actions.tsx +++ b/tdrive/frontend/src/app/features/drive/hooks/use-drive-actions.tsx @@ -235,7 +235,7 @@ export const useDriveActions = (inPublicSharing?: boolean) => { ); const update = useCallback( - async (update: Partial, id: string, parentId: string, previousName?: string) => { + async (update: Partial & { is_update_access_to_share_link?: boolean }, id: string, parentId: string, previousName?: string) => { try { const newItem = await DriveApiClient.update(companyId, id, update); if (previousName && previousName !== newItem.name && !update.name) diff --git a/tdrive/frontend/src/app/features/drive/hooks/use-drive-item.tsx b/tdrive/frontend/src/app/features/drive/hooks/use-drive-item.tsx index 41f901b6..bfb9f6fe 100644 --- a/tdrive/frontend/src/app/features/drive/hooks/use-drive-item.tsx +++ b/tdrive/frontend/src/app/features/drive/hooks/use-drive-item.tsx @@ -65,7 +65,7 @@ export const useDriveItem = (id: string) => { }, [id, setLoading, refresh, item?.item?.parent_id]); const update = useCallback( - async (update: Partial, skipLoading = false) => { + async (update: Partial & { is_update_access_to_share_link?: boolean }, skipLoading = false) => { if (!skipLoading) setLoading(true); try { await _update(update, id, item?.item?.parent_id || ''); diff --git a/tdrive/frontend/src/app/views/client/body/drive/modals/public-link/index.tsx b/tdrive/frontend/src/app/views/client/body/drive/modals/public-link/index.tsx index cf7da355..3f03be72 100644 --- a/tdrive/frontend/src/app/views/client/body/drive/modals/public-link/index.tsx +++ b/tdrive/frontend/src/app/views/client/body/drive/modals/public-link/index.tsx @@ -140,7 +140,10 @@ const PublicLinkModalContent = (props: { disabled={loading} level={item?.access_info?.public?.level || 'none'} onChange={level => { - item && update(changePublicLink(item, { level })); + item && update({ + ...changePublicLink(item, { level }), + is_update_access_to_share_link: true, + }); }} />