2022-12-09 15:51:42 -05:00
|
|
|
<script lang="ts">
|
2024-02-13 17:07:37 -05:00
|
|
|
import { page } from '$app/stores';
|
2024-04-08 21:02:09 +00:00
|
|
|
import DeleteConfirmDialog from '$lib/components/admin-page/delete-confirm-dialogue.svelte';
|
|
|
|
|
import RestoreDialogue from '$lib/components/admin-page/restore-dialogue.svelte';
|
2024-02-13 17:07:37 -05:00
|
|
|
import Icon from '$lib/components/elements/icon.svelte';
|
|
|
|
|
import CreateUserForm from '$lib/components/forms/create-user-form.svelte';
|
|
|
|
|
import EditUserForm from '$lib/components/forms/edit-user-form.svelte';
|
2023-10-13 11:02:28 -04:00
|
|
|
import UserPageLayout from '$lib/components/layouts/user-page-layout.svelte';
|
2024-09-19 18:20:09 -04:00
|
|
|
import ConfirmDialog from '$lib/components/shared-components/dialog/confirm-dialog.svelte';
|
2024-03-08 17:49:39 -05:00
|
|
|
import {
|
|
|
|
|
NotificationType,
|
|
|
|
|
notificationController,
|
|
|
|
|
} from '$lib/components/shared-components/notification/notification';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { locale } from '$lib/stores/preferences.store';
|
2025-01-15 15:09:19 -05:00
|
|
|
import { featureFlags, serverConfig } from '$lib/stores/server-config.store';
|
2023-12-12 17:35:28 +01:00
|
|
|
import { user } from '$lib/stores/user.store';
|
2024-03-08 17:49:39 -05:00
|
|
|
import { websocketEvents } from '$lib/stores/websocket';
|
2024-03-14 17:33:39 -04:00
|
|
|
import { copyToClipboard } from '$lib/utils';
|
2024-06-14 19:27:46 +02:00
|
|
|
import { getByteUnitString } from '$lib/utils/byte-units';
|
2024-05-26 18:15:52 -04:00
|
|
|
import { UserStatus, searchUsersAdmin, type UserAdminResponseDto } from '@immich/sdk';
|
2025-01-15 15:09:19 -05:00
|
|
|
import { Button, Code, IconButton, Text } from '@immich/ui';
|
2024-09-19 18:20:09 -04:00
|
|
|
import { mdiContentCopy, mdiDeleteRestore, mdiInfinity, mdiPencilOutline, mdiTrashCanOutline } from '@mdi/js';
|
2024-03-08 17:49:39 -05:00
|
|
|
import { DateTime } from 'luxon';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { onMount } from 'svelte';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2024-09-19 18:20:09 -04:00
|
|
|
import type { PageData } from './$types';
|
2023-05-21 23:18:10 -04:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
data: PageData;
|
|
|
|
|
}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let { data }: Props = $props();
|
|
|
|
|
|
|
|
|
|
let allUsers: UserAdminResponseDto[] = $state([]);
|
|
|
|
|
let shouldShowEditUserForm = $state(false);
|
|
|
|
|
let shouldShowCreateUserForm = $state(false);
|
|
|
|
|
let shouldShowPasswordResetSuccess = $state(false);
|
|
|
|
|
let shouldShowDeleteConfirmDialog = $state(false);
|
|
|
|
|
let shouldShowRestoreDialog = $state(false);
|
|
|
|
|
let selectedUser = $state<UserAdminResponseDto>();
|
|
|
|
|
let newPassword = $state('');
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-03-08 17:49:39 -05:00
|
|
|
const refresh = async () => {
|
2024-05-26 18:15:52 -04:00
|
|
|
allUsers = await searchUsersAdmin({ withDeleted: true });
|
2024-03-08 17:49:39 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onDeleteSuccess = (userId: string) => {
|
|
|
|
|
const user = allUsers.find(({ id }) => id === userId);
|
|
|
|
|
if (user) {
|
|
|
|
|
allUsers = allUsers.filter((user) => user.id !== userId);
|
|
|
|
|
notificationController.show({
|
|
|
|
|
type: NotificationType.Info,
|
2024-06-12 12:54:40 +02:00
|
|
|
message: $t('admin.user_successfully_removed', { values: { email: user.email } }),
|
2024-03-08 17:49:39 -05:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
onMount(() => {
|
|
|
|
|
allUsers = $page.data.allUsers;
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-03-08 17:49:39 -05:00
|
|
|
return websocketEvents.on('on_user_delete', onDeleteSuccess);
|
|
|
|
|
});
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-07-01 00:29:10 +02:00
|
|
|
const getDeleteDate = (deletedAt: string): Date => {
|
|
|
|
|
return DateTime.fromISO(deletedAt).plus({ days: $serverConfig.userDeleteDelay }).toJSDate();
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onUserCreated = async () => {
|
2024-03-08 17:49:39 -05:00
|
|
|
await refresh();
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowCreateUserForm = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-05-26 18:15:52 -04:00
|
|
|
const editUserHandler = (user: UserAdminResponseDto) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
selectedUser = user;
|
|
|
|
|
shouldShowEditUserForm = true;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onEditUserSuccess = async () => {
|
2024-03-08 17:49:39 -05:00
|
|
|
await refresh();
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowEditUserForm = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
const onEditPasswordSuccess = async () => {
|
2024-03-08 17:49:39 -05:00
|
|
|
await refresh();
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowEditUserForm = false;
|
2024-03-14 17:33:39 -04:00
|
|
|
shouldShowPasswordResetSuccess = true;
|
2023-07-01 00:50:47 -04:00
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-05-26 18:15:52 -04:00
|
|
|
const deleteUserHandler = (user: UserAdminResponseDto) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
selectedUser = user;
|
|
|
|
|
shouldShowDeleteConfirmDialog = true;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-03-08 17:49:39 -05:00
|
|
|
const onUserDelete = async () => {
|
|
|
|
|
await refresh();
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowDeleteConfirmDialog = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-05-26 18:15:52 -04:00
|
|
|
const restoreUserHandler = (user: UserAdminResponseDto) => {
|
2023-07-01 00:50:47 -04:00
|
|
|
selectedUser = user;
|
|
|
|
|
shouldShowRestoreDialog = true;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-03-08 17:49:39 -05:00
|
|
|
const onUserRestore = async () => {
|
|
|
|
|
await refresh();
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldShowRestoreDialog = false;
|
|
|
|
|
};
|
2022-12-09 15:51:42 -05:00
|
|
|
</script>
|
|
|
|
|
|
2023-12-12 17:35:28 +01:00
|
|
|
<UserPageLayout title={data.meta.title} admin>
|
2023-10-13 11:02:28 -04:00
|
|
|
<section id="setting-content" class="flex place-content-center sm:mx-4">
|
2023-12-14 17:55:15 +01:00
|
|
|
<section class="w-full pb-28 lg:w-[850px]">
|
2023-10-13 11:02:28 -04:00
|
|
|
{#if shouldShowCreateUserForm}
|
2024-04-16 05:06:15 +00:00
|
|
|
<CreateUserForm
|
2024-09-20 23:02:58 +02:00
|
|
|
onSubmit={onUserCreated}
|
|
|
|
|
onCancel={() => (shouldShowCreateUserForm = false)}
|
2024-04-08 21:02:09 +00:00
|
|
|
onClose={() => (shouldShowCreateUserForm = false)}
|
2024-10-17 21:54:50 +05:30
|
|
|
oauthEnabled={$featureFlags.oauth}
|
2024-04-16 05:06:15 +00:00
|
|
|
/>
|
2023-10-13 11:02:28 -04:00
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
{#if shouldShowEditUserForm && selectedUser}
|
2024-04-16 05:06:15 +00:00
|
|
|
<EditUserForm
|
|
|
|
|
user={selectedUser}
|
|
|
|
|
bind:newPassword
|
|
|
|
|
canResetPassword={selectedUser?.id !== $user.id}
|
2024-09-20 23:02:58 +02:00
|
|
|
onEditSuccess={onEditUserSuccess}
|
|
|
|
|
onResetPasswordSuccess={onEditPasswordSuccess}
|
2024-04-08 21:02:09 +00:00
|
|
|
onClose={() => (shouldShowEditUserForm = false)}
|
2024-04-16 05:06:15 +00:00
|
|
|
/>
|
2023-10-13 11:02:28 -04:00
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
{#if shouldShowDeleteConfirmDialog && selectedUser}
|
2023-10-13 11:02:28 -04:00
|
|
|
<DeleteConfirmDialog
|
|
|
|
|
user={selectedUser}
|
2024-09-19 18:20:09 -04:00
|
|
|
onSuccess={onUserDelete}
|
|
|
|
|
onFail={onUserDelete}
|
|
|
|
|
onCancel={() => (shouldShowDeleteConfirmDialog = false)}
|
2023-10-13 11:02:28 -04:00
|
|
|
/>
|
|
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
{#if shouldShowRestoreDialog && selectedUser}
|
2023-10-13 11:02:28 -04:00
|
|
|
<RestoreDialogue
|
|
|
|
|
user={selectedUser}
|
2024-09-19 18:20:09 -04:00
|
|
|
onSuccess={onUserRestore}
|
|
|
|
|
onFail={onUserRestore}
|
|
|
|
|
onCancel={() => (shouldShowRestoreDialog = false)}
|
2023-10-13 11:02:28 -04:00
|
|
|
/>
|
|
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2024-03-14 17:33:39 -04:00
|
|
|
{#if shouldShowPasswordResetSuccess}
|
2024-05-28 09:10:43 +07:00
|
|
|
<ConfirmDialog
|
2024-06-04 21:53:00 +02:00
|
|
|
title={$t('password_reset_success')}
|
|
|
|
|
confirmText={$t('done')}
|
2024-04-08 21:02:09 +00:00
|
|
|
onConfirm={() => (shouldShowPasswordResetSuccess = false)}
|
2024-05-28 09:10:43 +07:00
|
|
|
onCancel={() => (shouldShowPasswordResetSuccess = false)}
|
2024-04-08 21:02:09 +00:00
|
|
|
hideCancelButton={true}
|
2025-03-14 09:37:56 -04:00
|
|
|
confirmColor="success"
|
2024-04-08 21:02:09 +00:00
|
|
|
>
|
2024-11-14 08:43:25 -06:00
|
|
|
{#snippet promptSnippet()}
|
2024-04-08 21:02:09 +00:00
|
|
|
<div class="flex flex-col gap-4">
|
2025-01-15 15:09:19 -05:00
|
|
|
<Text>{$t('admin.user_password_has_been_reset')}</Text>
|
2024-04-08 21:02:09 +00:00
|
|
|
|
2025-01-15 15:09:19 -05:00
|
|
|
<div class="flex justify-center gap-2 items-center">
|
|
|
|
|
<Code color="primary">{newPassword}</Code>
|
|
|
|
|
<IconButton
|
|
|
|
|
icon={mdiContentCopy}
|
|
|
|
|
shape="round"
|
|
|
|
|
color="secondary"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
onclick={() => copyToClipboard(newPassword)}
|
|
|
|
|
title={$t('copy_password')}
|
2025-02-11 18:50:18 +00:00
|
|
|
aria-label={$t('copy_password')}
|
2025-01-15 15:09:19 -05:00
|
|
|
/>
|
2024-03-14 17:33:39 -04:00
|
|
|
</div>
|
2024-04-08 21:02:09 +00:00
|
|
|
|
2025-01-15 15:09:19 -05:00
|
|
|
<Text>{$t('admin.user_password_reset_description')}</Text>
|
2024-04-08 21:02:09 +00:00
|
|
|
</div>
|
2024-11-14 08:43:25 -06:00
|
|
|
{/snippet}
|
2024-05-28 09:10:43 +07:00
|
|
|
</ConfirmDialog>
|
2023-10-13 11:02:28 -04:00
|
|
|
{/if}
|
2022-12-09 15:51:42 -05:00
|
|
|
|
2023-12-14 17:55:15 +01:00
|
|
|
<table class="my-5 w-full text-left">
|
2023-10-13 11:02:28 -04:00
|
|
|
<thead
|
|
|
|
|
class="mb-4 flex h-12 w-full rounded-md border bg-gray-50 text-immich-primary dark:border-immich-dark-gray dark:bg-immich-dark-gray dark:text-immich-dark-primary"
|
|
|
|
|
>
|
|
|
|
|
<tr class="flex w-full place-items-center">
|
2024-06-04 21:53:00 +02:00
|
|
|
<th class="w-8/12 sm:w-5/12 lg:w-6/12 xl:w-4/12 2xl:w-5/12 text-center text-sm font-medium"
|
|
|
|
|
>{$t('email')}</th
|
|
|
|
|
>
|
|
|
|
|
<th class="hidden sm:block w-3/12 text-center text-sm font-medium">{$t('name')}</th>
|
|
|
|
|
<th class="hidden xl:block w-3/12 2xl:w-2/12 text-center text-sm font-medium">{$t('has_quota')}</th>
|
|
|
|
|
<th class="w-4/12 lg:w-3/12 xl:w-2/12 text-center text-sm font-medium">{$t('action')}</th>
|
2023-07-01 00:50:47 -04:00
|
|
|
</tr>
|
2023-10-13 11:02:28 -04:00
|
|
|
</thead>
|
2024-04-14 04:41:00 +02:00
|
|
|
<tbody class="block w-full overflow-y-auto rounded-md border dark:border-immich-dark-gray">
|
2023-10-13 11:02:28 -04:00
|
|
|
{#if allUsers}
|
2025-03-03 14:24:26 +00:00
|
|
|
{#each allUsers as immichUser, index (immichUser.id)}
|
2023-10-13 11:02:28 -04:00
|
|
|
<tr
|
2024-03-08 17:49:39 -05:00
|
|
|
class="flex h-[80px] overflow-hidden w-full place-items-center text-center dark:text-immich-dark-fg {immichUser.deletedAt
|
2023-12-14 17:55:15 +01:00
|
|
|
? 'bg-red-300 dark:bg-red-900'
|
2024-02-02 04:18:00 +01:00
|
|
|
: index % 2 == 0
|
2023-12-14 17:55:15 +01:00
|
|
|
? 'bg-immich-gray dark:bg-immich-dark-gray/75'
|
|
|
|
|
: 'bg-immich-bg dark:bg-immich-dark-gray/50'}"
|
2023-10-13 11:02:28 -04:00
|
|
|
>
|
2023-12-14 17:55:15 +01:00
|
|
|
<td class="w-8/12 sm:w-5/12 lg:w-6/12 xl:w-4/12 2xl:w-5/12 text-ellipsis break-all px-2 text-sm"
|
|
|
|
|
>{immichUser.email}</td
|
|
|
|
|
>
|
|
|
|
|
<td class="hidden sm:block w-3/12 text-ellipsis break-all px-2 text-sm">{immichUser.name}</td>
|
2024-01-15 09:04:29 -06:00
|
|
|
<td class="hidden xl:block w-3/12 2xl:w-2/12 text-ellipsis break-all px-2 text-sm">
|
|
|
|
|
<div class="container mx-auto flex flex-wrap justify-center">
|
|
|
|
|
{#if immichUser.quotaSizeInBytes && immichUser.quotaSizeInBytes > 0}
|
2024-06-14 19:27:46 +02:00
|
|
|
{getByteUnitString(immichUser.quotaSizeInBytes, $locale)}
|
2024-01-15 09:04:29 -06:00
|
|
|
{:else}
|
2024-07-10 22:20:52 +02:00
|
|
|
<Icon path={mdiInfinity} size="16" />
|
2024-01-15 09:04:29 -06:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
2024-04-27 22:29:43 +00:00
|
|
|
<td
|
|
|
|
|
class="flex flex-row flex-wrap justify-center gap-x-2 gap-y-1 w-4/12 lg:w-3/12 xl:w-2/12 text-ellipsis break-all text-sm"
|
|
|
|
|
>
|
2024-03-08 17:49:39 -05:00
|
|
|
{#if !immichUser.deletedAt}
|
2025-01-15 15:09:19 -05:00
|
|
|
<IconButton
|
|
|
|
|
shape="round"
|
2025-03-12 17:25:27 -04:00
|
|
|
size="small"
|
2024-04-27 22:29:43 +00:00
|
|
|
icon={mdiPencilOutline}
|
2024-06-04 21:53:00 +02:00
|
|
|
title={$t('edit_user')}
|
2024-11-14 08:43:25 -06:00
|
|
|
onclick={() => editUserHandler(immichUser)}
|
2025-02-11 18:50:18 +00:00
|
|
|
aria-label={$t('edit_user')}
|
2024-04-27 22:29:43 +00:00
|
|
|
/>
|
2023-12-12 17:35:28 +01:00
|
|
|
{#if immichUser.id !== $user.id}
|
2025-01-15 15:09:19 -05:00
|
|
|
<IconButton
|
|
|
|
|
shape="round"
|
2025-03-12 17:25:27 -04:00
|
|
|
size="small"
|
2024-04-27 22:29:43 +00:00
|
|
|
icon={mdiTrashCanOutline}
|
2024-06-04 21:53:00 +02:00
|
|
|
title={$t('delete_user')}
|
2024-11-14 08:43:25 -06:00
|
|
|
onclick={() => deleteUserHandler(immichUser)}
|
2025-02-11 18:50:18 +00:00
|
|
|
aria-label={$t('delete_user')}
|
2024-04-27 22:29:43 +00:00
|
|
|
/>
|
2023-10-13 11:02:28 -04:00
|
|
|
{/if}
|
|
|
|
|
{/if}
|
2024-03-08 17:49:39 -05:00
|
|
|
{#if immichUser.deletedAt && immichUser.status === UserStatus.Deleted}
|
2025-01-15 15:09:19 -05:00
|
|
|
<IconButton
|
|
|
|
|
shape="round"
|
2025-03-12 17:25:27 -04:00
|
|
|
size="small"
|
2024-04-27 22:29:43 +00:00
|
|
|
icon={mdiDeleteRestore}
|
2024-07-01 00:29:10 +02:00
|
|
|
title={$t('admin.user_restore_scheduled_removal', {
|
|
|
|
|
values: { date: getDeleteDate(immichUser.deletedAt) },
|
|
|
|
|
})}
|
2024-11-14 08:43:25 -06:00
|
|
|
onclick={() => restoreUserHandler(immichUser)}
|
2025-02-11 18:50:18 +00:00
|
|
|
aria-label={$t('admin.user_restore_scheduled_removal')}
|
2024-04-27 22:29:43 +00:00
|
|
|
/>
|
2023-10-13 11:02:28 -04:00
|
|
|
{/if}
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
{/each}
|
|
|
|
|
{/if}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
2025-01-21 16:16:26 -06:00
|
|
|
<Button shape="round" size="small" onclick={() => (shouldShowCreateUserForm = true)}>{$t('create_user')}</Button>
|
2023-10-13 11:02:28 -04:00
|
|
|
</section>
|
|
|
|
|
</section>
|
|
|
|
|
</UserPageLayout>
|