@eeplatform/nuxt-layer-common 1.7.47 → 1.7.49
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/CHANGELOG.md +12 -0
- package/components/Layout/Header.vue +5 -5
- package/components/ListGroupSelection.vue +134 -0
- package/components/RoleForm.vue +327 -0
- package/components/RolePermissionMain.vue +131 -199
- package/composables/useApps.ts +58 -0
- package/composables/useLocal.ts +1 -1
- package/composables/useLocalAuth.ts +15 -0
- package/composables/useMember.ts +63 -33
- package/composables/usePermission.ts +97 -0
- package/composables/useRole.ts +24 -37
- package/middleware/02.member.ts +8 -4
- package/middleware/03.role.ts +4 -2
- package/package.json +1 -1
- package/plugins/secure-member.client.ts +2 -2
- package/types/local.d.ts +8 -4
- package/types/member.d.ts +9 -0
- package/types/permission.d.ts +24 -0
- package/types/role.d.ts +3 -2
|
@@ -47,8 +47,105 @@ export default function usePermission() {
|
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
const perm = ref<TPerm>({
|
|
51
|
+
app: "",
|
|
52
|
+
key: "",
|
|
53
|
+
name: "",
|
|
54
|
+
group: "",
|
|
55
|
+
description: "",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
function addPerm(value: TPerm) {
|
|
59
|
+
return useNuxtApp().$api("/api/permissions", {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: value,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function updatePermById(
|
|
66
|
+
id: string,
|
|
67
|
+
value: Pick<TPerm, "key" | "name" | "group" | "description">
|
|
68
|
+
) {
|
|
69
|
+
return useNuxtApp().$api(`/api/permissions/id/${id}`, {
|
|
70
|
+
method: "PATCH",
|
|
71
|
+
body: value,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getAllPerm({
|
|
76
|
+
page = 1,
|
|
77
|
+
limit = 10,
|
|
78
|
+
search = "",
|
|
79
|
+
app = "",
|
|
80
|
+
status = "active",
|
|
81
|
+
} = {}) {
|
|
82
|
+
return useNuxtApp().$api<Record<string, any>>("/api/permissions", {
|
|
83
|
+
method: "GET",
|
|
84
|
+
query: { page, limit, search, app, status },
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function deletePermById(id: string) {
|
|
89
|
+
return useNuxtApp().$api(`/api/permissions/id/${id}`, {
|
|
90
|
+
method: "DELETE",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const permGroup = ref<TPermGroup>({
|
|
95
|
+
app: "",
|
|
96
|
+
key: "",
|
|
97
|
+
label: "",
|
|
98
|
+
order: 0,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
function addPermGroup(value: Pick<TPermGroup, "app" | "key" | "label">) {
|
|
102
|
+
return useNuxtApp().$api("/api/permissions/groups", {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: value,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function updatePermGroupById(
|
|
109
|
+
id: string,
|
|
110
|
+
value: Pick<TPermGroup, "key" | "label">
|
|
111
|
+
) {
|
|
112
|
+
return useNuxtApp().$api(`/api/permissions/groups/id/${id}`, {
|
|
113
|
+
method: "PATCH",
|
|
114
|
+
body: value,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function getAllPermGroup({
|
|
119
|
+
page = 1,
|
|
120
|
+
limit = 10,
|
|
121
|
+
search = "",
|
|
122
|
+
app = "",
|
|
123
|
+
status = "active",
|
|
124
|
+
} = {}) {
|
|
125
|
+
return useNuxtApp().$api<Record<string, any>>("/api/permissions/groups", {
|
|
126
|
+
method: "GET",
|
|
127
|
+
query: { page, limit, search, app, status },
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function deletePermGroupById(id: string) {
|
|
132
|
+
return useNuxtApp().$api(`/api/permissions/groups/id/${id}`, {
|
|
133
|
+
method: "DELETE",
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
50
137
|
return {
|
|
51
138
|
listPermissions,
|
|
52
139
|
hasPermission,
|
|
140
|
+
perm,
|
|
141
|
+
addPerm,
|
|
142
|
+
updatePermById,
|
|
143
|
+
getAllPerm,
|
|
144
|
+
deletePermById,
|
|
145
|
+
permGroup,
|
|
146
|
+
addPermGroup,
|
|
147
|
+
updatePermGroupById,
|
|
148
|
+
getAllPermGroup,
|
|
149
|
+
deletePermGroupById,
|
|
53
150
|
};
|
|
54
151
|
}
|
package/composables/useRole.ts
CHANGED
|
@@ -1,44 +1,36 @@
|
|
|
1
1
|
export default function useRole() {
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
name: string;
|
|
5
|
-
permissions: Array<string>;
|
|
6
|
-
type: string;
|
|
7
|
-
}
|
|
2
|
+
function add(
|
|
3
|
+
value: Pick<TRole, "name" | "permissions" | "app" | "org" | "createdBy">
|
|
8
4
|
) {
|
|
9
5
|
return useNuxtApp().$api("/api/roles", {
|
|
10
6
|
method: "POST",
|
|
11
|
-
body:
|
|
7
|
+
body: value,
|
|
12
8
|
});
|
|
13
9
|
}
|
|
14
10
|
|
|
15
|
-
function
|
|
11
|
+
function getAll({
|
|
16
12
|
search = "",
|
|
17
13
|
page = 1,
|
|
18
14
|
limit = 20,
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
app = "",
|
|
16
|
+
org = "",
|
|
21
17
|
} = {}) {
|
|
22
18
|
return useNuxtApp().$api<Record<string, any>>("/api/roles", {
|
|
23
19
|
method: "GET",
|
|
24
|
-
query: { search, page, limit,
|
|
20
|
+
query: { search, page, limit, app, org },
|
|
25
21
|
});
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
function
|
|
29
|
-
return useNuxtApp().$api<
|
|
24
|
+
function getById(id: string) {
|
|
25
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/roles/id/${id}`, {
|
|
30
26
|
method: "GET",
|
|
31
27
|
});
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
name?: string,
|
|
37
|
-
permissions?: Array<string>
|
|
38
|
-
) {
|
|
39
|
-
return useNuxtApp().$api(`/api/roles/id/${_id}`, {
|
|
30
|
+
function updateById(id: string, value: Pick<TRole, "name" | "permissions">) {
|
|
31
|
+
return useNuxtApp().$api(`/api/roles/id/${id}`, {
|
|
40
32
|
method: "PATCH",
|
|
41
|
-
body:
|
|
33
|
+
body: value,
|
|
42
34
|
});
|
|
43
35
|
}
|
|
44
36
|
|
|
@@ -56,33 +48,28 @@ export default function useRole() {
|
|
|
56
48
|
});
|
|
57
49
|
}
|
|
58
50
|
|
|
59
|
-
function
|
|
51
|
+
function deleteById(_id: string) {
|
|
60
52
|
return useNuxtApp().$api<Record<string, any>>(`/api/roles/${_id}`, {
|
|
61
53
|
method: "DELETE",
|
|
62
54
|
});
|
|
63
55
|
}
|
|
64
56
|
|
|
65
|
-
const role =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
createdAt: "",
|
|
72
|
-
updatedAt: "",
|
|
73
|
-
deletedAt: "",
|
|
74
|
-
default: false,
|
|
75
|
-
};
|
|
57
|
+
const role = ref<TRole>({
|
|
58
|
+
name: "",
|
|
59
|
+
org: "",
|
|
60
|
+
permissions: [],
|
|
61
|
+
app: "",
|
|
62
|
+
description: "",
|
|
76
63
|
});
|
|
77
64
|
|
|
78
65
|
return {
|
|
79
66
|
role,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
add,
|
|
68
|
+
getAll,
|
|
69
|
+
getById,
|
|
70
|
+
updateById,
|
|
84
71
|
updateRoleFieldById,
|
|
85
|
-
|
|
72
|
+
deleteById,
|
|
86
73
|
updatePermissionById,
|
|
87
74
|
};
|
|
88
75
|
}
|
package/middleware/02.member.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
export default defineNuxtRouteMiddleware(async () => {
|
|
1
|
+
export default defineNuxtRouteMiddleware(async (to) => {
|
|
2
2
|
// Ensure middleware runs only on the client side
|
|
3
3
|
if (import.meta.server) return;
|
|
4
4
|
|
|
5
5
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
6
|
+
const APP = useRuntimeConfig().public.APP;
|
|
7
|
+
const org = (to.params.org as string) ?? "";
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
console.log(APP);
|
|
8
10
|
|
|
9
|
-
const {
|
|
11
|
+
const { loggedInUser } = useLocalAuth();
|
|
12
|
+
|
|
13
|
+
const { getByApp } = useMember();
|
|
10
14
|
try {
|
|
11
|
-
const memberData = await
|
|
15
|
+
const memberData = await getByApp({ app: APP, user: loggedInUser(), org });
|
|
12
16
|
if (memberData.role) {
|
|
13
17
|
useCookie("role", cookieConfig).value = memberData.role;
|
|
14
18
|
}
|
package/middleware/03.role.ts
CHANGED
|
@@ -4,7 +4,7 @@ export default defineNuxtRouteMiddleware(async () => {
|
|
|
4
4
|
|
|
5
5
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const { getById } = useRole();
|
|
8
8
|
const role = useCookie("role", cookieConfig).value ?? "";
|
|
9
9
|
if (!role) {
|
|
10
10
|
navigateTo({ name: "require-role" });
|
|
@@ -12,9 +12,11 @@ export default defineNuxtRouteMiddleware(async () => {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const { userAppRole } = useLocalSetup();
|
|
15
|
+
const { permissions } = useLocalAuth();
|
|
15
16
|
|
|
16
17
|
try {
|
|
17
|
-
const roleData = await
|
|
18
|
+
const roleData = await getById(role);
|
|
19
|
+
permissions.value.push(...roleData.permissions);
|
|
18
20
|
userAppRole.value = roleData;
|
|
19
21
|
} catch (error) {
|
|
20
22
|
navigateTo({ name: "require-role" });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export default defineNuxtPlugin(() => {
|
|
2
2
|
const router = useRouter();
|
|
3
3
|
const { getByUserType } = useMember();
|
|
4
|
-
const {
|
|
4
|
+
const { getById } = useRole();
|
|
5
5
|
|
|
6
6
|
const { userAppRole, id } = useLocalSetup();
|
|
7
7
|
|
|
@@ -38,7 +38,7 @@ export default defineNuxtPlugin(() => {
|
|
|
38
38
|
|
|
39
39
|
const { data: getRoleByIdReq } = useLazyAsyncData(
|
|
40
40
|
"get-role-by-id",
|
|
41
|
-
() =>
|
|
41
|
+
() => getById(roleId.value),
|
|
42
42
|
{ watch: [roleId], immediate: false }
|
|
43
43
|
);
|
|
44
44
|
|
package/types/local.d.ts
CHANGED
|
@@ -19,8 +19,12 @@ declare type TNavigationItem = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
declare type TApp = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
_id?: string;
|
|
23
|
+
code: string;
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
status?: string;
|
|
27
|
+
createdAt?: string | Date;
|
|
28
|
+
updatedAt?: string | Date;
|
|
29
|
+
deletedAt?: string | Date;
|
|
26
30
|
};
|
package/types/member.d.ts
CHANGED
|
@@ -5,8 +5,17 @@ declare type TMember = {
|
|
|
5
5
|
name: string;
|
|
6
6
|
user: string;
|
|
7
7
|
role: string;
|
|
8
|
+
roleName?: string;
|
|
8
9
|
status?: string;
|
|
9
10
|
createdAt?: string;
|
|
10
11
|
updatedAt?: string;
|
|
11
12
|
deletedAt?: string;
|
|
12
13
|
};
|
|
14
|
+
|
|
15
|
+
declare type TMemberInvitation = {
|
|
16
|
+
_id?: string;
|
|
17
|
+
email: string;
|
|
18
|
+
app: string;
|
|
19
|
+
org: string;
|
|
20
|
+
role: string;
|
|
21
|
+
};
|
package/types/permission.d.ts
CHANGED
|
@@ -12,3 +12,27 @@ declare type TPermissions = {
|
|
|
12
12
|
[action: string]: TPermission;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
+
|
|
16
|
+
declare type TPerm = {
|
|
17
|
+
_id?: string;
|
|
18
|
+
app: string;
|
|
19
|
+
name: string;
|
|
20
|
+
key: string;
|
|
21
|
+
group: string;
|
|
22
|
+
description: string;
|
|
23
|
+
status?: string;
|
|
24
|
+
createdAt?: string | Date;
|
|
25
|
+
updatedAt?: string | Date;
|
|
26
|
+
deletedAt?: string | Date;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
declare type TPermGroup = {
|
|
30
|
+
_id?: string;
|
|
31
|
+
app: string;
|
|
32
|
+
key: string;
|
|
33
|
+
label: string;
|
|
34
|
+
order: number;
|
|
35
|
+
createdAt?: string | Date;
|
|
36
|
+
updatedAt?: string | Date;
|
|
37
|
+
deletedAt?: string | Date;
|
|
38
|
+
};
|
package/types/role.d.ts
CHANGED