diff --git a/app/fr/maif/izanami/errors/Errors.scala b/app/fr/maif/izanami/errors/Errors.scala index a66125092..e8133754b 100644 --- a/app/fr/maif/izanami/errors/Errors.scala +++ b/app/fr/maif/izanami/errors/Errors.scala @@ -73,7 +73,7 @@ case class UserAlreadyExist(user: String, email: String) status = BAD_REQUEST ) case class EmailAlreadyUsed(email: String) - extends IzanamiError(message = s"Email ${email} is already used by another user)", status = BAD_REQUEST) + extends IzanamiError(message = s"Email ${email} is already used by another user", status = BAD_REQUEST) case class InternalServerError(msg: String = "") extends IzanamiError(message = s"Something went wrong $msg", status = INTERNAL_SERVER_ERROR) case class MailSendingError(err: String, override val status: Int = INTERNAL_SERVER_ERROR) diff --git a/izanami-frontend/src/pages/users.tsx b/izanami-frontend/src/pages/users.tsx index b44ecb8e9..a6f225f3e 100644 --- a/izanami-frontend/src/pages/users.tsx +++ b/izanami-frontend/src/pages/users.tsx @@ -58,6 +58,7 @@ export function Users() { }, } ); + const userUpdateMutation = useMutation( (user: { username: string; admin: boolean; rights: TRights }) => { const { username, ...rest } = user; @@ -82,10 +83,20 @@ export function Users() { }, } ); - const inviteUserMutation = useMutation( - (data: { email: string; admin: boolean; rights: TRights }) => - createInvitation(data.email, data.admin, data.rights) + (data: { + admin: boolean; + email: string; + rights: TRights; + userToCopy: string; + }) => { + if (data.userToCopy) { + return queryUser(data.userToCopy).then((res: TUser) => { + return createInvitation(data.email, res.admin, res.rights); + }); + } + return createInvitation(data.email, data.admin, data.rights); + } ); function OperationToggleForm(props: { @@ -94,6 +105,7 @@ export function Users() { cancel: () => void; }) { const { bulkOperation, selectedRows, cancel } = props; + switch (bulkOperation) { case "Toggle Admin Role": { const adminOptions = [ @@ -196,7 +208,6 @@ export function Users() { ); } } - if (userQuery.isLoading) { return ; } else if (userQuery.isSuccess) { @@ -262,6 +273,7 @@ export function Users() { size: 15, }, ]; + return ( <>
@@ -293,32 +305,57 @@ export function Users() { props: { autoFocus: true, }, + defaultValue: "", + }, + useCopyUserRights: { + label: "Copy rights from another user", + type: "bool", }, admin: { label: "Admin", type: "bool", + visible: ({ rawValues }) => !rawValues.useCopyUserRights, }, rights: { label: () => "", type: "object", array: true, - render: ({ onChange }) => { - return ( - onChange?.(v)} - /> - ); - }, + visible: ({ rawValues }) => !rawValues.useCopyUserRights, + render: ({ onChange }) => ( + { + onChange?.(v); + }} + /> + ), + }, + userToCopy: { + label: "User to copy", + type: "object", + visible: ({ rawValues }) => rawValues.useCopyUserRights, + render: ({ onChange }) => ( +