2022-08-12 14:25:19 -05:00
|
|
|
<script lang="ts">
|
2024-02-13 17:07:37 -05:00
|
|
|
import ConfirmDialogue from '$lib/components/shared-components/confirm-dialogue.svelte';
|
2024-05-26 18:15:52 -04:00
|
|
|
import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte';
|
2023-12-12 03:35:57 +01:00
|
|
|
import { AppRoute } from '$lib/constants';
|
2024-01-30 18:21:45 +01:00
|
|
|
import { serverInfo } from '$lib/stores/server-info.store';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { convertFromBytes, convertToBytes } from '$lib/utils/byte-converter';
|
|
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
2024-05-26 18:15:52 -04:00
|
|
|
import { updateUserAdmin, type UserAdminResponseDto } from '@immich/sdk';
|
|
|
|
|
import { mdiAccountEditOutline } from '@mdi/js';
|
2024-02-13 17:07:37 -05:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
import Button from '../elements/buttons/button.svelte';
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2024-05-26 18:15:52 -04:00
|
|
|
export let user: UserAdminResponseDto;
|
2023-07-01 00:50:47 -04:00
|
|
|
export let canResetPassword = true;
|
2024-03-14 17:33:39 -04:00
|
|
|
export let newPassword: string;
|
2024-04-16 05:06:15 +00:00
|
|
|
export let onClose: () => void;
|
2023-07-01 00:50:47 -04:00
|
|
|
|
|
|
|
|
let error: string;
|
|
|
|
|
let success: string;
|
|
|
|
|
let isShowResetPasswordConfirmation = false;
|
2024-01-30 18:21:45 +01:00
|
|
|
let quotaSize = user.quotaSizeInBytes ? convertFromBytes(user.quotaSizeInBytes, 'GiB') : null;
|
|
|
|
|
|
|
|
|
|
const previousQutoa = user.quotaSizeInBytes;
|
|
|
|
|
|
|
|
|
|
$: quotaSizeWarning =
|
|
|
|
|
previousQutoa !== convertToBytes(Number(quotaSize), 'GiB') &&
|
|
|
|
|
!!quotaSize &&
|
|
|
|
|
convertToBytes(Number(quotaSize), 'GiB') > $serverInfo.diskSizeRaw;
|
2023-07-01 00:50:47 -04:00
|
|
|
|
2023-12-14 17:55:15 +01:00
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
|
close: void;
|
|
|
|
|
resetPasswordSuccess: void;
|
|
|
|
|
editSuccess: void;
|
|
|
|
|
}>();
|
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;
|
2024-05-26 18:15:52 -04:00
|
|
|
await updateUserAdmin({
|
|
|
|
|
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 || '',
|
2024-01-12 18:43:36 -06:00
|
|
|
quotaSizeInBytes: quotaSize ? convertToBytes(Number(quotaSize), 'GiB') : null,
|
2023-07-01 00:50:47 -04:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
dispatch('editSuccess');
|
2023-07-01 00:50:47 -04:00
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Unable to update user');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const resetPassword = async () => {
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-13 17:07:37 -05:00
|
|
|
dispatch('resetPasswordSuccess');
|
2024-02-02 04:18:00 +01:00
|
|
|
} catch (error) {
|
2024-02-13 17:07:37 -05:00
|
|
|
handleError(error, 'Unable to reset password');
|
2023-07-01 00:50:47 -04:00
|
|
|
} finally {
|
|
|
|
|
isShowResetPasswordConfirmation = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
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;
|
|
|
|
|
}
|
2022-08-12 14:25:19 -05:00
|
|
|
</script>
|
|
|
|
|
|
2024-04-16 05:06:15 +00:00
|
|
|
<FullScreenModal id="edit-user-modal" title="Edit user" icon={mdiAccountEditOutline} {onClose}>
|
|
|
|
|
<form on:submit|preventDefault={editUser} autocomplete="off" id="edit-user-form">
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="email">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">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"
|
|
|
|
|
>Quota Size (GiB) {#if quotaSizeWarning}
|
|
|
|
|
<p class="text-red-400 text-sm">You set a quota higher than the disk size</p>
|
|
|
|
|
{/if}</label
|
|
|
|
|
>
|
|
|
|
|
<input class="immich-form-input" id="quotaSize" name="quotaSize" type="number" min="0" bind:value={quotaSize} />
|
|
|
|
|
<p>Note: Enter 0 for unlimited quota</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="my-4 flex flex-col gap-2">
|
|
|
|
|
<label class="immich-form-label" for="storage-label">Storage Label</label>
|
|
|
|
|
<input
|
|
|
|
|
class="immich-form-input"
|
|
|
|
|
id="storage-label"
|
|
|
|
|
name="storage-label"
|
|
|
|
|
type="text"
|
|
|
|
|
bind:value={user.storageLabel}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Note: To apply the Storage Label to previously uploaded assets, run the
|
|
|
|
|
<a href={AppRoute.ADMIN_JOBS} class="text-immich-primary dark:text-immich-dark-primary">
|
|
|
|
|
Storage Migration Job</a
|
|
|
|
|
>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if error}
|
|
|
|
|
<p class="ml-4 text-sm text-red-400">{error}</p>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if success}
|
|
|
|
|
<p class="ml-4 text-sm text-immich-primary">{success}</p>
|
|
|
|
|
{/if}
|
|
|
|
|
</form>
|
|
|
|
|
<svelte:fragment slot="sticky-bottom">
|
2024-04-08 21:02:09 +00:00
|
|
|
{#if canResetPassword}
|
|
|
|
|
<Button color="light-red" fullwidth on:click={() => (isShowResetPasswordConfirmation = true)}
|
|
|
|
|
>Reset password</Button
|
|
|
|
|
>
|
|
|
|
|
{/if}
|
2024-04-16 05:06:15 +00:00
|
|
|
<Button type="submit" fullwidth form="edit-user-form">Confirm</Button>
|
|
|
|
|
</svelte:fragment>
|
|
|
|
|
</FullScreenModal>
|
2023-06-30 21:53:16 +02:00
|
|
|
|
|
|
|
|
{#if isShowResetPasswordConfirmation}
|
2023-07-01 00:50:47 -04:00
|
|
|
<ConfirmDialogue
|
2024-04-08 21:02:09 +00:00
|
|
|
id="reset-password-modal"
|
|
|
|
|
title="Reset password"
|
2023-07-01 00:50:47 -04:00
|
|
|
confirmText="Reset"
|
2024-03-07 04:18:53 +01:00
|
|
|
onConfirm={resetPassword}
|
|
|
|
|
onClose={() => (isShowResetPasswordConfirmation = false)}
|
2023-07-01 00:50:47 -04:00
|
|
|
>
|
|
|
|
|
<svelte:fragment slot="prompt">
|
|
|
|
|
<p>
|
2023-11-11 20:03:32 -05:00
|
|
|
Are you sure you want to reset <b>{user.name}</b>'s password?
|
2023-07-01 00:50:47 -04:00
|
|
|
</p>
|
|
|
|
|
</svelte:fragment>
|
|
|
|
|
</ConfirmDialogue>
|
2023-06-30 21:53:16 +02:00
|
|
|
{/if}
|