@capillarytech/cap-ui-utils 1.0.8 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/auth/hasRole.js +14 -0
- package/auth/index.js +10 -0
- package/auth/isCapUser.js +13 -0
- package/package.json +1 -1
package/auth/hasRole.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import warn from '../utils/console/warn';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Function to check if the user has access to the role
|
|
5
|
+
* @param {*} role
|
|
6
|
+
*/
|
|
7
|
+
export default function hasRole(role) {
|
|
8
|
+
if(!window.capAuth) {
|
|
9
|
+
warn("Cap auth not initialized. Please initialize cap auth to use this method");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const { roles } = window.capAuth;
|
|
13
|
+
return roles.includes(role);
|
|
14
|
+
}
|
package/auth/index.js
CHANGED
|
@@ -10,6 +10,8 @@ import log from '../utils/console/log';
|
|
|
10
10
|
import isEmpty from '../utils/isEmpty';
|
|
11
11
|
import hasAccess from './hasAccess';
|
|
12
12
|
import authHoc from './authHoc';
|
|
13
|
+
import hasRole from './hasRole';
|
|
14
|
+
import isCapUser from './isCapUser';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Function to initialize the capAuth configurations to the document
|
|
@@ -27,6 +29,12 @@ function _initialize(authConfigs) {
|
|
|
27
29
|
if(authConfigs.orgFeatures) {
|
|
28
30
|
capAuth.orgFeatures = Object.freeze(authConfigs.orgFeatures);
|
|
29
31
|
}
|
|
32
|
+
if(authConfigs.roles) {
|
|
33
|
+
capAuth.roles = Object.freeze(authConfigs.roles);
|
|
34
|
+
}
|
|
35
|
+
if(authConfigs.isCapUser) {
|
|
36
|
+
capAuth.isCapUser = true;
|
|
37
|
+
}
|
|
30
38
|
log("Cap auth initialized");
|
|
31
39
|
window.capAuth = Object.freeze(capAuth);
|
|
32
40
|
}
|
|
@@ -62,5 +70,7 @@ export default {
|
|
|
62
70
|
initialize,
|
|
63
71
|
hasAccess,
|
|
64
72
|
authHoc,
|
|
73
|
+
hasRole,
|
|
74
|
+
isCapUser,
|
|
65
75
|
}
|
|
66
76
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import warn from '../utils/console/warn';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Function to check if the user is a capUser
|
|
5
|
+
*/
|
|
6
|
+
export default function isCapUser() {
|
|
7
|
+
if(!window.capAuth) {
|
|
8
|
+
warn("Cap auth not initialized. Please initialize cap auth to use this method");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const { isCapUser = false } = window.capAuth;
|
|
12
|
+
return isCapUser;
|
|
13
|
+
}
|