Skip to content

High performance self-hosted photo and video management solution.

fix(web): show shared link download button when logged in (#26629)

Snowknight26b282d83e95a5
diff --git a/web/src/lib/services/asset.service.spec.ts b/web/src/lib/services/asset.service.spec.ts
new file mode 100644
index 0000000000..a94d86be47
--- /dev/null
+++ b/web/src/lib/services/asset.service.spec.ts
@@ -0,0 +1,37 @@
+import { getAssetActions } from '$lib/services/asset.service';
+import { user as userStore } from '$lib/stores/user.store';
+import { setSharedLink } from '$lib/utils';
+import { assetFactory } from '@test-data/factories/asset-factory';
+import { sharedLinkFactory } from '@test-data/factories/shared-link-factory';
+import { userAdminFactory } from '@test-data/factories/user-factory';
+
+describe('AssetService', () => {
+ describe('getAssetActions', () => {
+ it('should allow shared link downloads if the user owns the asset and shared link downloads are disabled', () => {
+ const ownerId = 'owner';
+ const user = userAdminFactory.build({ id: ownerId });
+ const asset = assetFactory.build({ ownerId });
+ userStore.set(user);
+ setSharedLink(sharedLinkFactory.build({ allowDownload: false }));
+ const assetActions = getAssetActions(() => '', asset);
+ expect(assetActions.SharedLinkDownload.$if?.()).toStrictEqual(true);
+ });
+
+ it('should not allow shared link downloads if the user does not own the asset and shared link downloads are disabled', () => {
+ const ownerId = 'owner';
+ const user = userAdminFactory.build({ id: 'non-owner' });
+ const asset = assetFactory.build({ ownerId });
+ userStore.set(user);
+ setSharedLink(sharedLinkFactory.build({ allowDownload: false }));
+ const assetActions = getAssetActions(() => '', asset);
+ expect(assetActions.SharedLinkDownload.$if?.()).toStrictEqual(false);
+ });
+
+ it('should allow shared link downloads if shared link downloads are enabled regardless of user', () => {
+ const asset = assetFactory.build();
+ setSharedLink(sharedLinkFactory.build({ allowDownload: true }));
+ const assetActions = getAssetActions(() => '', asset);
+ expect(assetActions.SharedLinkDownload.$if?.()).toStrictEqual(true);
+ });
+ });
+});
diff --git a/web/src/lib/services/asset.service.ts b/web/src/lib/services/asset.service.ts
index bbe4d9301b..a2dddbba51 100644
--- a/web/src/lib/services/asset.service.ts
+++ b/web/src/lib/services/asset.service.ts
@@ -106,7 +106,7 @@ export const getAssetActions = ($t: MessageFormatter, asset: AssetResponseDto) =
title: $t('share'),
icon: mdiShareVariantOutline,
type: $t('assets'),
- $if: () => !!(get(authUser) && !asset.isTrashed && asset.visibility !== AssetVisibility.Locked),
+ $if: () => !!(currentAuthUser && !asset.isTrashed && asset.visibility !== AssetVisibility.Locked),
onAction: () => modalManager.show(SharedLinkCreateModal, { assetIds: [asset.id] }),
};
@@ -129,7 +129,7 @@ export const getAssetActions = ($t: MessageFormatter, asset: AssetResponseDto) =
const SharedLinkDownload: ActionItem = {
...Download,
- $if: () => !currentAuthUser && sharedLink && sharedLink.allowDownload,
+ $if: () => isOwner || !!sharedLink?.allowDownload,
};
const PlayMotionPhoto: ActionItem = {