mirror of
https://github.com/immich-app/immich.git
synced 2025-06-03 05:34:32 -04:00
* rename albums_shared_users_users to album_permissions and add readonly column * disable synchronize on the original join table * remove unnecessary FK names * set readonly=true as default for new album shares * separate and implement album READ and WRITE permission * expose albumPermissions on the API, deprecate sharedUsers * generate openapi * create readonly view on frontend * ??? move slideshow button out from ellipsis menu so that non-owners can have access too * correct sharedUsers joins * add album permission repository * remove a log * fix assetCount getting reset when adding users * fix lint * add set permission endpoint and UI * sort users * remove log * Revert "??? move slideshow button out from ellipsis menu so that non-owners can have access too" This reverts commit 1343bfa31125f7136f81db28f7aa4c5ef0204847. * rename stuff * fix db schema annotations * sql generate * change readonly default to follow migration * fix deprecation notice * change readonly boolean to role enum * fix joincolumn as primary key * rename albumUserRepository in album service * clean up userId and albumId * add write access to shared link * fix existing tests * switch to vitest * format and fix tests on web * add new test * fix one e2e test * rename new API field to albumUsers * capitalize serverside enum * remove unused ReadWrite type * missed rename from previous commit * rename to albumUsers in album entity as well * remove outdated Equals calls * unnecessary relation * rename to updateUser in album service * minor renamery * move sorting to backend * rename and separate ALBUM_WRITE as ADD_ASSET and REMOVE_ASSET * fix tests * fix "should migrate single moving picture" test failing on European system timezone * generated changes after merge * lint fix * fix correct page to open after removing user from album * fix e2e tests and some bugs * rename updateAlbumUser rest endpoint * add new e2e tests for updateAlbumUser endpoint * small optimizations * refactor album e2e test, add new album shared with viewer * add new test to check if viewer can see the album * add new e2e tests for readonly share * failing test: User delete doesn't cascade to UserAlbum entity * fix: handle deleted users * use lodash for sort * add role to addUsersToAlbum endpoint * add UI for adding editors * lint fixes * change role back to editor as DB default * fix server tests * redesign user selection modal editor selector * style tweaks * fix type error * Revert "style tweaks" This reverts commit ab604f4c8f3a6f12ab0b5fe2dd2ede723aa68775. * Revert "redesign user selection modal editor selector" This reverts commit e6f344856c6c05e4eb5c78f0dffb9f52498795f4. * chore: cleanup and improve add user modal * chore: open api * small styling --------- Co-authored-by: mgabor <> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
181 lines
6.0 KiB
Svelte
181 lines
6.0 KiB
Svelte
<script lang="ts">
|
|
import { goto } from '$app/navigation';
|
|
import Dropdown from '$lib/components/elements/dropdown.svelte';
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
|
import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte';
|
|
import { AppRoute } from '$lib/constants';
|
|
import {
|
|
AlbumUserRole,
|
|
getAllSharedLinks,
|
|
getAllUsers,
|
|
type AlbumResponseDto,
|
|
type AlbumUserAddDto,
|
|
type SharedLinkResponseDto,
|
|
type UserResponseDto,
|
|
} from '@immich/sdk';
|
|
import { mdiCheck, mdiEye, mdiLink, mdiPencil, mdiShareCircle } from '@mdi/js';
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
import Button from '../elements/buttons/button.svelte';
|
|
import UserAvatar from '../shared-components/user-avatar.svelte';
|
|
|
|
export let album: AlbumResponseDto;
|
|
export let onClose: () => void;
|
|
let users: UserResponseDto[] = [];
|
|
let selectedUsers: Record<string, { user: UserResponseDto; role: AlbumUserRole }> = {};
|
|
|
|
const roleOptions: Array<{ title: string; value: AlbumUserRole | 'none'; icon?: string }> = [
|
|
{ title: 'Editor', value: AlbumUserRole.Editor, icon: mdiPencil },
|
|
{ title: 'Viewer', value: AlbumUserRole.Viewer, icon: mdiEye },
|
|
{ title: 'Remove', value: 'none' },
|
|
];
|
|
|
|
const dispatch = createEventDispatcher<{
|
|
select: AlbumUserAddDto[];
|
|
share: void;
|
|
}>();
|
|
let sharedLinks: SharedLinkResponseDto[] = [];
|
|
onMount(async () => {
|
|
await getSharedLinks();
|
|
const data = await getAllUsers({ isAll: false });
|
|
|
|
// remove invalid users
|
|
users = data.filter((user) => !(user.deletedAt || user.id === album.ownerId));
|
|
|
|
// Remove the existed shared users from the album
|
|
for (const sharedUser of album.sharedUsers) {
|
|
users = users.filter((user) => user.id !== sharedUser.id);
|
|
}
|
|
});
|
|
|
|
const getSharedLinks = async () => {
|
|
const data = await getAllSharedLinks();
|
|
sharedLinks = data.filter((link) => link.album?.id === album.id);
|
|
};
|
|
|
|
const handleToggle = (user: UserResponseDto) => {
|
|
if (Object.keys(selectedUsers).includes(user.id)) {
|
|
delete selectedUsers[user.id];
|
|
selectedUsers = selectedUsers;
|
|
} else {
|
|
selectedUsers[user.id] = { user, role: AlbumUserRole.Editor };
|
|
}
|
|
};
|
|
|
|
const handleChangeRole = (user: UserResponseDto, role: AlbumUserRole | 'none') => {
|
|
if (role === 'none') {
|
|
delete selectedUsers[user.id];
|
|
selectedUsers = selectedUsers;
|
|
} else {
|
|
selectedUsers[user.id].role = role;
|
|
}
|
|
};
|
|
</script>
|
|
|
|
<FullScreenModal id="user-selection-modal" title="Invite to album" showLogo {onClose}>
|
|
{#if Object.keys(selectedUsers).length > 0}
|
|
<div class="mb-2 py-2 sticky">
|
|
<p class="text-xs font-medium">SELECTED</p>
|
|
<div class="my-2">
|
|
{#each Object.values(selectedUsers) as { user }}
|
|
{#key user.id}
|
|
<div class="flex place-items-center gap-4 p-4">
|
|
<div
|
|
class="flex h-10 w-10 items-center justify-center rounded-full border bg-immich-dark-success text-3xl text-white dark:border-immich-dark-gray dark:bg-immich-dark-success"
|
|
>
|
|
<Icon path={mdiCheck} size={24} />
|
|
</div>
|
|
|
|
<!-- <UserAvatar {user} size="md" /> -->
|
|
<div class="text-left flex-grow">
|
|
<p class="text-immich-fg dark:text-immich-dark-fg">
|
|
{user.name}
|
|
</p>
|
|
<p class="text-xs">
|
|
{user.email}
|
|
</p>
|
|
</div>
|
|
|
|
<Dropdown
|
|
title="Role"
|
|
options={roleOptions}
|
|
render={({ title, icon }) => ({ title, icon })}
|
|
on:select={({ detail: { value } }) => handleChangeRole(user, value)}
|
|
/>
|
|
</div>
|
|
{/key}
|
|
{/each}
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
|
|
{#if users.length + Object.keys(selectedUsers).length === 0}
|
|
<p class="p-5 text-sm">
|
|
Looks like you have shared this album with all users or you don't have any user to share with.
|
|
</p>
|
|
{/if}
|
|
|
|
<div class="immich-scrollbar max-h-[500px] overflow-y-auto">
|
|
{#if users.length > 0 && users.length !== Object.keys(selectedUsers).length}
|
|
<p class="text-xs font-medium">SUGGESTIONS</p>
|
|
|
|
<div class="my-2">
|
|
{#each users as user}
|
|
{#if !Object.keys(selectedUsers).includes(user.id)}
|
|
<div class="flex place-items-center transition-all hover:bg-gray-200 dark:hover:bg-gray-700 rounded-xl">
|
|
<button on:click={() => handleToggle(user)} class="flex w-full place-items-center gap-4 p-4">
|
|
<UserAvatar {user} size="md" />
|
|
<div class="text-left flex-grow">
|
|
<p class="text-immich-fg dark:text-immich-dark-fg">
|
|
{user.name}
|
|
</p>
|
|
<p class="text-xs">
|
|
{user.email}
|
|
</p>
|
|
</div>
|
|
</button>
|
|
</div>
|
|
{/if}
|
|
{/each}
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
|
|
{#if users.length > 0}
|
|
<div class="py-3">
|
|
<Button
|
|
size="sm"
|
|
fullwidth
|
|
rounded="full"
|
|
disabled={Object.keys(selectedUsers).length === 0}
|
|
on:click={() =>
|
|
dispatch(
|
|
'select',
|
|
Object.values(selectedUsers).map(({ user, ...rest }) => ({ userId: user.id, ...rest })),
|
|
)}>Add</Button
|
|
>
|
|
</div>
|
|
{/if}
|
|
|
|
<hr />
|
|
|
|
<div id="shared-buttons" class="mt-4 flex place-content-center place-items-center justify-around">
|
|
<button
|
|
class="flex flex-col place-content-center place-items-center gap-2 hover:cursor-pointer"
|
|
on:click={() => dispatch('share')}
|
|
>
|
|
<Icon path={mdiLink} size={24} />
|
|
<p class="text-sm">Create link</p>
|
|
</button>
|
|
|
|
{#if sharedLinks.length}
|
|
<button
|
|
class="flex flex-col place-content-center place-items-center gap-2 hover:cursor-pointer"
|
|
on:click={() => goto(AppRoute.SHARED_LINKS)}
|
|
>
|
|
<Icon path={mdiShareCircle} size={24} />
|
|
<p class="text-sm">View links</p>
|
|
</button>
|
|
{/if}
|
|
</div>
|
|
</FullScreenModal>
|