blob: edac2cfc88d36cf685ea1afc13f88c1265a8f3d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/**
* Composable for checking session privileges
*
* This is used for UX improvements to conditionally render UI elements based
* on the session role. Note: This does NOT provide backend security —
* all operations are validated by the backend (bmcweb) according to Redfish
* privilege rules.
*
* Authorization comes from Session.Roles, not from the user account directly.
* LDAP and certificate sessions may have Roles without a corresponding
* AccountService user.
*
* Note: sessionRole reflects the *first* entry in the Session's Roles array.
* It is a role name (e.g. 'Administrator'), not a Redfish AssignedPrivilege.
*/
import { computed } from 'vue';
import { useStore } from 'vuex';
import { privilegesId } from '@/store/modules/GlobalStore';
export function usePrivilegeCheck() {
const store = useStore();
// First entry from the Session's Roles array (e.g. 'Administrator')
const sessionRole = computed(() => store.getters['global/sessionRole']);
const isReadOnly = computed(() => {
return (
sessionRole.value != null &&
sessionRole.value === privilegesId.readOnly
);
});
const hasOperatorOrAbove = computed(() => {
return (
sessionRole.value != null &&
(sessionRole.value === privilegesId.operator ||
sessionRole.value === privilegesId.admin)
);
});
const hasAdminPrivilege = computed(() => {
return (
sessionRole.value != null &&
sessionRole.value === privilegesId.admin
);
});
return {
sessionRole,
isReadOnly,
hasOperatorOrAbove,
hasAdminPrivilege,
};
}
|