@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.
- package/LICENSE +113 -21
- package/dist/UserManagementProvider.d.ts +4 -3
- package/dist/components/roles/RoleChip.d.ts +1 -1
- package/dist/components/roles/RolesDetailsForm.d.ts +1 -2
- package/dist/components/roles/RolesTable.d.ts +1 -1
- package/dist/components/roles/default_roles.d.ts +1 -1
- package/dist/components/users/UserDetailsForm.d.ts +2 -2
- package/dist/components/users/UsersTable.d.ts +2 -2
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/{useBuildFirestoreUserManagement.d.ts → useFirestoreUserManagement.d.ts} +8 -4
- package/dist/hooks/useUserManagement.d.ts +3 -2
- package/dist/index.es.js +569 -493
- 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/index.d.ts +1 -2
- package/dist/types/persisted_user.d.ts +5 -0
- package/dist/types/user_management.d.ts +18 -10
- package/dist/useUserManagementPlugin.d.ts +6 -1
- package/dist/utils/permissions.d.ts +3 -4
- package/package.json +14 -31
- package/src/UserManagementProvider.tsx +4 -3
- package/src/components/roles/RoleChip.tsx +1 -1
- package/src/components/roles/RolesDetailsForm.tsx +1 -2
- package/src/components/roles/RolesTable.tsx +1 -2
- package/src/components/roles/RolesView.tsx +1 -2
- package/src/components/roles/default_roles.tsx +1 -1
- package/src/components/users/UserDetailsForm.tsx +14 -13
- package/src/components/users/UsersTable.tsx +6 -6
- package/src/components/users/UsersView.tsx +3 -3
- package/src/hooks/index.ts +1 -1
- package/src/hooks/{useBuildFirestoreUserManagement.tsx → useFirestoreUserManagement.tsx} +92 -56
- package/src/hooks/useUserManagement.tsx +3 -3
- package/src/types/index.ts +1 -2
- package/src/types/persisted_user.ts +6 -0
- package/src/types/user_management.tsx +22 -11
- package/src/useUserManagementPlugin.tsx +89 -3
- package/src/utils/permissions.ts +7 -5
- package/dist/types/firecms_user.d.ts +0 -7
- package/dist/types/roles.d.ts +0 -31
- package/src/types/firecms_user.ts +0 -8
- package/src/types/roles.ts +0 -41
- package/tailwind.config.js +0 -68
@@ -1,13 +1,28 @@
|
|
1
|
-
import {
|
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
|
-
|
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
|
+
}
|
package/src/utils/permissions.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import {
|
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
|
14
|
-
({
|
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:
|
71
|
+
export function getUserRoles(roles: Role[], fireCMSUser: User): Role[] | undefined {
|
70
72
|
return !roles
|
71
73
|
? undefined
|
72
74
|
: (fireCMSUser.roles
|
package/dist/types/roles.d.ts
DELETED
@@ -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
|
-
};
|
package/src/types/roles.ts
DELETED
@@ -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
|
-
}
|
package/tailwind.config.js
DELETED
@@ -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
|
-
};
|