1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-30 19:52:20 +01:00

(bug) for admins and managers, the current password is not requested before changing their own password

This commit is contained in:
Sylvain 2022-07-20 10:45:42 +02:00
parent 7c918ff497
commit d05a6373be
3 changed files with 7 additions and 3 deletions

View File

@ -5,6 +5,7 @@
- Improved calendars loading time
- Refactored and documented the availability-slot-reservation data model
- Display bookers names to connected users now apply to all resources
- Fix a bug: for admins and managers, the current password is not requested before changing their own password
- Fix a bug: missing translation for avatar changing
- Fix a bug: unable to book a space's slot with an existing reservation
- Fix a bug: Unable to import accounts from SSO when the transformation modal was opened but leaved empty

View File

@ -9,19 +9,21 @@ import { FieldValues } from 'react-hook-form/dist/types/fields';
import { PasswordInput } from './password-input';
import { FormState } from 'react-hook-form/dist/types/form';
import MemberAPI from '../../api/member';
import { User } from '../../models/user';
interface ChangePasswordProp<TFieldValues> {
register: UseFormRegister<TFieldValues>,
onError: (message: string) => void,
currentFormPassword: string,
formState: FormState<TFieldValues>,
user: User,
}
/**
* This component shows a button that trigger a modal dialog to verify the user's current password.
* If the user's current password is correct, the modal dialog is closed and the button is replaced by a form to set the new password.
*/
export const ChangePassword = <TFieldValues extends FieldValues>({ register, onError, currentFormPassword, formState }: ChangePasswordProp<TFieldValues>) => {
export const ChangePassword = <TFieldValues extends FieldValues>({ register, onError, currentFormPassword, formState, user }: ChangePasswordProp<TFieldValues>) => {
const { t } = useTranslation('shared');
const [isModalOpen, setIsModalOpen] = React.useState<boolean>(false);
@ -31,8 +33,8 @@ export const ChangePassword = <TFieldValues extends FieldValues>({ register, onE
const { handleSubmit, register: passwordRegister } = useForm<{ password: string }>();
useEffect(() => {
MemberAPI.current().then(user => {
setIsPrivileged(user.role === 'admin' || user.role === 'manager');
MemberAPI.current().then(operator => {
setIsPrivileged((operator.role === 'admin' || operator.role === 'manager') && user.id !== operator.id);
}).catch(error => onError(error));
}, []);

View File

@ -252,6 +252,7 @@ export const UserProfileForm: React.FC<UserProfileFormProps> = ({ action, size,
{ action === 'update' && <ChangePassword register={register}
onError={onError}
currentFormPassword={output.password}
user={user}
formState={formState} />}
{action === 'create' && <PasswordInput register={register}
currentFormPassword={output.password}