@mapomodule/core 1.0.0-alpha.39 → 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 CHANGED
@@ -3,6 +3,25 @@
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
+
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)
18
+
19
+ **Note:** Version bump only for package @mapomodule/core
20
+
21
+
22
+
23
+
24
+
6
25
  # [1.0.0-alpha.39](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.38...v1.0.0-alpha.39) (2022-12-03)
7
26
 
8
27
 
@@ -1,19 +1,36 @@
1
- import Middleware from '../../middleware' // little hack to inject middleware in root project :P
1
+ import Middleware from "../../middleware"; // little hack to inject middleware in root project :P
2
2
 
3
- Middleware.permissions = Middleware.permissions || async function ({ route, error, store }) {
4
- route.meta = Array.isArray(route.meta) ? route.meta[0] : route.meta
5
- if (!route.meta.permissions) return
6
- const userInfo = store.getters['mapo/user/info']
7
- if (userInfo.is_superuser) {
8
- await store.dispatch('mapo/user/addPagePermission', {key: route.name, value: ["add", "change", "delete", "view"]})
9
- return
10
- }
11
- const { model } = route.meta.permissions
12
- const userPermission = (userInfo.user_permissions || []).filter(perm => perm.codename.endsWith(model)).map(({ codename }) => codename.replace(`_${model}`, ''))
13
- if (!userPermission.includes('view')) {
14
- return error({ statusCode: 404, message: 'This page could not be found' })
15
- } else {
16
- await store.dispatch('mapo/user/addPagePermission', {key: route.name, value: userPermission})
17
- return
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.39",
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": [
@@ -13,10 +13,10 @@
13
13
  "repository": "https://github.com/lotrekagency/mapo",
14
14
  "main": "./module.js",
15
15
  "dependencies": {
16
- "@mapomodule/utils": "^1.0.0-alpha.34"
16
+ "@mapomodule/utils": "^1.0.0-alpha.40"
17
17
  },
18
18
  "publishConfig": {
19
19
  "access": "public"
20
20
  },
21
- "gitHead": "11018687c8ee01a219dadc2f770c9f6b09be9f49"
21
+ "gitHead": "9f6bc45ab0ae3b56ed6fa98597c80808efced174"
22
22
  }