diff --git a/src/pages/users/modification/user-modification-dialog.tsx b/src/pages/users/modification/user-modification-dialog.tsx index 157b0d2..7cea2d7 100644 --- a/src/pages/users/modification/user-modification-dialog.tsx +++ b/src/pages/users/modification/user-modification-dialog.tsx @@ -43,13 +43,13 @@ const UserModificationDialog: FunctionComponent = ( useEffect(() => { if (userInfos && open) { - const sortedGroups = Array.from(userInfos.groups).sort((a, b) => a.localeCompare(b)); + const sortedGroups = Array.from(userInfos.groups ?? []).sort((a, b) => a.localeCompare(b)); reset({ [USER_NAME]: userInfos.sub, [USER_PROFILE_NAME]: userInfos.profileName, [USER_SELECTED_GROUPS]: JSON.stringify(sortedGroups), // only used to dirty the form }); - setSelectedGroups(userInfos.groups); + setSelectedGroups(userInfos.groups ?? []); // fetch profile & groups setDataFetchStatus(FetchStatus.FETCHING); @@ -109,22 +109,13 @@ const UserModificationDialog: FunctionComponent = ( const onSubmit = useCallback( (userFormData: UserModificationFormType) => { if (userInfos) { - const newData: UserInfos = { + UserAdminSrv.updateUser({ sub: userInfos.sub, // can't be changed - isAdmin: userInfos.isAdmin, // can't be changed profileName: userFormData.profileName ?? undefined, groups: selectedGroups, - }; - UserAdminSrv.updateUser(newData) - .catch((error) => - snackError({ - messageTxt: error.message, - headerId: 'users.table.error.update', - }) - ) - .then(() => { - onUpdate(); - }); + }) + .catch((error) => snackError({ messageTxt: error.message, headerId: 'users.table.error.update' })) + .then(() => onUpdate()); } }, [onUpdate, selectedGroups, snackError, userInfos] diff --git a/src/pages/users/users-table.tsx b/src/pages/users/users-table.tsx index 513e06f..ebc470c 100644 --- a/src/pages/users/users-table.tsx +++ b/src/pages/users/users-table.tsx @@ -5,18 +5,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { FunctionComponent, RefObject, useCallback, useMemo, useState } from 'react'; +import { type FunctionComponent, type RefObject, useCallback, useMemo, useState } from 'react'; import { useIntl } from 'react-intl'; import { PersonAdd } from '@mui/icons-material'; -import { GridButton, GridButtonDelete, GridTable, GridTableRef } from '../../components/Grid'; -import { GroupInfos, UserAdminSrv, UserInfos } from '../../services'; -import { - ColDef, - GetRowIdParams, - ICheckboxCellRendererParams, - RowClickedEvent, - TextFilterParams, -} from 'ag-grid-community'; +import { GridButton, GridButtonDelete, GridTable, type GridTableRef } from '../../components/Grid'; +import { type GroupInfos, UserAdminSrv, type UserInfos } from '../../services'; +import type { ColDef, GetRowIdParams, RowClickedEvent, TextFilterParams } from 'ag-grid-community'; import { useSnackMessage } from '@gridsuite/commons-ui'; import DeleteConfirmationDialog from '../common/delete-confirmation-dialog'; import { defaultColDef, defaultRowSelection } from '../common/table-config'; @@ -65,9 +59,7 @@ const UsersTable: FunctionComponent = (props) => { lockVisible: true, filter: true, headerName: intl.formatMessage({ id: 'users.table.id' }), - headerTooltip: intl.formatMessage({ - id: 'users.table.id.description', - }), + headerTooltip: intl.formatMessage({ id: 'users.table.id.description' }), filterParams: { caseSensitive: false, trimInput: true, @@ -80,12 +72,8 @@ const UsersTable: FunctionComponent = (props) => { cellDataType: 'text', flex: 2, filter: true, - headerName: intl.formatMessage({ - id: 'users.table.profileName', - }), - headerTooltip: intl.formatMessage({ - id: 'users.table.profileName.description', - }), + headerName: intl.formatMessage({ id: 'users.table.profileName' }), + headerTooltip: intl.formatMessage({ id: 'users.table.profileName.description' }), filterParams: { caseSensitive: false, trimInput: true, @@ -98,34 +86,14 @@ const UsersTable: FunctionComponent = (props) => { cellDataType: 'text', flex: 4, filter: true, - headerName: intl.formatMessage({ - id: 'users.table.groups', - }), - headerTooltip: intl.formatMessage({ - id: 'users.table.groups.description', - }), + headerName: intl.formatMessage({ id: 'users.table.groups' }), + headerTooltip: intl.formatMessage({ id: 'users.table.groups.description' }), filterParams: { caseSensitive: false, trimInput: true, } as TextFilterParams, cellRenderer: MultiChipCellRenderer, }, - { - field: 'isAdmin', - cellDataType: 'boolean', - //detected as cellRenderer: 'agCheckboxCellRenderer', - cellRendererParams: { - disabled: true, - } as ICheckboxCellRendererParams, - flex: 1, - headerName: intl.formatMessage({ - id: 'users.table.isAdmin', - }), - headerTooltip: intl.formatMessage({ - id: 'users.table.isAdmin.description', - }), - filter: true, - }, ], [intl] ); diff --git a/src/services/user-admin.ts b/src/services/user-admin.ts index e561341..e219faf 100644 --- a/src/services/user-admin.ts +++ b/src/services/user-admin.ts @@ -10,16 +10,20 @@ import { UUID } from 'crypto'; const USER_ADMIN_URL = `${getRestBase()}/user-admin/v1`; -export type UserInfos = { +export type UserInfosUpdate = { sub: string; profileName?: string; - isAdmin: boolean; - groups: string[]; + groups?: string[]; +}; +export type UserInfos = UserInfosUpdate & { + maxAllowedCases?: number; + numberCasesUsed?: number; + maxAllowedBuilds?: number; }; export function fetchUsers(): Promise { console.debug(`Fetching list of users...`); - return backendFetchJson(`${USER_ADMIN_URL}/users`, { + return backendFetchJson(`${USER_ADMIN_URL}/users`, { headers: { Accept: 'application/json', //'Content-Type': 'application/json; utf-8', @@ -28,10 +32,10 @@ export function fetchUsers(): Promise { }).catch((reason) => { console.error(`Error while fetching the servers data : ${reason}`); throw reason; - }) as Promise; + }); } -export function updateUser(userInfos: UserInfos) { +export function updateUser(userInfos: UserInfosUpdate) { console.debug(`Updating a user...`); return backendFetch(`${USER_ADMIN_URL}/users/${userInfos.sub}`, { diff --git a/src/translations/en.json b/src/translations/en.json index 509d988..1edc465 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -32,8 +32,6 @@ "users.table.id": "ID", "users.table.id.description": "User identifier", - "users.table.isAdmin": "Admin", - "users.table.isAdmin.description": "The users is an administrator of GridSuite", "users.table.profileName": "Profile", "users.table.profileName.description": "The user's profile", "users.table.error.delete": "Error while deleting user", diff --git a/src/translations/fr.json b/src/translations/fr.json index 9b06933..e760a40 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -33,8 +33,6 @@ "users.table.id": "ID", "users.table.id.description": "Identifiant de l'utilisateur", - "users.table.isAdmin": "Admin", - "users.table.isAdmin.description": "L'utilisateur est administrateur de GridSuite", "users.table.profileName": "Profil", "users.table.profileName.description": "Nom du profil associé à l'utilisateur", "users.table.error.delete": "Erreur pendant la suppression de l'utilisateur",