From f4d3ccfcaf968bd1f9af314eab425f7f99b360b4 Mon Sep 17 00:00:00 2001 From: Gabriel Gavrilov Date: Sat, 10 Aug 2024 22:49:58 -0600 Subject: [PATCH 1/4] Add empty password save error message --- src/components/dashboard/users/UserPasswordForm.tsx | 6 +++++- src/strings/en-us.json | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/dashboard/users/UserPasswordForm.tsx b/src/components/dashboard/users/UserPasswordForm.tsx index f8eda449588..e8adb8ee16e 100644 --- a/src/components/dashboard/users/UserPasswordForm.tsx +++ b/src/components/dashboard/users/UserPasswordForm.tsx @@ -7,6 +7,7 @@ import loading from '../../loading/loading'; import toast from '../../toast/toast'; import ButtonElement from '../../../elements/ButtonElement'; import InputElement from '../../../elements/InputElement'; +import { UserDto } from '@jellyfin/sdk/lib/generated-client'; type IProps = { userId: string | null; @@ -14,6 +15,7 @@ type IProps = { const UserPasswordForm: FunctionComponent = ({ userId }: IProps) => { const element = useRef(null); + let user: UserDto const loadUser = useCallback(async () => { const page = element.current; @@ -28,7 +30,7 @@ const UserPasswordForm: FunctionComponent = ({ userId }: IProps) => { return; } - const user = await window.ApiClient.getUser(userId); + user = await window.ApiClient.getUser(userId); const loggedInUser = await Dashboard.getCurrentUser(); if (!user.Policy || !user.Configuration) { @@ -76,6 +78,8 @@ const UserPasswordForm: FunctionComponent = ({ userId }: IProps) => { const onSubmit = (e: Event) => { if ((page.querySelector('#txtNewPassword') as HTMLInputElement).value != (page.querySelector('#txtNewPasswordConfirm') as HTMLInputElement).value) { toast(globalize.translate('PasswordMatchError')); + } else if((page.querySelector('#txtNewPassword') as HTMLInputElement).value == '' && user.Policy?.IsAdministrator) { + toast(globalize.translate('PasswordMissingSaveError')); } else { loading.show(); savePassword(); diff --git a/src/strings/en-us.json b/src/strings/en-us.json index 12023468eb2..218b3882924 100644 --- a/src/strings/en-us.json +++ b/src/strings/en-us.json @@ -1246,6 +1246,7 @@ "PasswordResetComplete": "The password has been reset.", "PasswordResetConfirmation": "Are you sure you wish to reset the password?", "PasswordResetProviderHelp": "Pick a password reset provider to be used when this user requests a password reset.", + "PasswordMissingSaveError": "New password cannot be empty.", "PasswordSaved": "Password saved.", "PathNotFound": "The path could not be found. Please ensure the path is valid and try again.", "Penciller": "Penciler", From 9c7148e07fcf8904b0f4f92dc25c35d538864872 Mon Sep 17 00:00:00 2001 From: Gabriel Gavrilov Date: Sat, 10 Aug 2024 23:15:37 -0600 Subject: [PATCH 2/4] Fix ESLint issues --- .../dashboard/users/UserPasswordForm.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/dashboard/users/UserPasswordForm.tsx b/src/components/dashboard/users/UserPasswordForm.tsx index e8adb8ee16e..a071111ad65 100644 --- a/src/components/dashboard/users/UserPasswordForm.tsx +++ b/src/components/dashboard/users/UserPasswordForm.tsx @@ -15,7 +15,7 @@ type IProps = { const UserPasswordForm: FunctionComponent = ({ userId }: IProps) => { const element = useRef(null); - let user: UserDto + const user = useRef(); const loadUser = useCallback(async () => { const page = element.current; @@ -30,17 +30,17 @@ const UserPasswordForm: FunctionComponent = ({ userId }: IProps) => { return; } - user = await window.ApiClient.getUser(userId); + user.current = await window.ApiClient.getUser(userId); const loggedInUser = await Dashboard.getCurrentUser(); - if (!user.Policy || !user.Configuration) { + if (!user.current.Policy || !user.current.Configuration) { throw new Error('Unexpected null user policy or configuration'); } - LibraryMenu.setTitle(user.Name); + LibraryMenu.setTitle(user.current.Name); - if (user.HasConfiguredPassword) { - if (!user.Policy?.IsAdministrator) { + if (user.current.HasConfiguredPassword) { + if (!user.current.Policy?.IsAdministrator) { (page.querySelector('#btnResetPassword') as HTMLDivElement).classList.remove('hide'); } (page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.remove('hide'); @@ -49,7 +49,7 @@ const UserPasswordForm: FunctionComponent = ({ userId }: IProps) => { (page.querySelector('#fldCurrentPassword') as HTMLDivElement).classList.add('hide'); } - const canChangePassword = loggedInUser?.Policy?.IsAdministrator || user.Policy.EnableUserPreferenceAccess; + const canChangePassword = loggedInUser?.Policy?.IsAdministrator || user.current.Policy.EnableUserPreferenceAccess; (page.querySelector('.passwordSection') as HTMLDivElement).classList.toggle('hide', !canChangePassword); import('../../autoFocuser').then(({ default: autoFocuser }) => { @@ -78,7 +78,7 @@ const UserPasswordForm: FunctionComponent = ({ userId }: IProps) => { const onSubmit = (e: Event) => { if ((page.querySelector('#txtNewPassword') as HTMLInputElement).value != (page.querySelector('#txtNewPasswordConfirm') as HTMLInputElement).value) { toast(globalize.translate('PasswordMatchError')); - } else if((page.querySelector('#txtNewPassword') as HTMLInputElement).value == '' && user.Policy?.IsAdministrator) { + } else if ((page.querySelector('#txtNewPassword') as HTMLInputElement).value == '' && user.current?.Policy?.IsAdministrator) { toast(globalize.translate('PasswordMissingSaveError')); } else { loading.show(); From e7230ab9c6f7390d3c1ef9c8f8089ddd389ac36c Mon Sep 17 00:00:00 2001 From: Gabriel Gavrilov Date: Tue, 20 Aug 2024 13:05:45 -0600 Subject: [PATCH 3/4] Add suggestion Co-authored-by: Bill Thornton --- src/components/dashboard/users/UserPasswordForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/dashboard/users/UserPasswordForm.tsx b/src/components/dashboard/users/UserPasswordForm.tsx index a071111ad65..dc2c3185c85 100644 --- a/src/components/dashboard/users/UserPasswordForm.tsx +++ b/src/components/dashboard/users/UserPasswordForm.tsx @@ -7,7 +7,7 @@ import loading from '../../loading/loading'; import toast from '../../toast/toast'; import ButtonElement from '../../../elements/ButtonElement'; import InputElement from '../../../elements/InputElement'; -import { UserDto } from '@jellyfin/sdk/lib/generated-client'; +import type { UserDto } from '@jellyfin/sdk/lib/generated-client'; type IProps = { userId: string | null; From a25e29161be0978f1529a4cc9f00ec8a8e71e8dd Mon Sep 17 00:00:00 2001 From: Gabriel Gavrilov Date: Tue, 20 Aug 2024 13:07:17 -0600 Subject: [PATCH 4/4] Move import to top --- src/components/dashboard/users/UserPasswordForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/dashboard/users/UserPasswordForm.tsx b/src/components/dashboard/users/UserPasswordForm.tsx index dc2c3185c85..0ab5dd50cfb 100644 --- a/src/components/dashboard/users/UserPasswordForm.tsx +++ b/src/components/dashboard/users/UserPasswordForm.tsx @@ -1,4 +1,5 @@ import React, { FunctionComponent, useCallback, useEffect, useRef } from 'react'; +import type { UserDto } from '@jellyfin/sdk/lib/generated-client'; import Dashboard from '../../../utils/dashboard'; import globalize from '../../../scripts/globalize'; import LibraryMenu from '../../../scripts/libraryMenu'; @@ -7,7 +8,6 @@ import loading from '../../loading/loading'; import toast from '../../toast/toast'; import ButtonElement from '../../../elements/ButtonElement'; import InputElement from '../../../elements/InputElement'; -import type { UserDto } from '@jellyfin/sdk/lib/generated-client'; type IProps = { userId: string | null;