@addev-be/ui 0.6.24 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +10 -7
- package/src/components/data/SqlRequestDataGrid/index.tsx +8 -5
- package/src/providers/AuthenticationProvider/helpers.ts +3 -0
- package/src/providers/AuthenticationProvider/index.tsx +24 -0
- package/src/services/base.ts +1 -9
- package/src/services/index.ts +0 -1
- package/src/services/types/userProfiles.ts +1 -1
- package/src/services/types/users.ts +7 -1
- package/src/services/types/userPermissions.ts +0 -3
package/package.json
CHANGED
|
@@ -248,15 +248,18 @@ export const sqlCheckboxColumn = <R extends Record<string, any>>(
|
|
|
248
248
|
): SqlRequestDataGridColumns<R> => ({
|
|
249
249
|
[key]: {
|
|
250
250
|
name: title,
|
|
251
|
-
render: (row) =>
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
251
|
+
render: (row) => {
|
|
252
|
+
const value = !!+(row[key] ?? 0);
|
|
253
|
+
return (
|
|
254
|
+
<>
|
|
255
|
+
<input type="checkbox" checked={value} readOnly />
|
|
256
|
+
<span>{value ? ' Oui' : ' Non'}</span>
|
|
257
|
+
</>
|
|
258
|
+
);
|
|
259
|
+
},
|
|
257
260
|
getter: (row) => row[key] ?? '',
|
|
258
261
|
sortGetter: (row) => row[key] ?? '',
|
|
259
|
-
filter: { ...numberFilter(key), getter: (value) => value[key] ?? 0 },
|
|
262
|
+
filter: { ...numberFilter(key), getter: (value) => +(value[key] ?? 0) },
|
|
260
263
|
footer: (rows) => `${rows[0][key]} éléments`,
|
|
261
264
|
...options,
|
|
262
265
|
},
|
|
@@ -85,11 +85,14 @@ export const SqlRequestDataGridInner = <R,>(
|
|
|
85
85
|
setCount(-1);
|
|
86
86
|
}, []);
|
|
87
87
|
|
|
88
|
-
const onFiltersChanged = useCallback(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
const onFiltersChanged = useCallback(
|
|
89
|
+
(filters: DataGridFilters) => {
|
|
90
|
+
const newConditions = convertSqlFiltersToConditions(filters);
|
|
91
|
+
setConditions(newConditions);
|
|
92
|
+
refresh();
|
|
93
|
+
},
|
|
94
|
+
[refresh]
|
|
95
|
+
);
|
|
93
96
|
|
|
94
97
|
const onSortsChanged = useCallback(
|
|
95
98
|
(sorts: Record<string, DataGridSort>) => {
|
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
useSendRecoveryKeyRequestHandler,
|
|
19
19
|
} from '../../services';
|
|
20
20
|
|
|
21
|
+
import { basePermissions } from './helpers';
|
|
22
|
+
|
|
21
23
|
export type AuthenticationContextProps = {
|
|
22
24
|
token?: string;
|
|
23
25
|
user?: UserDTO;
|
|
@@ -28,6 +30,8 @@ export type AuthenticationContextProps = {
|
|
|
28
30
|
sendRecoveryKey: (email: string) => Promise<number>;
|
|
29
31
|
checkRecoveryKey: (key: string) => Promise<number>;
|
|
30
32
|
resetPassword: (key: string, password: string) => Promise<number>;
|
|
33
|
+
permissions: Record<string, string>;
|
|
34
|
+
hasPermission: (permission: string) => boolean;
|
|
31
35
|
};
|
|
32
36
|
|
|
33
37
|
export const AuthenticationContext = createContext<AuthenticationContextProps>({
|
|
@@ -38,18 +42,26 @@ export const AuthenticationContext = createContext<AuthenticationContextProps>({
|
|
|
38
42
|
sendRecoveryKey: async () => -1,
|
|
39
43
|
checkRecoveryKey: async () => -1,
|
|
40
44
|
resetPassword: async () => -1,
|
|
45
|
+
permissions: {},
|
|
46
|
+
hasPermission: () => false,
|
|
41
47
|
});
|
|
42
48
|
|
|
43
49
|
export type AuthenticationProviderProps = PropsWithChildren<{
|
|
50
|
+
permissions?: Record<string, string>;
|
|
44
51
|
loginComponent?: FC;
|
|
45
52
|
requestHandlerName?: string;
|
|
46
53
|
}>;
|
|
47
54
|
|
|
48
55
|
export const AuthenticationProvider: FC<AuthenticationProviderProps> = ({
|
|
56
|
+
permissions,
|
|
49
57
|
loginComponent: LoginComponent,
|
|
50
58
|
children,
|
|
51
59
|
requestHandlerName,
|
|
52
60
|
}) => {
|
|
61
|
+
const allPermissions = useMemo(
|
|
62
|
+
() => ({ ...basePermissions, ...permissions }),
|
|
63
|
+
[permissions]
|
|
64
|
+
);
|
|
53
65
|
const [, setWebSocketStatus] = useState<boolean | undefined>(false);
|
|
54
66
|
const [token, setToken] = useState<string | undefined>(
|
|
55
67
|
sessionStorage.getItem('authToken') || undefined
|
|
@@ -148,6 +160,14 @@ export const AuthenticationProvider: FC<AuthenticationProviderProps> = ({
|
|
|
148
160
|
[sendCheckRecoveryKeyRequest]
|
|
149
161
|
);
|
|
150
162
|
|
|
163
|
+
const hasPermission = useCallback(
|
|
164
|
+
(permission: string) =>
|
|
165
|
+
permission in allPermissions &&
|
|
166
|
+
!!allPermissions[permission] &&
|
|
167
|
+
(user?.isAdmin || (user?.permissions?.includes(permission) ?? false)),
|
|
168
|
+
[allPermissions, user?.isAdmin, user?.permissions]
|
|
169
|
+
);
|
|
170
|
+
|
|
151
171
|
const contextValue = useMemo(
|
|
152
172
|
() => ({
|
|
153
173
|
token,
|
|
@@ -159,10 +179,14 @@ export const AuthenticationProvider: FC<AuthenticationProviderProps> = ({
|
|
|
159
179
|
sendRecoveryKey,
|
|
160
180
|
checkRecoveryKey,
|
|
161
181
|
resetPassword,
|
|
182
|
+
permissions: allPermissions,
|
|
183
|
+
hasPermission,
|
|
162
184
|
}),
|
|
163
185
|
[
|
|
186
|
+
allPermissions,
|
|
164
187
|
authenticate,
|
|
165
188
|
checkRecoveryKey,
|
|
189
|
+
hasPermission,
|
|
166
190
|
login,
|
|
167
191
|
logout,
|
|
168
192
|
resetPassword,
|
package/src/services/base.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
id: string;
|
|
3
|
-
dateAdd: string;
|
|
4
|
-
dateUpd: string;
|
|
5
|
-
dateDel: string | null;
|
|
6
|
-
};
|
|
1
|
+
import { BaseModelDTO } from './types/base';
|
|
7
2
|
|
|
8
3
|
export const emptyBaseModel: BaseModelDTO = {
|
|
9
4
|
id: '',
|
|
10
|
-
dateAdd: new Date().toISOString(),
|
|
11
|
-
dateUpd: new Date().toISOString(),
|
|
12
|
-
dateDel: null,
|
|
13
5
|
};
|
|
14
6
|
|
|
15
7
|
export type ArchivableModelDTO = BaseModelDTO & {
|
package/src/services/index.ts
CHANGED
|
@@ -62,7 +62,13 @@ export type GetAllUsersResponseDTO = t.TypeOf<
|
|
|
62
62
|
|
|
63
63
|
export const saveUserRequestDtoCodec = t.type(
|
|
64
64
|
{
|
|
65
|
-
|
|
65
|
+
data: t.intersection([
|
|
66
|
+
userDtoCodec,
|
|
67
|
+
t.partial({
|
|
68
|
+
password: t.string,
|
|
69
|
+
}),
|
|
70
|
+
]),
|
|
71
|
+
password: t.string,
|
|
66
72
|
},
|
|
67
73
|
'SaveUserRequestDTO'
|
|
68
74
|
);
|