@mapomodule/core
Advanced tools
Comparing version 1.0.0-alpha.40 to 1.0.0-alpha.41
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.0.0-alpha.41](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.40...v1.0.0-alpha.41) (2022-12-20) | ||
### Features | ||
* handle all_permissions prop in user ([14d4252](https://github.com/lotrekagency/mapo/commit/14d425215434e29f82093fc96e53b172bf247b8f)) | ||
# [1.0.0-alpha.40](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.39...v1.0.0-alpha.40) (2022-12-20) | ||
@@ -8,0 +19,0 @@ |
@@ -1,19 +0,36 @@ | ||
import Middleware from '../../middleware' // little hack to inject middleware in root project :P | ||
import Middleware from "../../middleware"; // little hack to inject middleware in root project :P | ||
Middleware.permissions = Middleware.permissions || async function ({ route, error, store }) { | ||
route.meta = Array.isArray(route.meta) ? route.meta[0] : route.meta | ||
if (!route.meta.permissions) return | ||
const userInfo = store.getters['mapo/user/info'] | ||
if (userInfo.is_superuser) { | ||
await store.dispatch('mapo/user/addPagePermission', {key: route.name, value: ["add", "change", "delete", "view"]}) | ||
return | ||
} | ||
const { model } = route.meta.permissions | ||
const userPermission = (userInfo.user_permissions || []).filter(perm => perm.codename.endsWith(model)).map(({ codename }) => codename.replace(`_${model}`, '')) | ||
if (!userPermission.includes('view')) { | ||
return error({ statusCode: 404, message: 'This page could not be found' }) | ||
} else { | ||
await store.dispatch('mapo/user/addPagePermission', {key: route.name, value: userPermission}) | ||
return | ||
} | ||
} | ||
Middleware.permissions = | ||
Middleware.permissions || | ||
async function ({ route, error, store }) { | ||
route.meta = Array.isArray(route.meta) ? route.meta[0] : route.meta; | ||
if (!route.meta.permissions) return; | ||
const userInfo = store.getters["mapo/user/info"]; | ||
if (userInfo.is_superuser) { | ||
await store.dispatch("mapo/user/addPagePermission", { | ||
key: route.name, | ||
value: ["add", "change", "delete", "view"], | ||
}); | ||
return; | ||
} | ||
const { model } = route.meta.permissions; | ||
const userPermission = ( | ||
userInfo.all_permissions || | ||
userInfo.user_permissions || | ||
[] | ||
) | ||
.filter((perm) => perm.codename.endsWith(model)) | ||
.map(({ codename }) => codename.replace(`_${model}`, "")); | ||
if (!userPermission.includes("view")) { | ||
return error({ | ||
statusCode: 404, | ||
message: "This page could not be found", | ||
}); | ||
} else { | ||
await store.dispatch("mapo/user/addPagePermission", { | ||
key: route.name, | ||
value: userPermission, | ||
}); | ||
return; | ||
} | ||
}; |
{ | ||
"name": "@mapomodule/core", | ||
"version": "1.0.0-alpha.40", | ||
"version": "1.0.0-alpha.41", | ||
"description": "This is part of Mapo nuxt module. Injects the core mapo plugin helpers.", | ||
@@ -21,3 +21,3 @@ "author": "bnznamco <gabriele.baldi.01@gmail.com>", | ||
}, | ||
"gitHead": "918d8d3ed9a6edc9be25e082f9917866e8c73c57" | ||
"gitHead": "9f6bc45ab0ae3b56ed6fa98597c80808efced174" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27492
402