2022-08-12 14:25:19 -05:00
|
|
|
<script lang="ts">
|
2023-12-12 03:35:57 +01:00
|
|
|
import { AppRoute } from '$lib/constants';
|
2025-05-03 00:41:42 +02:00
|
|
|
import { modalManager } from '$lib/managers/modal-manager.svelte';
|
2024-12-16 15:45:01 +01:00
|
|
|
import { userInteraction } from '$lib/stores/user.svelte';
|
2025-03-14 09:38:06 -04:00
|
|
|
import { ByteUnit, convertFromBytes, convertToBytes } from '$lib/utils/byte-units';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
2024-05-26 18:15:52 -04:00
|
|
|
import { updateUserAdmin, type UserAdminResponseDto } from '@immich/sdk';
|
2025-05-03 00:41:42 +02:00
|
|
|
import { Button, Modal, ModalBody, ModalFooter } from '@immich/ui';
|
2025-05-09 16:00:58 -05:00
|
|
|
import { mdiAccountEditOutline, mdiLockSmart, mdiOnepassword } from '@mdi/js';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
user: UserAdminResponseDto;
|
|
|
|
|
canResetPassword?: boolean;
|
2025-05-03 00:41:42 +02:00
|
|
|
onClose: (
|
2025-05-09 16:00:58 -05:00
|
|
|
data?:
|
|
|
|
|
| { action: 'update'; data: UserAdminResponseDto }
|
|
|
|
|
| { action: 'resetPassword'; data: string }
|
|
|
|
|
| { action: 'resetPinCode' },
|
2025-05-03 00:41:42 +02:00
|
|
|
) => void;
|
2024-11-14 08:43:25 -06:00
|
|
|
}
|
|
|
|
|
|
2025-05-03 00:41:42 +02:00
|
|
|
let { user, canResetPassword = true, onClose }: Props = $props();
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2025-04-07 16:22:56 +02:00
|
|
|
let quotaSize = $state(user.quotaSizeInBytes === null ? null : convertFromBytes(user.quotaSizeInBytes, ByteUnit.GiB));
|
2025-05-03 00:41:42 +02:00
|
|
|
let newPassword = $state<string>('');
|
2024-01-30 18:21:45 +01:00
|
|
|
|
|
|
|
|
const previousQutoa = user.quotaSizeInBytes;
|
|
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let quotaSizeWarning = $derived(
|
2024-06-14 19:27:46 +02:00
|
|
|
previousQutoa !== convertToBytes(Number(quotaSize), ByteUnit.GiB) &&
|
2024-11-14 08:43:25 -06:00
|
|
|
!!quotaSize &&
|
2024-12-16 15:45:01 +01:00
|
|
|
userInteraction.serverInfo &&
|
|
|
|
|
convertToBytes(Number(quotaSize), ByteUnit.GiB) > userInteraction.serverInfo.diskSizeRaw,
|
2024-11-14 08:43:25 -06:00
|
|
|
);
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
const editUser = async () => {
|
|
|
|
|
try {
|
2024-02-29 19:35:37 +01:00
|
|
|
const { id, email, name, storageLabel } = user;
|
2025-05-03 00:41:42 +02:00
|
|
|
const newUser = await updateUserAdmin({
|
2024-05-26 18:15:52 -04:00
|
|
|
id,
|
|
|
|
|
userAdminUpdateDto: {
|
2023-07-01 00:50:47 -04:00
|
|
|
email,
|
2023-11-11 20:03:32 -05:00
|
|
|
name,
|
2023-07-01 00:50:47 -04:00
|
|
|
storageLabel: storageLabel || '',
|
2025-04-07 16:22:56 +02:00
|
|
|
quotaSizeInBytes: quotaSize === null ? null : convertToBytes(Number(quotaSize), ByteUnit.GiB),
|
2023-07-01 00:50:47 -04:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-03 00:41:42 +02:00
|
|
|
onClose({ action: 'update', data: newUser });
|
2023-07-01 00:50:47 -04:00
|
|
|
} catch (error) {
|
2024-06-04 21:53:00 +02:00
|
|
|
handleError(error, $t('errors.unable_to_update_user'));
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const resetPassword = async () => {
|
2025-05-03 00:41:42 +02:00
|
|
|
const isConfirmed = await modalManager.openDialog({
|
2024-06-12 12:54:40 +02:00
|
|
|
prompt: $t('admin.confirm_user_password_reset', { values: { user: user.name } }),
|
2024-05-28 09:10:43 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!isConfirmed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 00:50:47 -04:00
|
|
|
try {
|
2024-03-14 17:33:39 -04:00
|
|
|
newPassword = generatePassword();
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-05-26 18:15:52 -04:00
|
|
|
await updateUserAdmin({
|
|
|
|
|
id: user.id,
|
|
|
|
|
userAdminUpdateDto: {
|
2024-03-14 17:33:39 -04:00
|
|
|
password: newPassword,
|
2023-07-01 00:50:47 -04:00
|
|
|
shouldChangePassword: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-05-03 00:41:42 +02:00
|
|
|
onClose({ action: 'resetPassword', data: newPassword });
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
2024-06-04 21:53:00 +02:00
|
|
|
handleError(error, $t('errors.unable_to_reset_password'));
|
2023-07-01 00:50:47 -04:00
|
|
|
}
|
|
|
|
|
};
|
2024-03-14 17:33:39 -04:00
|
|
|
|
2025-05-09 16:00:58 -05:00
|
|
|
const resetUserPincode = async () => {
|
|
|
|
|
const isConfirmed = await modalManager.openDialog({
|
|
|
|
|
prompt: $t('admin.confirm_user_pin_code_reset', { values: { user: user.name } }),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!isConfirmed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await updateUserAdmin({ id: user.id, userAdminUpdateDto: { pinCode: null } });
|
|
|
|
|
|
|
|
|
|
onClose({ action: 'resetPinCode' });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, $t('errors.unable_to_reset_pin_code'));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-14 17:33:39 -04:00
|
|
|
// TODO move password reset server-side
|
|
|
|
|
function generatePassword(length: number = 16) {
|
|
|
|
|
let generatedPassword = '';
|
|
|
|
|
|
|
|
|
|
const characterSet = '0123456789' + 'abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ',.-{}+!#$%/()=?';
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
|
let randomNumber = crypto.getRandomValues(new Uint32Array(1))[0];
|
|
|
|
|
randomNumber = randomNumber / 2 ** 32;
|
|
|
|
|
randomNumber = Math.floor(randomNumber * characterSet.length);
|
|
|
|
|
|
|
|
|
|
generatedPassword += characterSet[randomNumber];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return generatedPassword;
|
|
|
|
|
}
|
2024-11-14 08:43:25 -06:00
|
|
|
|
|
|
|
|
const onSubmit = async (event: Event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
await editUser();
|
|
|
|
|
};
|
2022-08-12 14:25:19 -05:00
|
|
|
</script>
|
|
|
|
|
|
2025-05-06 07:47:58 -05:00
|
|
|
<Modal title={$t('edit_user')} size="small" icon={mdiAccountEditOutline} {onClose} class="text-dark bg-light">
|
2025-05-03 00:41:42 +02:00
|
|
|
<ModalBody>
|
|
|
|
|
<form onsubmit={onSubmit} autocomplete="off" id="edit-user-form">
|
2025-05-06 07:47:58 -05:00
|
|
|
<div class="mb-4 flex flex-col gap-2">
|
2025-05-03 00:41:42 +02:00
|
|
|
<label class="immich-form-label" for="email">{$t('email')}</label>
|
|
|
|
|
<input class="immich-form-input" id="email" name="email" type="email" bind:value={user.email} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="name">{$t('name')}</label>
|
|
|
|
|
<input class="immich-form-input" id="name" name="name" type="text" required bind:value={user.name} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="flex items-center gap-2 immich-form-label" for="quotaSize">
|
|
|
|
|
{$t('admin.quota_size_gib')}
|
|
|
|
|
{#if quotaSizeWarning}
|
|
|
|
|
<p class="text-red-400 text-sm">{$t('errors.quota_higher_than_disk_size')}</p>
|
|
|
|
|
{/if}</label
|
|
|
|
|
>
|
|
|
|
|
<input
|
|
|
|
|
class="immich-form-input"
|
|
|
|
|
id="quotaSize"
|
|
|
|
|
name="quotaSize"
|
|
|
|
|
placeholder={$t('unlimited')}
|
|
|
|
|
type="number"
|
|
|
|
|
min="0"
|
|
|
|
|
bind:value={quotaSize}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="storage-label">{$t('storage_label')}</label>
|
|
|
|
|
<input
|
|
|
|
|
class="immich-form-input"
|
|
|
|
|
id="storage-label"
|
|
|
|
|
name="storage-label"
|
|
|
|
|
type="text"
|
|
|
|
|
bind:value={user.storageLabel}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
{$t('admin.note_apply_storage_label_previous_assets')}
|
|
|
|
|
<a href={AppRoute.ADMIN_JOBS} class="text-immich-primary dark:text-immich-dark-primary">
|
|
|
|
|
{$t('admin.storage_template_migration_job')}
|
|
|
|
|
</a>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</ModalBody>
|
|
|
|
|
|
|
|
|
|
<ModalFooter>
|
2025-05-09 16:00:58 -05:00
|
|
|
<div class="w-full">
|
|
|
|
|
<div class="flex gap-3 w-full">
|
|
|
|
|
{#if canResetPassword}
|
|
|
|
|
<Button
|
|
|
|
|
shape="round"
|
|
|
|
|
color="warning"
|
|
|
|
|
variant="filled"
|
|
|
|
|
fullWidth
|
|
|
|
|
onclick={resetPassword}
|
|
|
|
|
leadingIcon={mdiOnepassword}
|
|
|
|
|
>
|
|
|
|
|
{$t('reset_password')}</Button
|
|
|
|
|
>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
shape="round"
|
|
|
|
|
color="warning"
|
|
|
|
|
variant="filled"
|
|
|
|
|
fullWidth
|
|
|
|
|
onclick={resetUserPincode}
|
|
|
|
|
leadingIcon={mdiLockSmart}>{$t('reset_pin_code')}</Button
|
2025-05-03 00:41:42 +02:00
|
|
|
>
|
2025-05-09 16:00:58 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="w-full mt-4">
|
|
|
|
|
<Button type="submit" shape="round" fullWidth form="edit-user-form">{$t('confirm')}</Button>
|
|
|
|
|
</div>
|
2024-04-16 05:06:15 +00:00
|
|
|
</div>
|
2025-05-03 00:41:42 +02:00
|
|
|
</ModalFooter>
|
|
|
|
|
</Modal>
|