From 39af018d1c9393d8eb38dffec1638b393b323753 Mon Sep 17 00:00:00 2001 From: jedi04 <78037206+jedi04@users.noreply.github.com> Date: Thu, 17 Oct 2024 21:54:50 +0530 Subject: [PATCH] fix(server): Allow passwordless users when oauth enabled (#13517) * fix(server): Allow passwordless users when oauth enabled * fix(web): Use features flags for checking oauth --- server/src/dtos/user.dto.ts | 1 - server/src/services/user-admin.service.ts | 4 ++++ web/src/lib/components/forms/create-user-form.svelte | 10 ++++++++-- web/src/routes/admin/user-management/+page.svelte | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server/src/dtos/user.dto.ts b/server/src/dtos/user.dto.ts index 36f0b6386f76d..593a7934bccc1 100644 --- a/server/src/dtos/user.dto.ts +++ b/server/src/dtos/user.dto.ts @@ -62,7 +62,6 @@ export class UserAdminCreateDto { @Transform(toEmail) email!: string; - @IsNotEmpty() @IsString() password!: string; diff --git a/server/src/services/user-admin.service.ts b/server/src/services/user-admin.service.ts index 94608a24ac035..84a5b5842d9b9 100644 --- a/server/src/services/user-admin.service.ts +++ b/server/src/services/user-admin.service.ts @@ -26,6 +26,10 @@ export class UserAdminService extends BaseService { async create(dto: UserAdminCreateDto): Promise { const { notify, ...rest } = dto; + const config = await this.getConfig({ withCache: false }); + if (!config.oauth.enabled && !rest.password) { + throw new BadRequestException('password is required'); + } const user = await createUser({ userRepo: this.userRepository, cryptoRepo: this.cryptoRepository }, rest); await this.eventRepository.emit('user.signup', { diff --git a/web/src/lib/components/forms/create-user-form.svelte b/web/src/lib/components/forms/create-user-form.svelte index 9c4b83002b77a..0687912542067 100644 --- a/web/src/lib/components/forms/create-user-form.svelte +++ b/web/src/lib/components/forms/create-user-form.svelte @@ -13,6 +13,7 @@ export let onClose: () => void; export let onSubmit: () => void; export let onCancel: () => void; + export let oauthEnabled = false; let error: string; let success: string; @@ -90,12 +91,17 @@
- +
- +
diff --git a/web/src/routes/admin/user-management/+page.svelte b/web/src/routes/admin/user-management/+page.svelte index 2313b17cb1ea1..80c0169176107 100644 --- a/web/src/routes/admin/user-management/+page.svelte +++ b/web/src/routes/admin/user-management/+page.svelte @@ -15,7 +15,7 @@ notificationController, } from '$lib/components/shared-components/notification/notification'; import { locale } from '$lib/stores/preferences.store'; - import { serverConfig } from '$lib/stores/server-config.store'; + import { serverConfig, featureFlags } from '$lib/stores/server-config.store'; import { user } from '$lib/stores/user.store'; import { websocketEvents } from '$lib/stores/websocket'; import { copyToClipboard } from '$lib/utils'; @@ -113,6 +113,7 @@ onSubmit={onUserCreated} onCancel={() => (shouldShowCreateUserForm = false)} onClose={() => (shouldShowCreateUserForm = false)} + oauthEnabled={$featureFlags.oauth} /> {/if}