Skip to content

Commit d820975

Browse files
Remove admin notion of users (#121)
It's now Managed by profiles in the auth system.
1 parent fad2cdf commit d820975

File tree

5 files changed

+25
-66
lines changed

5 files changed

+25
-66
lines changed

src/pages/users/modification/user-modification-dialog.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ const UserModificationDialog: FunctionComponent<UserModificationDialogProps> = (
4343

4444
useEffect(() => {
4545
if (userInfos && open) {
46-
const sortedGroups = Array.from(userInfos.groups).sort((a, b) => a.localeCompare(b));
46+
const sortedGroups = Array.from(userInfos.groups ?? []).sort((a, b) => a.localeCompare(b));
4747
reset({
4848
[USER_NAME]: userInfos.sub,
4949
[USER_PROFILE_NAME]: userInfos.profileName,
5050
[USER_SELECTED_GROUPS]: JSON.stringify(sortedGroups), // only used to dirty the form
5151
});
52-
setSelectedGroups(userInfos.groups);
52+
setSelectedGroups(userInfos.groups ?? []);
5353

5454
// fetch profile & groups
5555
setDataFetchStatus(FetchStatus.FETCHING);
@@ -109,22 +109,13 @@ const UserModificationDialog: FunctionComponent<UserModificationDialogProps> = (
109109
const onSubmit = useCallback(
110110
(userFormData: UserModificationFormType) => {
111111
if (userInfos) {
112-
const newData: UserInfos = {
112+
UserAdminSrv.updateUser({
113113
sub: userInfos.sub, // can't be changed
114-
isAdmin: userInfos.isAdmin, // can't be changed
115114
profileName: userFormData.profileName ?? undefined,
116115
groups: selectedGroups,
117-
};
118-
UserAdminSrv.updateUser(newData)
119-
.catch((error) =>
120-
snackError({
121-
messageTxt: error.message,
122-
headerId: 'users.table.error.update',
123-
})
124-
)
125-
.then(() => {
126-
onUpdate();
127-
});
116+
})
117+
.catch((error) => snackError({ messageTxt: error.message, headerId: 'users.table.error.update' }))
118+
.then(() => onUpdate());
128119
}
129120
},
130121
[onUpdate, selectedGroups, snackError, userInfos]

src/pages/users/users-table.tsx

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { FunctionComponent, RefObject, useCallback, useMemo, useState } from 'react';
8+
import { type FunctionComponent, type RefObject, useCallback, useMemo, useState } from 'react';
99
import { useIntl } from 'react-intl';
1010
import { PersonAdd } from '@mui/icons-material';
11-
import { GridButton, GridButtonDelete, GridTable, GridTableRef } from '../../components/Grid';
12-
import { GroupInfos, UserAdminSrv, UserInfos } from '../../services';
13-
import {
14-
ColDef,
15-
GetRowIdParams,
16-
ICheckboxCellRendererParams,
17-
RowClickedEvent,
18-
TextFilterParams,
19-
} from 'ag-grid-community';
11+
import { GridButton, GridButtonDelete, GridTable, type GridTableRef } from '../../components/Grid';
12+
import { type GroupInfos, UserAdminSrv, type UserInfos } from '../../services';
13+
import type { ColDef, GetRowIdParams, RowClickedEvent, TextFilterParams } from 'ag-grid-community';
2014
import { useSnackMessage } from '@gridsuite/commons-ui';
2115
import DeleteConfirmationDialog from '../common/delete-confirmation-dialog';
2216
import { defaultColDef, defaultRowSelection } from '../common/table-config';
@@ -65,9 +59,7 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
6559
lockVisible: true,
6660
filter: true,
6761
headerName: intl.formatMessage({ id: 'users.table.id' }),
68-
headerTooltip: intl.formatMessage({
69-
id: 'users.table.id.description',
70-
}),
62+
headerTooltip: intl.formatMessage({ id: 'users.table.id.description' }),
7163
filterParams: {
7264
caseSensitive: false,
7365
trimInput: true,
@@ -80,12 +72,8 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
8072
cellDataType: 'text',
8173
flex: 2,
8274
filter: true,
83-
headerName: intl.formatMessage({
84-
id: 'users.table.profileName',
85-
}),
86-
headerTooltip: intl.formatMessage({
87-
id: 'users.table.profileName.description',
88-
}),
75+
headerName: intl.formatMessage({ id: 'users.table.profileName' }),
76+
headerTooltip: intl.formatMessage({ id: 'users.table.profileName.description' }),
8977
filterParams: {
9078
caseSensitive: false,
9179
trimInput: true,
@@ -98,34 +86,14 @@ const UsersTable: FunctionComponent<UsersTableProps> = (props) => {
9886
cellDataType: 'text',
9987
flex: 4,
10088
filter: true,
101-
headerName: intl.formatMessage({
102-
id: 'users.table.groups',
103-
}),
104-
headerTooltip: intl.formatMessage({
105-
id: 'users.table.groups.description',
106-
}),
89+
headerName: intl.formatMessage({ id: 'users.table.groups' }),
90+
headerTooltip: intl.formatMessage({ id: 'users.table.groups.description' }),
10791
filterParams: {
10892
caseSensitive: false,
10993
trimInput: true,
11094
} as TextFilterParams<GroupInfos>,
11195
cellRenderer: MultiChipCellRenderer,
11296
},
113-
{
114-
field: 'isAdmin',
115-
cellDataType: 'boolean',
116-
//detected as cellRenderer: 'agCheckboxCellRenderer',
117-
cellRendererParams: {
118-
disabled: true,
119-
} as ICheckboxCellRendererParams<UserInfos, {}>,
120-
flex: 1,
121-
headerName: intl.formatMessage({
122-
id: 'users.table.isAdmin',
123-
}),
124-
headerTooltip: intl.formatMessage({
125-
id: 'users.table.isAdmin.description',
126-
}),
127-
filter: true,
128-
},
12997
],
13098
[intl]
13199
);

src/services/user-admin.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ import { UUID } from 'crypto';
1010

1111
const USER_ADMIN_URL = `${getRestBase()}/user-admin/v1`;
1212

13-
export type UserInfos = {
13+
export type UserInfosUpdate = {
1414
sub: string;
1515
profileName?: string;
16-
isAdmin: boolean;
17-
groups: string[];
16+
groups?: string[];
17+
};
18+
export type UserInfos = UserInfosUpdate & {
19+
maxAllowedCases?: number;
20+
numberCasesUsed?: number;
21+
maxAllowedBuilds?: number;
1822
};
1923

2024
export function fetchUsers(): Promise<UserInfos[]> {
2125
console.debug(`Fetching list of users...`);
22-
return backendFetchJson(`${USER_ADMIN_URL}/users`, {
26+
return backendFetchJson<UserInfos[]>(`${USER_ADMIN_URL}/users`, {
2327
headers: {
2428
Accept: 'application/json',
2529
//'Content-Type': 'application/json; utf-8',
@@ -28,10 +32,10 @@ export function fetchUsers(): Promise<UserInfos[]> {
2832
}).catch((reason) => {
2933
console.error(`Error while fetching the servers data : ${reason}`);
3034
throw reason;
31-
}) as Promise<UserInfos[]>;
35+
});
3236
}
3337

34-
export function updateUser(userInfos: UserInfos) {
38+
export function updateUser(userInfos: UserInfosUpdate) {
3539
console.debug(`Updating a user...`);
3640

3741
return backendFetch(`${USER_ADMIN_URL}/users/${userInfos.sub}`, {

src/translations/en.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
"users.table.id": "ID",
3434
"users.table.id.description": "User identifier",
35-
"users.table.isAdmin": "Admin",
36-
"users.table.isAdmin.description": "The users is an administrator of GridSuite",
3735
"users.table.profileName": "Profile",
3836
"users.table.profileName.description": "The user's profile",
3937
"users.table.error.delete": "Error while deleting user",

src/translations/fr.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
"users.table.id": "ID",
3535
"users.table.id.description": "Identifiant de l'utilisateur",
36-
"users.table.isAdmin": "Admin",
37-
"users.table.isAdmin.description": "L'utilisateur est administrateur de GridSuite",
3836
"users.table.profileName": "Profil",
3937
"users.table.profileName.description": "Nom du profil associé à l'utilisateur",
4038
"users.table.error.delete": "Erreur pendant la suppression de l'utilisateur",

0 commit comments

Comments
 (0)