@mapomodule/core 1.0.0-alpha.40 → 1.0.0-alpha.41
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 +11 -0
- package/middleware/permissions.js +35 -18
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-alpha.41](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.40...v1.0.0-alpha.41) (2022-12-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* handle all_permissions prop in user ([14d4252](https://github.com/lotrekagency/mapo/commit/14d425215434e29f82093fc96e53b172bf247b8f))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [1.0.0-alpha.40](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.39...v1.0.0-alpha.40) (2022-12-20)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @mapomodule/core
|
|
@@ -1,19 +1,36 @@
|
|
|
1
|
-
import Middleware from
|
|
1
|
+
import Middleware from "../../middleware"; // little hack to inject middleware in root project :P
|
|
2
2
|
|
|
3
|
-
Middleware.permissions =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
Middleware.permissions =
|
|
4
|
+
Middleware.permissions ||
|
|
5
|
+
async function ({ route, error, store }) {
|
|
6
|
+
route.meta = Array.isArray(route.meta) ? route.meta[0] : route.meta;
|
|
7
|
+
if (!route.meta.permissions) return;
|
|
8
|
+
const userInfo = store.getters["mapo/user/info"];
|
|
9
|
+
if (userInfo.is_superuser) {
|
|
10
|
+
await store.dispatch("mapo/user/addPagePermission", {
|
|
11
|
+
key: route.name,
|
|
12
|
+
value: ["add", "change", "delete", "view"],
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const { model } = route.meta.permissions;
|
|
17
|
+
const userPermission = (
|
|
18
|
+
userInfo.all_permissions ||
|
|
19
|
+
userInfo.user_permissions ||
|
|
20
|
+
[]
|
|
21
|
+
)
|
|
22
|
+
.filter((perm) => perm.codename.endsWith(model))
|
|
23
|
+
.map(({ codename }) => codename.replace(`_${model}`, ""));
|
|
24
|
+
if (!userPermission.includes("view")) {
|
|
25
|
+
return error({
|
|
26
|
+
statusCode: 404,
|
|
27
|
+
message: "This page could not be found",
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
await store.dispatch("mapo/user/addPagePermission", {
|
|
31
|
+
key: route.name,
|
|
32
|
+
value: userPermission,
|
|
33
|
+
});
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapomodule/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.41",
|
|
4
4
|
"description": "This is part of Mapo nuxt module. Injects the core mapo plugin helpers.",
|
|
5
5
|
"author": "bnznamco <gabriele.baldi.01@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "9f6bc45ab0ae3b56ed6fa98597c80808efced174"
|
|
22
22
|
}
|