Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add empty password save error message #5904

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/components/dashboard/users/UserPasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ 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';
GabrielGavrilov marked this conversation as resolved.
Show resolved Hide resolved

type IProps = {
userId: string | null;
};

const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
const element = useRef<HTMLDivElement>(null);
const user = useRef<UserDto>();

const loadUser = useCallback(async () => {
const page = element.current;
Expand All @@ -28,17 +30,17 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ userId }: IProps) => {
return;
}

const user = await window.ApiClient.getUser(userId);
user.current = await window.ApiClient.getUser(userId);
thornbill marked this conversation as resolved.
Show resolved Hide resolved
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');
Expand All @@ -47,7 +49,7 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ 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 }) => {
Expand Down Expand Up @@ -76,6 +78,8 @@ const UserPasswordForm: FunctionComponent<IProps> = ({ 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.current?.Policy?.IsAdministrator) {
toast(globalize.translate('PasswordMissingSaveError'));
} else {
loading.show();
savePassword();
Expand Down
1 change: 1 addition & 0 deletions src/strings/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading