@firecms/user_management 3.0.0-canary.8 → 3.0.0-canary.80

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.
Files changed (43) hide show
  1. package/LICENSE +113 -21
  2. package/dist/UserManagementProvider.d.ts +4 -3
  3. package/dist/components/roles/RoleChip.d.ts +1 -1
  4. package/dist/components/roles/RolesDetailsForm.d.ts +1 -2
  5. package/dist/components/roles/RolesTable.d.ts +1 -1
  6. package/dist/components/roles/default_roles.d.ts +1 -1
  7. package/dist/components/users/UserDetailsForm.d.ts +2 -2
  8. package/dist/components/users/UsersTable.d.ts +2 -2
  9. package/dist/hooks/index.d.ts +1 -1
  10. package/dist/hooks/{useBuildFirestoreUserManagement.d.ts → useFirestoreUserManagement.d.ts} +8 -4
  11. package/dist/hooks/useUserManagement.d.ts +3 -2
  12. package/dist/index.es.js +569 -493
  13. package/dist/index.es.js.map +1 -1
  14. package/dist/index.umd.js +1 -1
  15. package/dist/index.umd.js.map +1 -1
  16. package/dist/types/index.d.ts +1 -2
  17. package/dist/types/persisted_user.d.ts +5 -0
  18. package/dist/types/user_management.d.ts +18 -10
  19. package/dist/useUserManagementPlugin.d.ts +6 -1
  20. package/dist/utils/permissions.d.ts +3 -4
  21. package/package.json +14 -31
  22. package/src/UserManagementProvider.tsx +4 -3
  23. package/src/components/roles/RoleChip.tsx +1 -1
  24. package/src/components/roles/RolesDetailsForm.tsx +1 -2
  25. package/src/components/roles/RolesTable.tsx +1 -2
  26. package/src/components/roles/RolesView.tsx +1 -2
  27. package/src/components/roles/default_roles.tsx +1 -1
  28. package/src/components/users/UserDetailsForm.tsx +14 -13
  29. package/src/components/users/UsersTable.tsx +6 -6
  30. package/src/components/users/UsersView.tsx +3 -3
  31. package/src/hooks/index.ts +1 -1
  32. package/src/hooks/{useBuildFirestoreUserManagement.tsx → useFirestoreUserManagement.tsx} +92 -56
  33. package/src/hooks/useUserManagement.tsx +3 -3
  34. package/src/types/index.ts +1 -2
  35. package/src/types/persisted_user.ts +6 -0
  36. package/src/types/user_management.tsx +22 -11
  37. package/src/useUserManagementPlugin.tsx +89 -3
  38. package/src/utils/permissions.ts +7 -5
  39. package/dist/types/firecms_user.d.ts +0 -7
  40. package/dist/types/roles.d.ts +0 -31
  41. package/src/types/firecms_user.ts +0 -8
  42. package/src/types/roles.ts +0 -41
  43. package/tailwind.config.js +0 -68
@@ -1,13 +1,28 @@
1
- import { AuthController, FireCMSPlugin } from "@firecms/core";
1
+ import { FireCMSPlugin, useAuthController, useSnackbarController } from "@firecms/core";
2
2
  import { UserManagementProvider } from "./UserManagementProvider";
3
- import { UserManagement } from "./types";
3
+ import { PersistedUser, UserManagement } from "./types";
4
+ import { AddIcon, Button, Paper, Typography } from "@firecms/ui";
5
+ import { DEFAULT_ROLES } from "./components/roles/default_roles";
4
6
 
5
7
  export function useUserManagementPlugin({ userManagement }: {
6
8
  userManagement: UserManagement,
7
9
  }): FireCMSPlugin {
10
+
11
+ const noUsers = userManagement.users.length === 0;
12
+ const noRoles = userManagement.roles.length === 0;
13
+
8
14
  return {
9
- name: "User management plugin",
15
+ key: "user_management",
10
16
  loading: userManagement.loading,
17
+
18
+ homePage: {
19
+ additionalChildrenStart: noUsers || noRoles
20
+ ? <IntroWidget
21
+ noUsers={noUsers}
22
+ noRoles={noRoles}
23
+ userManagement={userManagement}/>
24
+ : undefined
25
+ },
11
26
  provider: {
12
27
  Component: UserManagementProvider,
13
28
  props: {
@@ -16,3 +31,74 @@ export function useUserManagementPlugin({ userManagement }: {
16
31
  }
17
32
  }
18
33
  }
34
+
35
+ export function IntroWidget({
36
+ noUsers,
37
+ noRoles,
38
+ userManagement
39
+ }: {
40
+ noUsers: boolean;
41
+ noRoles: boolean;
42
+ userManagement: UserManagement<PersistedUser>;
43
+ }) {
44
+
45
+ const authController = useAuthController();
46
+ const snackbarController = useSnackbarController();
47
+
48
+ const buttonLabel = noUsers && noRoles
49
+ ? "Create default roles and add current user as admin"
50
+ : noUsers
51
+ ? "Add current user as admin"
52
+ : noRoles ? "Create default roles" : undefined;
53
+
54
+ return (
55
+ <Paper
56
+ className={"my-4 flex flex-col px-4 py-6 bg-white dark:bg-slate-800 gap-2"}>
57
+ <Typography variant={"subtitle2"} className={"uppercase"}>Create your users and roles</Typography>
58
+ <Typography>
59
+ You have no users or roles defined. You can create default roles and add the current user as admin.
60
+ </Typography>
61
+ <Button onClick={() => {
62
+ if (!authController.user?.uid) {
63
+ throw Error("UsersTable, authController misconfiguration");
64
+ }
65
+ if (noUsers) {
66
+ userManagement.saveUser({
67
+ uid: authController.user?.uid,
68
+ email: authController.user?.email,
69
+ displayName: authController.user?.displayName,
70
+ photoURL: authController.user?.photoURL,
71
+ providerId: authController.user?.providerId,
72
+ isAnonymous: authController.user?.isAnonymous,
73
+ roles: [{
74
+ id: "admin",
75
+ name: "Admin"
76
+ }],
77
+ created_on: new Date()
78
+ })
79
+ .then(() => {
80
+ snackbarController.open({
81
+ type: "success",
82
+ message: "User added successfully"
83
+ })
84
+ })
85
+ .catch((error) => {
86
+ snackbarController.open({
87
+ type: "error",
88
+ message: "Error adding user: " + error.message
89
+ })
90
+ });
91
+ }
92
+ if (noRoles) {
93
+ DEFAULT_ROLES.forEach((role) => {
94
+ userManagement.saveRole(role);
95
+ });
96
+ }
97
+ }}>
98
+ <AddIcon/>
99
+ {buttonLabel}
100
+ </Button>
101
+ </Paper>
102
+ );
103
+
104
+ }
@@ -1,5 +1,4 @@
1
- import { CMSType, EntityCollection, Permissions } from "@firecms/core";
2
- import { Role, UserWithRoles } from "../types";
1
+ import { EntityCollection, Permissions, Role, User } from "@firecms/core";
3
2
 
4
3
  export const RESERVED_GROUPS = ["Admin"];
5
4
 
@@ -10,8 +9,11 @@ const DEFAULT_PERMISSIONS = {
10
9
  delete: false
11
10
  };
12
11
 
13
- export function resolveUserRolePermissions<UserType extends UserWithRoles>
14
- ({ collection, user }: {
12
+ export function resolveUserRolePermissions<UserType extends User>
13
+ ({
14
+ collection,
15
+ user
16
+ }: {
15
17
  collection: EntityCollection<any>,
16
18
  user: UserType | null
17
19
  }): Permissions {
@@ -66,7 +68,7 @@ const mergePermissions = (permA: Permissions, permB: Permissions) => {
66
68
  };
67
69
  }
68
70
 
69
- export function getUserRoles(roles: Role[], fireCMSUser: UserWithRoles): Role[] | undefined {
71
+ export function getUserRoles(roles: Role[], fireCMSUser: User): Role[] | undefined {
70
72
  return !roles
71
73
  ? undefined
72
74
  : (fireCMSUser.roles
@@ -1,7 +0,0 @@
1
- import { User } from "@firecms/core";
2
- import { Role } from "./roles";
3
- export type UserWithRoles = User & {
4
- updated_on?: Date;
5
- created_on?: Date;
6
- roles: Role[];
7
- };
@@ -1,31 +0,0 @@
1
- import { Permissions } from "@firecms/core";
2
- export type Role = {
3
- /**
4
- * ID of the role
5
- */
6
- id: string;
7
- /**
8
- * Name of the role
9
- */
10
- name: string;
11
- /**
12
- * If this flag is true, the user can perform any action
13
- */
14
- isAdmin?: boolean;
15
- /**
16
- * Default permissions for all collections for this role.
17
- * You can override this values at the collection level using
18
- * {@link collectionPermissions}
19
- */
20
- defaultPermissions?: Permissions;
21
- /**
22
- * Record of stripped collection ids to their permissions.
23
- * @see stripCollectionPath
24
- */
25
- collectionPermissions?: Record<string, Permissions>;
26
- config?: {
27
- createCollections?: boolean;
28
- editCollections?: boolean | "own";
29
- deleteCollections?: boolean | "own";
30
- };
31
- };
@@ -1,8 +0,0 @@
1
- import { User } from "@firecms/core";
2
- import { Role } from "./roles";
3
-
4
- export type UserWithRoles = User & {
5
- updated_on?: Date;
6
- created_on?: Date;
7
- roles: Role[];
8
- }
@@ -1,41 +0,0 @@
1
- import { Permissions } from "@firecms/core";
2
-
3
- export type Role = {
4
-
5
- /**
6
- * ID of the role
7
- */
8
- id: string;
9
-
10
- /**
11
- * Name of the role
12
- */
13
- name: string;
14
-
15
- /**
16
- * If this flag is true, the user can perform any action
17
- */
18
- isAdmin?: boolean;
19
-
20
- /**
21
- * Default permissions for all collections for this role.
22
- * You can override this values at the collection level using
23
- * {@link collectionPermissions}
24
- */
25
- defaultPermissions?: Permissions;
26
-
27
- /**
28
- * Record of stripped collection ids to their permissions.
29
- * @see stripCollectionPath
30
- */
31
- collectionPermissions?: Record<string, Permissions>;
32
-
33
- config?: {
34
-
35
- createCollections?: boolean;
36
-
37
- editCollections?: boolean | "own";
38
-
39
- deleteCollections?: boolean | "own";
40
- }
41
- }
@@ -1,68 +0,0 @@
1
- export default {
2
- darkMode: ["selector", "[data-theme=\"dark\"]"],
3
- mode: "jit",
4
- content: [
5
- "./index.html",
6
- "./src/**/*.{js,ts,jsx,tsx}",
7
- "./node_modules/firecms/src/**/*.{js,ts,jsx,tsx}",
8
- "./node_modules/@firecms/**/src/**/*.{js,ts,jsx,tsx}"
9
- ],
10
- theme: {
11
- extend: {
12
- fontFamily: {
13
- sans: [
14
- "Rubik",
15
- "Roboto",
16
- "Helvetica",
17
- "Arial",
18
- "sans-serif"
19
- ],
20
- headers: [
21
- "Rubik",
22
- "Roboto",
23
- "Helvetica",
24
- "Arial",
25
- "sans-serif"
26
- ],
27
- mono: [
28
- "IBM Plex Mono",
29
- "Space Mono",
30
- "Lucida Console",
31
- "monospace"
32
- ]
33
- },
34
- colors: {
35
- primary: "var(--fcms-primary)",
36
- "primary-dark": "var(--fcms-primary-dark)",
37
- "primary-bg": "var(--fcms-primary-bg)",
38
- secondary: "var(--fcms-secondary)",
39
- field: {
40
- disabled: "rgb(224 224 226)",
41
- "disabled-dark": "rgb(35 35 37)"
42
- },
43
- text: {
44
- primary: "rgba(0, 0, 0, 0.87)",
45
- "primary-dark": "#ffffff",
46
- secondary: "rgba(0, 0, 0, 0.6)",
47
- "secondary-dark": "rgba(255, 255, 255, 0.7)",
48
- disabled: "rgba(0, 0, 0, 0.38)",
49
- "disabled-dark": "rgba(255, 255, 255, 0.5)",
50
- label: "rgb(131, 131, 131)"
51
- },
52
- gray: {
53
- 50: "#f8f8fc",
54
- 100: "#E7E7EB",
55
- 200: "#CFCFD6",
56
- 300: "#B7B7BF",
57
- 400: "#A0A0A9",
58
- 500: "#87878F",
59
- 600: "#6C6C75",
60
- 700: "#505058",
61
- 800: "#35353A",
62
- 900: "#18181C",
63
- 950: "#101013"
64
- }
65
- }
66
- }
67
- }
68
- };