Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 6 additions & 15 deletions src/pages/users/modification/user-modification-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ const UserModificationDialog: FunctionComponent<UserModificationDialogProps> = (

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);
Expand Down Expand Up @@ -109,22 +109,13 @@ const UserModificationDialog: FunctionComponent<UserModificationDialogProps> = (
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]
Expand Down
50 changes: 9 additions & 41 deletions src/pages/users/users-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -65,9 +59,7 @@ const UsersTable: FunctionComponent<UsersTableProps> = (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,
Expand All @@ -80,12 +72,8 @@ const UsersTable: FunctionComponent<UsersTableProps> = (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,
Expand All @@ -98,34 +86,14 @@ const UsersTable: FunctionComponent<UsersTableProps> = (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<GroupInfos>,
cellRenderer: MultiChipCellRenderer,
},
{
field: 'isAdmin',
cellDataType: 'boolean',
//detected as cellRenderer: 'agCheckboxCellRenderer',
cellRendererParams: {
disabled: true,
} as ICheckboxCellRendererParams<UserInfos, {}>,
flex: 1,
headerName: intl.formatMessage({
id: 'users.table.isAdmin',
}),
headerTooltip: intl.formatMessage({
id: 'users.table.isAdmin.description',
}),
filter: true,
},
],
[intl]
);
Expand Down
16 changes: 10 additions & 6 deletions src/services/user-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserInfos[]> {
console.debug(`Fetching list of users...`);
return backendFetchJson(`${USER_ADMIN_URL}/users`, {
return backendFetchJson<UserInfos[]>(`${USER_ADMIN_URL}/users`, {
headers: {
Accept: 'application/json',
//'Content-Type': 'application/json; utf-8',
Expand All @@ -28,10 +32,10 @@ export function fetchUsers(): Promise<UserInfos[]> {
}).catch((reason) => {
console.error(`Error while fetching the servers data : ${reason}`);
throw reason;
}) as Promise<UserInfos[]>;
});
}

export function updateUser(userInfos: UserInfos) {
export function updateUser(userInfos: UserInfosUpdate) {
console.debug(`Updating a user...`);

return backendFetch(`${USER_ADMIN_URL}/users/${userInfos.sub}`, {
Expand Down
2 changes: 0 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading