Bug 38930: Add a permissions store

This patch adds a permissions store to hold a user's permissions and run checks when required

Test plan:
1) Apply the patch and run the following commands
a) yarn build
b) restart_all
2) Ensuring you are logged in as the Koha superlibrarian user, navigate to the ERM module and click into Agreements
3) Note that the button for New Agreement is visible
4) Choose a random staff user and assign them the following permissions:
- Staff access, allows viewing of the catalogue in staff interface (catalogue)
- Manage Koha system settings (Administration panel) (parameters)
- Acquisition management (acquisition)
- Manage the electronic resources module (erm)
These are the permissions required to access the ERM module
6) Open an incognito browser and log in as the chosen staff member with these permissions
7) For this example, the New agreement button has been hidden behind the CAN_user_suggestions_suggestions_create to demonstrate how it would work
8) Navigate to the Agreements page again, the button should not be visible
9) Back in your main browser, assign the following permission set to the user:
- Create purchase suggestions (suggestions_create)
10) Hard refresh the incognito browser, the button should now be visible again

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Matt Blenkinsop 2025-01-17 17:05:25 +00:00 committed by Katrin Fischer
parent 9c746e675c
commit 0a44ed18d2
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import { defineStore } from "pinia";
export const usePermissionsStore = defineStore("permissions", {
state: () => ({
userPermissions: null,
}),
actions: {
isUserPermitted(operation, permissions) {
const userPermissions = permissions
? permissions
: this.userPermissions;
if (!operation) return true;
if (!userPermissions) return false;
return (
userPermissions.hasOwnProperty(operation) &&
userPermissions[operation]
);
},
},
});