diff --git a/package-lock.json b/package-lock.json index 520c856..cc47e42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@heroicons/vue": "^1.0.6", "axios": "^0.26.1", "jwt-decode": "^4.0.0", + "lodash.clonedeep": "^4.5.0", "nprogress": "^0.2.0", "pdf-dist": "^1.0.0", "pinia": "^2.1.7", @@ -27,6 +28,7 @@ "@rushstack/eslint-patch": "^1.8.0", "@tsconfig/node20": "^20.1.4", "@types/eslint": "~9.6.0", + "@types/lodash.clonedeep": "^4.5.9", "@types/node": "^20.14.5", "@types/nprogress": "^0.2.0", "@types/qrcode": "^1.5.5", @@ -3062,6 +3064,23 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true }, + "node_modules/@types/lodash": { + "version": "4.17.7", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.7.tgz", + "integrity": "sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/lodash.clonedeep": { + "version": "4.5.9", + "resolved": "https://registry.npmjs.org/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.9.tgz", + "integrity": "sha512-19429mWC+FyaAhOLzsS8kZUsI+/GmBAQ0HFiCPsKGU+7pBXOQWhyrY6xNNDwUSX8SMZMJvuFVMF9O5dQOlQK9Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/lodash": "*" + } + }, "node_modules/@types/node": { "version": "20.14.15", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.15.tgz", @@ -6593,6 +6612,12 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, + "node_modules/lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==", + "license": "MIT" + }, "node_modules/lodash.debounce": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", diff --git a/package.json b/package.json index e94b600..8d629cb 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@heroicons/vue": "^1.0.6", "axios": "^0.26.1", "jwt-decode": "^4.0.0", + "lodash.clonedeep": "^4.5.0", "nprogress": "^0.2.0", "pdf-dist": "^1.0.0", "pinia": "^2.1.7", @@ -42,6 +43,7 @@ "@rushstack/eslint-patch": "^1.8.0", "@tsconfig/node20": "^20.1.4", "@types/eslint": "~9.6.0", + "@types/lodash.clonedeep": "^4.5.9", "@types/node": "^20.14.5", "@types/nprogress": "^0.2.0", "@types/qrcode": "^1.5.5", diff --git a/src/components/admin/user/Permission.vue b/src/components/admin/user/Permission.vue new file mode 100644 index 0000000..2f40ef4 --- /dev/null +++ b/src/components/admin/user/Permission.vue @@ -0,0 +1,160 @@ + + + + + diff --git a/src/stores/ability.ts b/src/stores/ability.ts index ae743ca..7f28346 100644 --- a/src/stores/ability.ts +++ b/src/stores/ability.ts @@ -15,7 +15,31 @@ export const useAbilityStore = defineStore("ability", { if (type == "admin") return permissions.admin ?? false; if (permissions.admin) return true; if ( - (!module && permissions[section] != undefined) || + (!module && + permissions[section] != undefined && + (permissions[section]?.all == "*" || permissions[section]?.all?.includes(type))) || + permissions[section]?.all == "*" || + permissions[section]?.all?.includes(type) + ) + return true; + if (module && (permissions[section]?.[module] == "*" || permissions[section]?.[module]?.includes(type))) + return true; + return false; + }, + _can: + () => + ( + permissions: PermissionObject, + type: PermissionType | "admin", + section: PermissionSection, + module?: PermissionModule + ): boolean => { + if (type == "admin") return permissions.admin ?? false; + if (permissions.admin) return true; + if ( + (!module && + permissions[section] != undefined && + (permissions[section]?.all == "*" || permissions[section]?.all?.includes(type))) || permissions[section]?.all == "*" || permissions[section]?.all?.includes(type) ) diff --git a/src/stores/admin/navigation.ts b/src/stores/admin/navigation.ts index 99fd45a..164fd17 100644 --- a/src/stores/admin/navigation.ts +++ b/src/stores/admin/navigation.ts @@ -205,7 +205,7 @@ export const useNavigationStore = defineStore("navigation", { { key: "#user", title: "Benutzer", - component: shallowRef(defineAsyncComponent(() => import("@/views/admin/members/Overview.vue"))), + component: shallowRef(defineAsyncComponent(() => import("@/views/admin/user/User.vue"))), }, ] : []), diff --git a/src/stores/admin/permission.ts b/src/stores/admin/permission.ts new file mode 100644 index 0000000..357d734 --- /dev/null +++ b/src/stores/admin/permission.ts @@ -0,0 +1,12 @@ +import { defineStore } from "pinia"; + +export const usePermissionStore = defineStore("permission", { + state: () => { + return { + sections: [], + }; + }, + actions: { + logoutAccount() {}, + }, +}); diff --git a/src/types/permissionTypes.ts b/src/types/permissionTypes.ts index fd6d6dd..f042390 100644 --- a/src/types/permissionTypes.ts +++ b/src/types/permissionTypes.ts @@ -24,7 +24,31 @@ export type PermissionString = export type PermissionObject = { [section in PermissionSection]?: { [module in PermissionModule]?: Array | "*"; - } & { all?: PermissionType | "*" }; + } & { all?: Array | "*" }; } & { admin?: boolean; }; + +export type SectionsAndModulesObject = { + [section in PermissionSection]: Array; +}; + +export const permissionSections: Array = ["club", "settings", "user"]; +export const permissionModules: Array = [ + "members", + "calendar", + "newsletter", + "protocoll", + "qualification", + "award", + "executive_position", + "communication", + "user", + "role", +]; +export const permissionTypes: Array = ["read", "create", "update", "delete"]; +export const sectionsAndModules: SectionsAndModulesObject = { + club: ["members", "calendar", "newsletter", "protocoll"], + settings: ["qualification", "award", "executive_position", "communication"], + user: ["user", "role"], +}; diff --git a/src/views/admin/user/User.vue b/src/views/admin/user/User.vue new file mode 100644 index 0000000..2d3d1d3 --- /dev/null +++ b/src/views/admin/user/User.vue @@ -0,0 +1,23 @@ + + + + +