@firecms/user_management 3.0.0-beta.6 → 3.0.0-beta.8
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/dist/hooks/useFirestoreUserManagement.d.ts +1 -1
- package/dist/index.es.js +169 -180
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/user_management.d.ts +4 -0
- package/package.json +13 -27
- package/src/hooks/useFirestoreUserManagement.tsx +6 -3
- package/src/types/user_management.tsx +5 -0
package/dist/index.es.js
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
import F, { useEffect as ce, useCallback as k, useContext as
|
2
|
-
import { getFirestore as Y, onSnapshot as ue, collection as ee, setDoc as me, doc as H, addDoc as
|
1
|
+
import F, { useEffect as ce, useCallback as k, useContext as Fe, useState as A } from "react";
|
2
|
+
import { getFirestore as Y, onSnapshot as ue, collection as ee, setDoc as me, doc as H, addDoc as Ae, deleteDoc as he } from "@firebase/firestore";
|
3
3
|
import { jsx as e, jsxs as s, Fragment as K } from "react/jsx-runtime";
|
4
|
-
import { getColorSchemeForSeed as Pe, Chip as
|
4
|
+
import { getColorSchemeForSeed as Pe, Chip as Te, Dialog as fe, DialogContent as ge, Typography as P, TextField as Q, Paper as pe, Table as re, TableHeader as ie, TableCell as d, TableBody as oe, TableRow as W, Tooltip as V, Checkbox as I, Select as ne, SelectItem as L, DialogActions as Ce, Button as O, LoadingButton as ve, DoneIcon as we, IconButton as ye, DeleteIcon as be, CenteredView as Ne, Container as Ue, AddIcon as le, MultiSelect as Le, MultiSelectItem as Be } from "@firecms/ui";
|
5
5
|
import * as M from "yup";
|
6
|
-
import { toSnakeCase as
|
6
|
+
import { toSnakeCase as _e, FieldCaption as B, DeleteConfirmationDialog as xe, useNavigationController as Ve, useSnackbarController as se, useAuthController as ae, useCustomizationController as Me, defaultDateFormat as Oe } from "@firecms/core";
|
7
7
|
import { useCreateFormex as Re, getIn as J, Formex as De } from "@firecms/formex";
|
8
|
-
import { format as
|
9
|
-
import * as
|
10
|
-
const
|
8
|
+
import { format as $e } from "date-fns";
|
9
|
+
import * as qe from "date-fns/locale";
|
10
|
+
const gn = ["Admin"], Ye = {
|
11
11
|
read: !1,
|
12
12
|
edit: !1,
|
13
13
|
create: !1,
|
14
14
|
delete: !1
|
15
15
|
};
|
16
|
-
function
|
16
|
+
function We({
|
17
17
|
collection: t,
|
18
18
|
user: r
|
19
19
|
}) {
|
@@ -33,12 +33,11 @@ function Ye({
|
|
33
33
|
edit: !1,
|
34
34
|
delete: !1
|
35
35
|
};
|
36
|
-
return n.map((i) =>
|
36
|
+
return n.map((i) => je(i, t.id)).reduce(te, l);
|
37
37
|
}
|
38
|
-
} else
|
39
|
-
return qe;
|
38
|
+
} else return Ye;
|
40
39
|
}
|
41
|
-
function
|
40
|
+
function je(t, r) {
|
42
41
|
const n = {
|
43
42
|
read: t.isAdmin || t.defaultPermissions?.read,
|
44
43
|
create: t.isAdmin || t.defaultPermissions?.create,
|
@@ -53,23 +52,23 @@ const te = (t, r) => ({
|
|
53
52
|
edit: t.edit || r.edit,
|
54
53
|
delete: t.delete || r.delete
|
55
54
|
});
|
56
|
-
function
|
55
|
+
function pn(t, r) {
|
57
56
|
return t ? r.roles ? r.roles.map((n) => t.find((l) => l.id === n.id)).filter(Boolean) : [] : void 0;
|
58
57
|
}
|
59
|
-
const
|
58
|
+
const ze = (t, r) => {
|
60
59
|
const n = t.map((i) => i.id), l = r.map((i) => i.id);
|
61
60
|
return n.length === r.length && n.every((i) => l.includes(i));
|
62
61
|
};
|
63
|
-
function
|
62
|
+
function Cn(t, r) {
|
64
63
|
if (!r)
|
65
64
|
return;
|
66
|
-
const n =
|
65
|
+
const n = Je(r), l = new Date(n.exp * 1e3);
|
67
66
|
localStorage.setItem(`auth_token::${t}`, JSON.stringify({
|
68
67
|
token: r,
|
69
68
|
expiry: l
|
70
69
|
}));
|
71
70
|
}
|
72
|
-
function
|
71
|
+
function vn(t) {
|
73
72
|
const r = localStorage.getItem(`auth_token::${t}`);
|
74
73
|
if (r) {
|
75
74
|
const n = JSON.parse(r);
|
@@ -77,13 +76,13 @@ function Cn(t) {
|
|
77
76
|
return n.token;
|
78
77
|
}
|
79
78
|
}
|
80
|
-
function
|
79
|
+
function wn() {
|
81
80
|
for (let t = 0; t < localStorage.length; t++) {
|
82
81
|
const r = localStorage.key(t);
|
83
82
|
r?.startsWith("auth_token::") && localStorage.removeItem(r);
|
84
83
|
}
|
85
84
|
}
|
86
|
-
function
|
85
|
+
function Je(t) {
|
87
86
|
if (!t)
|
88
87
|
throw new Error("No JWT token");
|
89
88
|
const n = t.split(".")[1].replace(/-/g, "+").replace(/_/g, "/"), l = decodeURIComponent(window.atob(n).split("").map(function(i) {
|
@@ -91,7 +90,7 @@ function ze(t) {
|
|
91
90
|
}).join(""));
|
92
91
|
return JSON.parse(l);
|
93
92
|
}
|
94
|
-
function
|
93
|
+
function yn(t, r = 10) {
|
95
94
|
if (!/^#([0-9A-Fa-f]{3}){1,2}$/.test(t))
|
96
95
|
throw new Error("Invalid color format");
|
97
96
|
let n = t.substring(1).split("");
|
@@ -99,38 +98,37 @@ function wn(t, r = 10) {
|
|
99
98
|
let l = parseInt(n[0] + n[1], 16), i = parseInt(n[2] + n[3], 16), m = parseInt(n[4] + n[5], 16);
|
100
99
|
return l = Math.floor(l * (1 - r / 100)), i = Math.floor(i * (1 - r / 100)), m = Math.floor(m * (1 - r / 100)), "#" + (l < 16 ? "0" : "") + l.toString(16) + (i < 16 ? "0" : "") + i.toString(16) + (m < 16 ? "0" : "") + m.toString(16);
|
101
100
|
}
|
102
|
-
function
|
101
|
+
function bn(t, r = 10) {
|
103
102
|
if (!/^#([0-9A-Fa-f]{3}){1,2}$/.test(t))
|
104
103
|
throw new Error("Invalid color format");
|
105
104
|
let n = t.substring(1).split("");
|
106
105
|
n.length === 3 && (n = [n[0], n[0], n[1], n[1], n[2], n[2]]);
|
107
|
-
const l = parseInt(n[0] + n[1], 16), i = parseInt(n[2] + n[3], 16), m = parseInt(n[4] + n[5], 16),
|
108
|
-
return `rgba(${l}, ${i}, ${m}, ${
|
106
|
+
const l = parseInt(n[0] + n[1], 16), i = parseInt(n[2] + n[3], 16), m = parseInt(n[4] + n[5], 16), g = r / 100;
|
107
|
+
return `rgba(${l}, ${i}, ${m}, ${g})`;
|
109
108
|
}
|
110
|
-
function
|
109
|
+
function Nn({
|
111
110
|
firebaseApp: t,
|
112
111
|
usersPath: r = "__FIRECMS/config/users",
|
113
112
|
rolesPath: n = "__FIRECMS/config/roles",
|
114
113
|
usersLimit: l,
|
115
114
|
canEditRoles: i = !0,
|
116
115
|
allowDefaultRolesCreation: m,
|
117
|
-
includeCollectionConfigPermissions:
|
116
|
+
includeCollectionConfigPermissions: g
|
118
117
|
}) {
|
119
|
-
const [v, R] = F.useState(!0), [w, c] = F.useState(!0), [
|
120
|
-
...
|
121
|
-
roles:
|
118
|
+
const [v, R] = F.useState(!0), [w, c] = F.useState(!0), [E, U] = F.useState([]), [a, C] = F.useState([]), y = a.map((f) => ({
|
119
|
+
...f,
|
120
|
+
roles: E.filter((p) => f.roles?.includes(p.id))
|
122
121
|
})), [b, _] = F.useState(), [z, u] = F.useState(), h = v || w;
|
123
122
|
ce(() => {
|
124
|
-
if (!t || !n)
|
125
|
-
|
126
|
-
const g = Y(t);
|
123
|
+
if (!t || !n) return;
|
124
|
+
const f = Y(t);
|
127
125
|
return ue(
|
128
|
-
ee(
|
126
|
+
ee(f, n),
|
129
127
|
{
|
130
128
|
next: (p) => {
|
131
129
|
_(void 0);
|
132
130
|
try {
|
133
|
-
const N =
|
131
|
+
const N = He(p.docs);
|
134
132
|
U(N);
|
135
133
|
} catch (N) {
|
136
134
|
console.error("Error loading roles", N), _(N);
|
@@ -143,16 +141,15 @@ function bn({
|
|
143
141
|
}
|
144
142
|
);
|
145
143
|
}, [t, n]), ce(() => {
|
146
|
-
if (!t || !r)
|
147
|
-
|
148
|
-
const g = Y(t);
|
144
|
+
if (!t || !r) return;
|
145
|
+
const f = Y(t);
|
149
146
|
return ue(
|
150
|
-
ee(
|
147
|
+
ee(f, r),
|
151
148
|
{
|
152
149
|
next: (p) => {
|
153
150
|
u(void 0);
|
154
151
|
try {
|
155
|
-
const N =
|
152
|
+
const N = Ge(p.docs);
|
156
153
|
C(N);
|
157
154
|
} catch (N) {
|
158
155
|
console.error("Error loading users", N), u(N);
|
@@ -165,71 +162,62 @@ function bn({
|
|
165
162
|
}
|
166
163
|
);
|
167
164
|
}, [t, r]);
|
168
|
-
const x = k(async (
|
169
|
-
if (!t)
|
170
|
-
throw Error("useFirestoreUserManagement Firebase not initialised");
|
165
|
+
const x = k(async (f) => {
|
166
|
+
if (!t) throw Error("useFirestoreUserManagement Firebase not initialised");
|
171
167
|
const p = Y(t);
|
172
|
-
if (!p || !r)
|
173
|
-
|
174
|
-
|
175
|
-
const N = g.roles?.map((ke) => ke.id), {
|
168
|
+
if (!p || !r) throw Error("useFirestoreUserManagement Firestore not initialised");
|
169
|
+
console.debug("Persisting user", f);
|
170
|
+
const N = f.roles?.map((Ie) => Ie.id), {
|
176
171
|
uid: q,
|
177
172
|
...Z
|
178
|
-
} =
|
173
|
+
} = f, de = {
|
179
174
|
...Z,
|
180
175
|
roles: N
|
181
176
|
};
|
182
|
-
return q ? me(H(p, r, q), de, { merge: !0 }).then(() =>
|
183
|
-
}, [r, t]), D = k((
|
184
|
-
if (!t)
|
185
|
-
throw Error("useFirestoreUserManagement Firebase not initialised");
|
177
|
+
return q ? me(H(p, r, q), de, { merge: !0 }).then(() => f) : Ae(ee(p, r), de).then(() => f);
|
178
|
+
}, [r, t]), D = k((f) => {
|
179
|
+
if (!t) throw Error("useFirestoreUserManagement Firebase not initialised");
|
186
180
|
const p = Y(t);
|
187
|
-
if (!p || !n)
|
188
|
-
|
189
|
-
console.debug("Persisting role", g);
|
181
|
+
if (!p || !n) throw Error("useFirestoreUserManagement Firestore not initialised");
|
182
|
+
console.debug("Persisting role", f);
|
190
183
|
const {
|
191
184
|
id: N,
|
192
185
|
...q
|
193
|
-
} =
|
186
|
+
} = f, Z = H(p, n, N);
|
194
187
|
return me(Z, q, { merge: !0 });
|
195
|
-
}, [n, t]), T = k(async (
|
196
|
-
if (!t)
|
197
|
-
throw Error("useFirestoreUserManagement Firebase not initialised");
|
188
|
+
}, [n, t]), T = k(async (f) => {
|
189
|
+
if (!t) throw Error("useFirestoreUserManagement Firebase not initialised");
|
198
190
|
const p = Y(t);
|
199
|
-
if (!p || !r)
|
200
|
-
|
201
|
-
|
202
|
-
const { uid: N } = g;
|
191
|
+
if (!p || !r) throw Error("useFirestoreUserManagement Firestore not initialised");
|
192
|
+
console.debug("Deleting", f);
|
193
|
+
const { uid: N } = f;
|
203
194
|
return he(H(p, r, N));
|
204
|
-
}, [r, t]), o = k((
|
205
|
-
if (!t)
|
206
|
-
throw Error("useFirestoreUserManagement Firebase not initialised");
|
195
|
+
}, [r, t]), o = k((f) => {
|
196
|
+
if (!t) throw Error("useFirestoreUserManagement Firebase not initialised");
|
207
197
|
const p = Y(t);
|
208
|
-
if (!p || !n)
|
209
|
-
|
210
|
-
|
211
|
-
const { id: N } = g, q = H(p, n, N);
|
198
|
+
if (!p || !n) throw Error("useFirestoreUserManagement Firestore not initialised");
|
199
|
+
console.debug("Deleting", f);
|
200
|
+
const { id: N } = f, q = H(p, n, N);
|
212
201
|
return he(q);
|
213
|
-
}, [n, t]),
|
214
|
-
collection:
|
202
|
+
}, [n, t]), S = k(({
|
203
|
+
collection: f,
|
215
204
|
user: p
|
216
|
-
}) =>
|
217
|
-
collection:
|
205
|
+
}) => We({
|
206
|
+
collection: f,
|
218
207
|
user: p
|
219
|
-
}), []), $ = k((
|
220
|
-
if (!y)
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
if (console.debug("Authenticating user", g), h)
|
208
|
+
}), []), $ = k((f) => {
|
209
|
+
if (!y) throw Error("Users not loaded");
|
210
|
+
return y.find((N) => N.email?.toLowerCase() === f?.email?.toLowerCase())?.roles;
|
211
|
+
}, [y]), G = k(({ user: f }) => {
|
212
|
+
if (console.debug("Authenticating user", f), h)
|
225
213
|
return console.warn("User management is still loading"), !1;
|
226
|
-
if (y.length === 0 || y.find((N) => N.email?.toLowerCase() ===
|
214
|
+
if (y.length === 0 || y.find((N) => N.email?.toLowerCase() === f?.email?.toLowerCase()))
|
227
215
|
return !0;
|
228
216
|
throw Error("Could not find a user with the provided email in the user management system.");
|
229
|
-
}, [h, y]);
|
217
|
+
}, [h, y]), ke = E.some((f) => f.id === "admin");
|
230
218
|
return {
|
231
219
|
loading: h,
|
232
|
-
roles:
|
220
|
+
roles: E,
|
233
221
|
users: y,
|
234
222
|
saveUser: x,
|
235
223
|
saveRole: D,
|
@@ -238,15 +226,16 @@ function bn({
|
|
238
226
|
deleteRole: o,
|
239
227
|
usersLimit: l,
|
240
228
|
usersError: z,
|
229
|
+
isAdmin: ke,
|
241
230
|
canEditRoles: i === void 0 ? !0 : i,
|
242
231
|
allowDefaultRolesCreation: m === void 0 ? !0 : m,
|
243
|
-
includeCollectionConfigPermissions: !!
|
244
|
-
collectionPermissions:
|
232
|
+
includeCollectionConfigPermissions: !!g,
|
233
|
+
collectionPermissions: S,
|
245
234
|
defineRolesFor: $,
|
246
235
|
authenticator: G
|
247
236
|
};
|
248
237
|
}
|
249
|
-
const
|
238
|
+
const Ge = (t) => t.map((r) => {
|
250
239
|
const n = r.data();
|
251
240
|
return {
|
252
241
|
uid: r.id,
|
@@ -254,21 +243,21 @@ const Je = (t) => t.map((r) => {
|
|
254
243
|
created_on: n?.created_on?.toDate(),
|
255
244
|
updated_on: n?.updated_on?.toDate()
|
256
245
|
};
|
257
|
-
}),
|
246
|
+
}), He = (t) => t.map((r) => ({
|
258
247
|
id: r.id,
|
259
248
|
...r.data()
|
260
249
|
})), Ee = F.createContext({});
|
261
|
-
function
|
250
|
+
function Ke({
|
262
251
|
children: t,
|
263
252
|
userManagement: r
|
264
253
|
}) {
|
265
254
|
return /* @__PURE__ */ e(Ee.Provider, { value: r, children: t });
|
266
255
|
}
|
267
|
-
const j = () =>
|
256
|
+
const j = () => Fe(Ee);
|
268
257
|
function X({ role: t }) {
|
269
258
|
let r;
|
270
259
|
return t.isAdmin ? r = "blueDarker" : t.id === "editor" ? r = "yellowLight" : t.id === "viewer" ? r = "grayLight" : r = Pe(t.id), /* @__PURE__ */ e(
|
271
|
-
|
260
|
+
Te,
|
272
261
|
{
|
273
262
|
colorScheme: r,
|
274
263
|
children: t.name
|
@@ -276,34 +265,34 @@ function X({ role: t }) {
|
|
276
265
|
t.id
|
277
266
|
);
|
278
267
|
}
|
279
|
-
const
|
268
|
+
const Qe = M.object().shape({
|
280
269
|
id: M.string().required("Required"),
|
281
270
|
name: M.string().required("Required")
|
282
271
|
});
|
283
|
-
function
|
272
|
+
function Xe({
|
284
273
|
open: t,
|
285
274
|
role: r,
|
286
275
|
editable: n,
|
287
276
|
handleClose: l,
|
288
277
|
collections: i
|
289
278
|
}) {
|
290
|
-
const { saveRole: m } = j(),
|
279
|
+
const { saveRole: m } = j(), g = !r, [v, R] = A(), w = k((o) => (R(void 0), m(o)), [m]), c = Re({
|
291
280
|
initialValues: r ?? {
|
292
281
|
name: ""
|
293
282
|
},
|
294
|
-
onSubmit: (o,
|
295
|
-
|
283
|
+
onSubmit: (o, S) => w(o).then(() => {
|
284
|
+
S.resetForm({
|
296
285
|
values: o
|
297
286
|
}), l();
|
298
287
|
}).catch(($) => R($)),
|
299
|
-
validation: (o) =>
|
288
|
+
validation: (o) => Qe.validate(o, { abortEarly: !1 }).then(() => ({})).catch((S) => {
|
300
289
|
const $ = {};
|
301
|
-
return
|
290
|
+
return S.inner.forEach((G) => {
|
302
291
|
$[G.path] = G.message;
|
303
292
|
}), $;
|
304
293
|
})
|
305
294
|
}), {
|
306
|
-
isSubmitting:
|
295
|
+
isSubmitting: E,
|
307
296
|
touched: U,
|
308
297
|
values: a,
|
309
298
|
errors: C,
|
@@ -313,7 +302,7 @@ function Qe({
|
|
313
302
|
setFieldTouched: z
|
314
303
|
} = c, u = a.isAdmin ?? !1, h = a.defaultPermissions?.create ?? !1, x = a.defaultPermissions?.read ?? !1, D = a.defaultPermissions?.edit ?? !1, T = a.defaultPermissions?.delete ?? !1;
|
315
304
|
return F.useEffect(() => {
|
316
|
-
!J(U, "id") && a.name && b("id",
|
305
|
+
!J(U, "id") && a.name && b("id", _e(a.name));
|
317
306
|
}, [U, a.name]), /* @__PURE__ */ e(
|
318
307
|
fe,
|
319
308
|
{
|
@@ -338,7 +327,7 @@ function Qe({
|
|
338
327
|
{
|
339
328
|
className: "flex flex-row pt-12 pb-8",
|
340
329
|
children: /* @__PURE__ */ e(
|
341
|
-
|
330
|
+
P,
|
342
331
|
{
|
343
332
|
variant: "h4",
|
344
333
|
className: "flex-grow",
|
@@ -372,7 +361,7 @@ function Qe({
|
|
372
361
|
required: !0,
|
373
362
|
error: U.id && !!C.id,
|
374
363
|
value: a.id,
|
375
|
-
disabled: !
|
364
|
+
disabled: !g || !n,
|
376
365
|
onChange: (o) => {
|
377
366
|
y(o), z("id", !0);
|
378
367
|
},
|
@@ -526,7 +515,7 @@ function Qe({
|
|
526
515
|
{
|
527
516
|
disabled: u || h || !n,
|
528
517
|
checked: (u || h || J(a, `collectionPermissions.${o.path}.create`)) ?? !1,
|
529
|
-
onCheckedChange: (
|
518
|
+
onCheckedChange: (S) => b(`collectionPermissions.${o.path}.create`, S)
|
530
519
|
}
|
531
520
|
)
|
532
521
|
}
|
@@ -540,7 +529,7 @@ function Qe({
|
|
540
529
|
{
|
541
530
|
disabled: u || x || !n,
|
542
531
|
checked: (u || x || J(a, `collectionPermissions.${o.path}.read`)) ?? !1,
|
543
|
-
onCheckedChange: (
|
532
|
+
onCheckedChange: (S) => b(`collectionPermissions.${o.path}.read`, S)
|
544
533
|
}
|
545
534
|
)
|
546
535
|
}
|
@@ -554,7 +543,7 @@ function Qe({
|
|
554
543
|
{
|
555
544
|
disabled: u || D || !n,
|
556
545
|
checked: (u || D || J(a, `collectionPermissions.${o.path}.edit`)) ?? !1,
|
557
|
-
onCheckedChange: (
|
546
|
+
onCheckedChange: (S) => b(`collectionPermissions.${o.path}.edit`, S)
|
558
547
|
}
|
559
548
|
)
|
560
549
|
}
|
@@ -568,7 +557,7 @@ function Qe({
|
|
568
557
|
{
|
569
558
|
disabled: u || T || !n,
|
570
559
|
checked: (u || T || J(a, `collectionPermissions.${o.path}.delete`)) ?? !1,
|
571
|
-
onCheckedChange: (
|
560
|
+
onCheckedChange: (S) => b(`collectionPermissions.${o.path}.delete`, S)
|
572
561
|
}
|
573
562
|
)
|
574
563
|
}
|
@@ -696,7 +685,7 @@ function Qe({
|
|
696
685
|
] })
|
697
686
|
] }),
|
698
687
|
/* @__PURE__ */ s(Ce, { position: "sticky", children: [
|
699
|
-
v && /* @__PURE__ */ e(
|
688
|
+
v && /* @__PURE__ */ e(P, { className: "text-red-500", children: "There was an error saving this role" }),
|
700
689
|
/* @__PURE__ */ e(
|
701
690
|
O,
|
702
691
|
{
|
@@ -714,9 +703,9 @@ function Qe({
|
|
714
703
|
color: "primary",
|
715
704
|
type: "submit",
|
716
705
|
disabled: !_,
|
717
|
-
loading:
|
706
|
+
loading: E,
|
718
707
|
startIcon: /* @__PURE__ */ e(we, {}),
|
719
|
-
children:
|
708
|
+
children: g ? "Create role" : "Update"
|
720
709
|
}
|
721
710
|
)
|
722
711
|
] })
|
@@ -760,7 +749,7 @@ const Se = [
|
|
760
749
|
}
|
761
750
|
}
|
762
751
|
];
|
763
|
-
function
|
752
|
+
function Ze({
|
764
753
|
onRoleClicked: t,
|
765
754
|
editable: r
|
766
755
|
}) {
|
@@ -769,7 +758,7 @@ function Xe({
|
|
769
758
|
saveRole: l,
|
770
759
|
deleteRole: i,
|
771
760
|
allowDefaultRolesCreation: m
|
772
|
-
} = j(), [
|
761
|
+
} = j(), [g, v] = A(void 0), [R, w] = A(!1);
|
773
762
|
return /* @__PURE__ */ s(
|
774
763
|
"div",
|
775
764
|
{
|
@@ -784,7 +773,7 @@ function Xe({
|
|
784
773
|
] }),
|
785
774
|
/* @__PURE__ */ s(oe, { children: [
|
786
775
|
n && n.map((c) => {
|
787
|
-
const
|
776
|
+
const E = c.isAdmin || c.defaultPermissions?.create, U = c.isAdmin || c.defaultPermissions?.read, a = c.isAdmin || c.defaultPermissions?.edit, C = c.isAdmin || c.defaultPermissions?.delete;
|
788
777
|
return /* @__PURE__ */ s(
|
789
778
|
W,
|
790
779
|
{
|
@@ -804,7 +793,7 @@ function Xe({
|
|
804
793
|
/* @__PURE__ */ e(d, { children: /* @__PURE__ */ e(X, { role: c }) }),
|
805
794
|
/* @__PURE__ */ e(d, { className: "items-center", children: /* @__PURE__ */ e(I, { checked: c.isAdmin ?? !1 }) }),
|
806
795
|
/* @__PURE__ */ e(d, { children: /* @__PURE__ */ s("ul", { children: [
|
807
|
-
|
796
|
+
E && /* @__PURE__ */ e("li", { children: "Create" }),
|
808
797
|
U && /* @__PURE__ */ e("li", { children: "Read" }),
|
809
798
|
a && /* @__PURE__ */ e("li", { children: "Update" }),
|
810
799
|
C && /* @__PURE__ */ e("li", { children: "Delete" })
|
@@ -815,7 +804,7 @@ function Xe({
|
|
815
804
|
);
|
816
805
|
}),
|
817
806
|
(!n || n.length === 0) && /* @__PURE__ */ e(W, { children: /* @__PURE__ */ e(d, { colspan: 4, children: /* @__PURE__ */ s(Ne, { className: "flex flex-col gap-4 my-8 items-center", children: [
|
818
|
-
/* @__PURE__ */ e(
|
807
|
+
/* @__PURE__ */ e(P, { variant: "label", children: "You don't have any roles yet." }),
|
819
808
|
m && /* @__PURE__ */ e(
|
820
809
|
O,
|
821
810
|
{
|
@@ -834,10 +823,10 @@ function Xe({
|
|
834
823
|
/* @__PURE__ */ e(
|
835
824
|
xe,
|
836
825
|
{
|
837
|
-
open: !!
|
826
|
+
open: !!g,
|
838
827
|
loading: R,
|
839
828
|
onAccept: () => {
|
840
|
-
|
829
|
+
g && (w(!0), i(g).then(() => {
|
841
830
|
v(void 0);
|
842
831
|
}).finally(() => {
|
843
832
|
w(!1);
|
@@ -854,16 +843,16 @@ function Xe({
|
|
854
843
|
}
|
855
844
|
);
|
856
845
|
}
|
857
|
-
const
|
846
|
+
const en = F.memo(
|
858
847
|
function({ children: r }) {
|
859
|
-
const { collections: n } =
|
860
|
-
i(!0),
|
848
|
+
const { collections: n } = Ve(), [l, i] = A(!1), [m, g] = A(), { canEditRoles: v } = j(), R = k((c) => {
|
849
|
+
i(!0), g(c);
|
861
850
|
}, []);
|
862
851
|
return /* @__PURE__ */ s(Ue, { className: "w-full flex flex-col py-4 gap-4", maxWidth: "6xl", children: [
|
863
852
|
r,
|
864
853
|
/* @__PURE__ */ s("div", { className: "flex items-center mt-12", children: [
|
865
854
|
/* @__PURE__ */ e(
|
866
|
-
|
855
|
+
P,
|
867
856
|
{
|
868
857
|
gutterBottom: !0,
|
869
858
|
variant: "h4",
|
@@ -883,36 +872,36 @@ const Ze = F.memo(
|
|
883
872
|
}
|
884
873
|
) })
|
885
874
|
] }),
|
886
|
-
/* @__PURE__ */ e(
|
875
|
+
/* @__PURE__ */ e(Ze, { onRoleClicked: R, editable: !!v }),
|
887
876
|
/* @__PURE__ */ e(
|
888
|
-
|
877
|
+
Xe,
|
889
878
|
{
|
890
879
|
open: l,
|
891
880
|
role: m,
|
892
881
|
editable: v,
|
893
882
|
collections: n,
|
894
883
|
handleClose: () => {
|
895
|
-
|
884
|
+
g(void 0), i(!1);
|
896
885
|
}
|
897
886
|
},
|
898
887
|
m?.id ?? "new"
|
899
888
|
)
|
900
889
|
] });
|
901
890
|
}
|
902
|
-
),
|
891
|
+
), nn = M.object().shape({
|
903
892
|
displayName: M.string().required("Required"),
|
904
893
|
email: M.string().email().required("Required"),
|
905
894
|
roles: M.array().min(1)
|
906
895
|
});
|
907
|
-
function
|
908
|
-
const m = n.filter((w) => w.roles?.map((c) => c.id).includes("admin")),
|
909
|
-
if ((!i || !
|
896
|
+
function tn(t, r, n, l, i) {
|
897
|
+
const m = n.filter((w) => w.roles?.map((c) => c.id).includes("admin")), g = t.roles?.map((w) => w.id).includes("admin");
|
898
|
+
if ((!i || !ze(i.roles ?? [], r.roles ?? [])) && !g)
|
910
899
|
throw new Error("Only admins can change roles");
|
911
900
|
if (i && i.roles?.map((w) => w.id).includes("admin") && !r.roles?.map((w) => w.id).includes("admin") && m.length === 1)
|
912
901
|
throw new Error("There must be at least one admin");
|
913
902
|
return !0;
|
914
903
|
}
|
915
|
-
function
|
904
|
+
function rn({
|
916
905
|
open: t,
|
917
906
|
user: r,
|
918
907
|
handleClose: n
|
@@ -921,23 +910,23 @@ function tn({
|
|
921
910
|
user: i
|
922
911
|
} = ae(), {
|
923
912
|
saveUser: m,
|
924
|
-
users:
|
913
|
+
users: g,
|
925
914
|
roles: v
|
926
915
|
} = j(), R = !r, w = k((h) => {
|
927
916
|
if (!i)
|
928
917
|
throw new Error("Logged user not found");
|
929
918
|
try {
|
930
|
-
return
|
919
|
+
return tn(i, h, g, v, r), m(h);
|
931
920
|
} catch (x) {
|
932
921
|
return Promise.reject(x);
|
933
922
|
}
|
934
|
-
}, [v, m, r,
|
923
|
+
}, [v, m, r, g, i]), c = Re({
|
935
924
|
initialValues: r ?? {
|
936
925
|
displayName: "",
|
937
926
|
email: "",
|
938
927
|
roles: v.filter((h) => h.id === "editor")
|
939
928
|
},
|
940
|
-
validation: (h) =>
|
929
|
+
validation: (h) => nn.validate(h, { abortEarly: !1 }).then(() => ({})).catch((x) => x.inner.reduce((D, T) => (D[T.path] = T.message, D), {})),
|
941
930
|
onSubmit: (h, x) => w(h).then(() => {
|
942
931
|
n(), x.resetForm({
|
943
932
|
values: h
|
@@ -949,7 +938,7 @@ function tn({
|
|
949
938
|
});
|
950
939
|
})
|
951
940
|
}), {
|
952
|
-
isSubmitting:
|
941
|
+
isSubmitting: E,
|
953
942
|
touched: U,
|
954
943
|
handleChange: a,
|
955
944
|
values: C,
|
@@ -984,7 +973,7 @@ function tn({
|
|
984
973
|
{
|
985
974
|
className: "flex flex-row pt-4 pb-4",
|
986
975
|
children: /* @__PURE__ */ e(
|
987
|
-
|
976
|
+
P,
|
988
977
|
{
|
989
978
|
variant: "h4",
|
990
979
|
className: "flex-grow",
|
@@ -1025,7 +1014,7 @@ function tn({
|
|
1025
1014
|
/* @__PURE__ */ e(B, { children: u > 0 && y.email ? y.email : "Email of this user" })
|
1026
1015
|
] }),
|
1027
1016
|
/* @__PURE__ */ e("div", { className: "col-span-12", children: /* @__PURE__ */ e(
|
1028
|
-
|
1017
|
+
Le,
|
1029
1018
|
{
|
1030
1019
|
label: "Roles",
|
1031
1020
|
value: C.roles?.map((h) => h.id) ?? [],
|
@@ -1035,7 +1024,7 @@ function tn({
|
|
1035
1024
|
return x ? /* @__PURE__ */ e("div", { className: "flex flex-wrap space-x-2 space-y-2", children: /* @__PURE__ */ e(X, { role: x }, x?.id) }) : null;
|
1036
1025
|
},
|
1037
1026
|
children: v.map((h) => /* @__PURE__ */ e(
|
1038
|
-
|
1027
|
+
Be,
|
1039
1028
|
{
|
1040
1029
|
value: h.id,
|
1041
1030
|
children: /* @__PURE__ */ e(X, { role: h }, h?.id)
|
@@ -1064,7 +1053,7 @@ function tn({
|
|
1064
1053
|
color: "primary",
|
1065
1054
|
type: "submit",
|
1066
1055
|
disabled: !_,
|
1067
|
-
loading:
|
1056
|
+
loading: E,
|
1068
1057
|
startIcon: /* @__PURE__ */ e(we, {}),
|
1069
1058
|
children: R ? "Create user" : "Update"
|
1070
1059
|
}
|
@@ -1076,12 +1065,12 @@ function tn({
|
|
1076
1065
|
}
|
1077
1066
|
);
|
1078
1067
|
}
|
1079
|
-
function
|
1068
|
+
function on({ onUserClicked: t }) {
|
1080
1069
|
const {
|
1081
1070
|
users: r,
|
1082
1071
|
saveUser: n,
|
1083
1072
|
deleteUser: l
|
1084
|
-
} = j(), i = ae(), m = se(),
|
1073
|
+
} = j(), i = ae(), m = se(), g = Me(), v = g?.locale ? qe[g?.locale] : void 0, R = g?.dateTimeFormat ?? Oe, [w, c] = A(void 0), [E, U] = A(!1);
|
1085
1074
|
return /* @__PURE__ */ s("div", { className: "overflow-auto", children: [
|
1086
1075
|
/* @__PURE__ */ s(re, { children: [
|
1087
1076
|
/* @__PURE__ */ s(ie, { children: [
|
@@ -1094,7 +1083,7 @@ function rn({ onUserClicked: t }) {
|
|
1094
1083
|
] }),
|
1095
1084
|
/* @__PURE__ */ s(oe, { children: [
|
1096
1085
|
r && r.map((a) => {
|
1097
|
-
const C = a.roles, y = a.created_on ?
|
1086
|
+
const C = a.roles, y = a.created_on ? $e(a.created_on, R, { locale: v }) : "";
|
1098
1087
|
return /* @__PURE__ */ s(
|
1099
1088
|
W,
|
1100
1089
|
{
|
@@ -1123,7 +1112,7 @@ function rn({ onUserClicked: t }) {
|
|
1123
1112
|
);
|
1124
1113
|
}),
|
1125
1114
|
(!r || r.length === 0) && /* @__PURE__ */ e(W, { children: /* @__PURE__ */ e(d, { colspan: 6, children: /* @__PURE__ */ s(Ne, { className: "flex flex-col gap-4 my-8 items-center", children: [
|
1126
|
-
/* @__PURE__ */ e(
|
1115
|
+
/* @__PURE__ */ e(P, { variant: "label", children: "There are no users yet" }),
|
1127
1116
|
/* @__PURE__ */ e(
|
1128
1117
|
O,
|
1129
1118
|
{
|
@@ -1162,7 +1151,7 @@ function rn({ onUserClicked: t }) {
|
|
1162
1151
|
xe,
|
1163
1152
|
{
|
1164
1153
|
open: !!w,
|
1165
|
-
loading:
|
1154
|
+
loading: E,
|
1166
1155
|
onAccept: () => {
|
1167
1156
|
w && (U(!0), l(w).then(() => {
|
1168
1157
|
c(void 0);
|
@@ -1184,9 +1173,9 @@ function rn({ onUserClicked: t }) {
|
|
1184
1173
|
)
|
1185
1174
|
] });
|
1186
1175
|
}
|
1187
|
-
const
|
1188
|
-
const [n, l] =
|
1189
|
-
m(
|
1176
|
+
const ln = function({ children: r }) {
|
1177
|
+
const [n, l] = A(), [i, m] = A(), { users: g, usersLimit: v } = j(), R = v !== void 0 && g && g.length >= v, w = k((E) => {
|
1178
|
+
m(E), l(!0);
|
1190
1179
|
}, []), c = k(() => {
|
1191
1180
|
l(!1), m(void 0);
|
1192
1181
|
}, []);
|
@@ -1198,7 +1187,7 @@ const on = function({ children: r }) {
|
|
1198
1187
|
className: "flex items-center mt-12",
|
1199
1188
|
children: [
|
1200
1189
|
/* @__PURE__ */ e(
|
1201
|
-
|
1190
|
+
P,
|
1202
1191
|
{
|
1203
1192
|
gutterBottom: !0,
|
1204
1193
|
variant: "h4",
|
@@ -1220,9 +1209,9 @@ const on = function({ children: r }) {
|
|
1220
1209
|
]
|
1221
1210
|
}
|
1222
1211
|
),
|
1223
|
-
/* @__PURE__ */ e(
|
1212
|
+
/* @__PURE__ */ e(on, { onUserClicked: w }),
|
1224
1213
|
/* @__PURE__ */ e(
|
1225
|
-
|
1214
|
+
rn,
|
1226
1215
|
{
|
1227
1216
|
open: n ?? !1,
|
1228
1217
|
user: i,
|
@@ -1232,14 +1221,14 @@ const on = function({ children: r }) {
|
|
1232
1221
|
)
|
1233
1222
|
] });
|
1234
1223
|
};
|
1235
|
-
function
|
1224
|
+
function Un({ userManagement: t }) {
|
1236
1225
|
const r = t.users.length === 0, n = t.roles.length === 0;
|
1237
1226
|
return {
|
1238
1227
|
key: "user_management",
|
1239
1228
|
loading: t.loading,
|
1240
1229
|
homePage: {
|
1241
1230
|
additionalChildrenStart: r || n ? /* @__PURE__ */ e(
|
1242
|
-
|
1231
|
+
sn,
|
1243
1232
|
{
|
1244
1233
|
noUsers: r,
|
1245
1234
|
noRoles: n,
|
@@ -1248,14 +1237,14 @@ function Nn({ userManagement: t }) {
|
|
1248
1237
|
) : void 0
|
1249
1238
|
},
|
1250
1239
|
provider: {
|
1251
|
-
Component:
|
1240
|
+
Component: Ke,
|
1252
1241
|
props: {
|
1253
1242
|
userManagement: t
|
1254
1243
|
}
|
1255
1244
|
}
|
1256
1245
|
};
|
1257
1246
|
}
|
1258
|
-
function
|
1247
|
+
function sn({
|
1259
1248
|
noUsers: t,
|
1260
1249
|
noRoles: r,
|
1261
1250
|
userManagement: n
|
@@ -1266,8 +1255,8 @@ function ln({
|
|
1266
1255
|
{
|
1267
1256
|
className: "my-4 flex flex-col px-4 py-6 bg-white dark:bg-slate-800 gap-2",
|
1268
1257
|
children: [
|
1269
|
-
/* @__PURE__ */ e(
|
1270
|
-
/* @__PURE__ */ e(
|
1258
|
+
/* @__PURE__ */ e(P, { variant: "subtitle2", className: "uppercase", children: "Create your users and roles" }),
|
1259
|
+
/* @__PURE__ */ e(P, { children: "You have no users or roles defined. You can create default roles and add the current user as admin." }),
|
1271
1260
|
/* @__PURE__ */ s(O, { onClick: () => {
|
1272
1261
|
if (!l.user?.uid)
|
1273
1262
|
throw Error("UsersTable, authController misconfiguration");
|
@@ -1288,13 +1277,13 @@ function ln({
|
|
1288
1277
|
type: "success",
|
1289
1278
|
message: "User added successfully"
|
1290
1279
|
});
|
1291
|
-
}).catch((
|
1280
|
+
}).catch((g) => {
|
1292
1281
|
i.open({
|
1293
1282
|
type: "error",
|
1294
|
-
message: "Error adding user: " +
|
1283
|
+
message: "Error adding user: " + g.message
|
1295
1284
|
});
|
1296
|
-
}), r && Se.forEach((
|
1297
|
-
n.saveRole(
|
1285
|
+
}), r && Se.forEach((g) => {
|
1286
|
+
n.saveRole(g);
|
1298
1287
|
});
|
1299
1288
|
}, children: [
|
1300
1289
|
/* @__PURE__ */ e(le, {}),
|
@@ -1304,47 +1293,47 @@ function ln({
|
|
1304
1293
|
}
|
1305
1294
|
);
|
1306
1295
|
}
|
1307
|
-
const
|
1296
|
+
const xn = [
|
1308
1297
|
{
|
1309
1298
|
path: "users",
|
1310
1299
|
name: "CMS Users",
|
1311
1300
|
group: "Admin",
|
1312
1301
|
icon: "face",
|
1313
|
-
view: /* @__PURE__ */ e(
|
1302
|
+
view: /* @__PURE__ */ e(ln, {})
|
1314
1303
|
},
|
1315
1304
|
{
|
1316
1305
|
path: "roles",
|
1317
1306
|
name: "Roles",
|
1318
1307
|
group: "Admin",
|
1319
1308
|
icon: "gpp_good",
|
1320
|
-
view: /* @__PURE__ */ e(
|
1309
|
+
view: /* @__PURE__ */ e(en, {})
|
1321
1310
|
}
|
1322
1311
|
];
|
1323
1312
|
export {
|
1324
|
-
|
1325
|
-
|
1313
|
+
sn as IntroWidget,
|
1314
|
+
gn as RESERVED_GROUPS,
|
1326
1315
|
X as RoleChip,
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1316
|
+
Qe as RoleYupSchema,
|
1317
|
+
Xe as RolesDetailsForm,
|
1318
|
+
Ze as RolesTable,
|
1319
|
+
en as RolesView,
|
1320
|
+
rn as UserDetailsForm,
|
1332
1321
|
Ee as UserManagementContext,
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1322
|
+
Ke as UserManagementProvider,
|
1323
|
+
nn as UserYupSchema,
|
1324
|
+
on as UsersTable,
|
1325
|
+
ln as UsersView,
|
1326
|
+
ze as areRolesEqual,
|
1327
|
+
Cn as cacheDelegatedLoginToken,
|
1328
|
+
wn as clearDelegatedLoginTokensCache,
|
1329
|
+
yn as darkenColor,
|
1330
|
+
vn as getDelegatedLoginTokenFromCache,
|
1331
|
+
pn as getUserRoles,
|
1332
|
+
bn as hexToRgbaWithOpacity,
|
1333
|
+
We as resolveUserRolePermissions,
|
1334
|
+
Nn as useFirestoreUserManagement,
|
1346
1335
|
j as useUserManagement,
|
1347
|
-
|
1348
|
-
|
1336
|
+
Un as useUserManagementPlugin,
|
1337
|
+
xn as userManagementAdminViews
|
1349
1338
|
};
|
1350
1339
|
//# sourceMappingURL=index.es.js.map
|