1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-15 08:10:13 +00:00

fix: allow profile picture update even if "allow own account edit" enabled

This commit is contained in:
Elias Schneider
2025-07-03 10:57:56 +02:00
parent be52660227
commit 9872608d61
3 changed files with 63 additions and 45 deletions

View File

@@ -3,6 +3,7 @@
import * as Avatar from '$lib/components/ui/avatar'; import * as Avatar from '$lib/components/ui/avatar';
import Button from '$lib/components/ui/button/button.svelte'; import Button from '$lib/components/ui/button/button.svelte';
import { m } from '$lib/paraglide/messages'; import { m } from '$lib/paraglide/messages';
import appConfigStore from '$lib/stores/application-configuration-store';
import { cachedProfilePicture } from '$lib/utils/cached-image-util'; import { cachedProfilePicture } from '$lib/utils/cached-image-util';
import { LucideLoader, LucideRefreshCw, LucideUpload } from '@lucide/svelte'; import { LucideLoader, LucideRefreshCw, LucideUpload } from '@lucide/svelte';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
@@ -54,8 +55,16 @@
label: m.reset(), label: m.reset(),
action: async () => { action: async () => {
isLoading = true; isLoading = true;
await resetCallback().catch(); try {
isLoading = false; await resetCallback();
await fetch(cachedProfilePicture.getUrl(userId, { skipCache: true }))
.then((response) => response.blob())
.then((blob) => {
imageDataURL = URL.createObjectURL(blob);
});
} finally {
isLoading = false;
}
} }
} }
}); });
@@ -64,7 +73,7 @@
<div class="flex flex-col items-center gap-6 sm:flex-row"> <div class="flex flex-col items-center gap-6 sm:flex-row">
<div class="shrink-0"> <div class="shrink-0">
{#if isLdapUser} {#if isLdapUser && $appConfigStore.ldapEnabled}
<Avatar.Root class="size-24"> <Avatar.Root class="size-24">
<Avatar.Image class="object-cover" src={imageDataURL} /> <Avatar.Image class="object-cover" src={imageDataURL} />
</Avatar.Root> </Avatar.Root>
@@ -96,7 +105,7 @@
<div class="grow"> <div class="grow">
<h3 class="font-medium">{m.profile_picture()}</h3> <h3 class="font-medium">{m.profile_picture()}</h3>
{#if isLdapUser} {#if isLdapUser && $appConfigStore.ldapEnabled}
<p class="text-muted-foreground text-sm"> <p class="text-muted-foreground text-sm">
{m.profile_picture_is_managed_by_ldap_server()} {m.profile_picture_is_managed_by_ldap_server()}
</p> </p>
@@ -105,7 +114,12 @@
{m.click_profile_picture_to_upload_custom()} {m.click_profile_picture_to_upload_custom()}
</p> </p>
<p class="text-muted-foreground mb-2 text-sm">{m.image_should_be_in_format()}</p> <p class="text-muted-foreground mb-2 text-sm">{m.image_should_be_in_format()}</p>
<Button variant="outline" size="sm" onclick={onReset} disabled={isLoading || isLdapUser}> <Button
variant="outline"
size="sm"
onclick={onReset}
disabled={isLoading || (isLdapUser && $appConfigStore.ldapEnabled)}
>
<LucideRefreshCw class="mr-2 size-4" /> <LucideRefreshCw class="mr-2 size-4" />
{m.reset_to_default()} {m.reset_to_default()}
</Button> </Button>

View File

@@ -34,6 +34,10 @@
const userService = new UserService(); const userService = new UserService();
const webauthnService = new WebAuthnService(); const webauthnService = new WebAuthnService();
const userInfoInputDisabled = $derived(
!$appConfigStore.allowOwnAccountEdit || (!!account.ldapId && $appConfigStore.ldapEnabled)
);
async function updateAccount(user: UserCreate) { async function updateAccount(user: UserCreate) {
let success = true; let success = true;
await userService await userService
@@ -118,27 +122,23 @@
</div> </div>
<!-- Account details card --> <!-- Account details card -->
<fieldset <Card.Root>
disabled={!$appConfigStore.allowOwnAccountEdit || <Card.Header>
(!!account.ldapId && $appConfigStore.ldapEnabled)} <Card.Title>
> <UserCog class="text-primary/80 size-5" />
<Card.Root> {m.account_details()}
<Card.Header> </Card.Title>
<Card.Title> </Card.Header>
<UserCog class="text-primary/80 size-5" /> <Card.Content>
{m.account_details()} <AccountForm
</Card.Title> {account}
</Card.Header> userId={account.id}
<Card.Content> callback={updateAccount}
<AccountForm isLdapUser={!!account.ldapId}
{account} {userInfoInputDisabled}
userId={account.id} />
callback={updateAccount} </Card.Content>
isLdapUser={!!account.ldapId} </Card.Root>
/>
</Card.Content>
</Card.Root>
</fieldset>
<!-- Passkey management card --> <!-- Passkey management card -->
<div> <div>

View File

@@ -15,12 +15,14 @@
callback, callback,
account, account,
userId, userId,
isLdapUser = false isLdapUser = false,
userInfoInputDisabled = false
}: { }: {
account: UserCreate; account: UserCreate;
userId: string; userId: string;
callback: (user: UserCreate) => Promise<boolean>; callback: (user: UserCreate) => Promise<boolean>;
isLdapUser?: boolean; isLdapUser?: boolean;
userInfoInputDisabled?: boolean;
} = $props(); } = $props();
let isLoading = $state(false); let isLoading = $state(false);
@@ -78,26 +80,28 @@
<hr class="border-border" /> <hr class="border-border" />
<!-- User Information --> <!-- User Information -->
<div> <fieldset disabled={userInfoInputDisabled}>
<div class="flex flex-col gap-3 sm:flex-row"> <div>
<div class="w-full"> <div class="flex flex-col gap-3 sm:flex-row">
<FormInput label={m.first_name()} bind:input={$inputs.firstName} /> <div class="w-full">
<FormInput label={m.first_name()} bind:input={$inputs.firstName} />
</div>
<div class="w-full">
<FormInput label={m.last_name()} bind:input={$inputs.lastName} />
</div>
</div> </div>
<div class="w-full"> <div class="mt-3 flex flex-col gap-3 sm:flex-row">
<FormInput label={m.last_name()} bind:input={$inputs.lastName} /> <div class="w-full">
<FormInput label={m.email()} bind:input={$inputs.email} />
</div>
<div class="w-full">
<FormInput label={m.username()} bind:input={$inputs.username} />
</div>
</div> </div>
</div> </div>
<div class="mt-3 flex flex-col gap-3 sm:flex-row">
<div class="w-full">
<FormInput label={m.email()} bind:input={$inputs.email} />
</div>
<div class="w-full">
<FormInput label={m.username()} bind:input={$inputs.username} />
</div>
</div>
</div>
<div class="flex justify-end pt-2"> <div class="flex justify-end pt-2">
<Button {isLoading} type="submit">{m.save()}</Button> <Button {isLoading} type="submit">{m.save()}</Button>
</div> </div>
</fieldset>
</form> </form>