From 0e09eee673435662c616b0f921cdc02619001c1e Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Thu, 14 Oct 2021 10:40:57 +0200 Subject: [PATCH] UI: Add permission checks (photos) and refactor acl evaluation for public mode #98 --- frontend/src/app.js | 21 ++++++++-- frontend/src/common/acl.js | 26 +----------- frontend/src/component/navigation.vue | 12 +++--- frontend/src/component/photo/cards.vue | 7 ++-- frontend/src/component/photo/clipboard.vue | 8 ++-- frontend/src/component/photo/list.vue | 6 +-- frontend/src/component/photo/mosaic.vue | 8 ++-- frontend/src/component/photo/toolbar.vue | 2 +- frontend/src/component/photo/viewer.vue | 4 +- frontend/src/dialog/photo/details.vue | 4 +- frontend/src/dialog/photo/info.vue | 8 ++++ frontend/src/pages/albums.vue | 2 +- frontend/src/routes.js | 48 ++++++++++------------ internal/acl/actions.go | 1 + internal/api/batch.go | 4 +- 15 files changed, 79 insertions(+), 82 deletions(-) diff --git a/frontend/src/app.js b/frontend/src/app.js index a2b61dc39..2c6993f44 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -57,7 +57,7 @@ import Hls from "hls.js"; import "common/maptiler-lang"; import { $gettext, Mount } from "common/vm"; import * as offline from "@lcdp/offline-plugin/runtime"; -import Acl from "./common/acl"; +import Acl, { Constants } from "./common/acl"; // Initialize helpers const viewer = new Viewer(); @@ -103,11 +103,26 @@ Vue.prototype.$earlyAccess = () => { Vue.mixin({ data() { - return {}; + return { + aclResources: Constants.resources, + aclActions: Constants.actions, + }; }, computed: { acl() { - return new Acl(window.__CONFIG__.acl); + return new Acl(this.$config.values.acl); + // return new Acl(window.__CONFIG__.acl); + }, + }, + methods: { + hasPermission(resource, action) { + console.log(this.$config.values); + if (this.$config.values.public) return true; + // let acl = new Acl(window.__CONFIG__.acl); + console.log(`USER: ${this.$session.getUser().UserName}`); + console.log(this.$session.getUser()); + console.log(`ROLE: ${this.$session.getUser().getRole()}`); + return this.acl.accessAllowed(this.$session.getUser().getRole(), resource, action); }, }, }); diff --git a/frontend/src/common/acl.js b/frontend/src/common/acl.js index 1207e4745..ea06bae15 100644 --- a/frontend/src/common/acl.js +++ b/frontend/src/common/acl.js @@ -23,6 +23,7 @@ export const Constants = { ActionUpdate: "update", ActionUpdateSelf: "update-self", ActionDelete: "delete", + ActionArchive: "archive", ActionPrivate: "private", ActionUpload: "upload", ActionDownload: "download", @@ -68,14 +69,9 @@ export default class Acl { } accessAllowed(role, resource, action) { if (!this.acl) return false; - console.log("resource: ", resource); - console.log("role: ", role); - console.log("action: ", action); let res; if (!this.acl[resource]) { - console.log("resource not found"); if (!this.acl[Constants.resources.ResourceDefault]) return false; - console.log("using default resource"); res = this.acl[Constants.resources.ResourceDefault]; } else { res = this.acl[resource]; @@ -83,9 +79,7 @@ export default class Acl { let rol; if (!res[role]) { - console.log("role not found"); if (!res[Constants.roles.RoleDefault]) return false; - console.log("using default role"); rol = res[Constants.roles.RoleDefault]; } else { rol = res[role]; @@ -93,32 +87,14 @@ export default class Acl { let act; if (!rol[action]) { - console.log("action not found"); if (!rol[Constants.actions.ActionDefault]) return false; - console.log("using default action"); act = rol[Constants.actions.ActionDefault]; } else { act = rol[action]; } - console.log("Result: ", act); return act; } accessAllowedAny(role, resource, ...actions) { - // let result = false; - // for (const a in actions) { - // result = result || this.accessAllowed(role, resource, a); - // } - // return result; - // return actions.reduce((accumulator, action) => { - // return accumulator || this.accessAllowed(role, resource, action); - // }); - // for (const a in actions) { - // if (this.accessAllowed(role, resource, a)) return true; - // } - // return false; return actions.some((action) => this.accessAllowed(role, resource, action)); } - getConstants() { - return Constants; - } } diff --git a/frontend/src/component/navigation.vue b/frontend/src/component/navigation.vue index 0893e04e2..e4a2fed2e 100644 --- a/frontend/src/component/navigation.vue +++ b/frontend/src/component/navigation.vue @@ -116,7 +116,7 @@ - @@ -126,7 +126,7 @@ - + Archive @@ -301,7 +301,7 @@ - + lock @@ -314,7 +314,7 @@ - + camera_roll @@ -326,7 +326,7 @@ - +