@yangsaiyam/helper 1.5.1 → 1.5.2
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/package.json +1 -1
- package/src/roles/index.test.ts +23 -1
- package/src/roles/index.ts +17 -1
package/package.json
CHANGED
package/src/roles/index.test.ts
CHANGED
|
@@ -46,14 +46,36 @@ assert.equal(
|
|
|
46
46
|
permissionLabelKey(Permission.CONTACT_FORM_DELETE),
|
|
47
47
|
"permissions.contactFormDelete",
|
|
48
48
|
);
|
|
49
|
+
assert.equal(
|
|
50
|
+
permissionLabelKey(Permission.OTP_ATTEMPTS_READ),
|
|
51
|
+
"permissions.otpAttemptsRead",
|
|
52
|
+
);
|
|
53
|
+
assert.equal(
|
|
54
|
+
permissionLabelKey(Permission.TWO_FACTOR_AUTH_WRITE),
|
|
55
|
+
"permissions.twoFactorAuthWrite",
|
|
56
|
+
);
|
|
57
|
+
assert.equal(permissionLabelKey(Permission.VIEWS_READ), "permissions.viewsRead");
|
|
49
58
|
|
|
50
59
|
assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.USERS_DELETE));
|
|
60
|
+
assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.OTP_ATTEMPTS_READ));
|
|
61
|
+
assert.ok(
|
|
62
|
+
ROLE_PERMISSIONS["super-admin"].includes(Permission.TWO_FACTOR_AUTH_WRITE),
|
|
63
|
+
);
|
|
64
|
+
assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.VIEWS_READ));
|
|
51
65
|
assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.CONTACT_FORM_DELETE));
|
|
66
|
+
assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.VIEWS_READ));
|
|
67
|
+
assert.equal(
|
|
68
|
+
ROLE_PERMISSIONS.admin.includes(Permission.USERS_WRITE),
|
|
69
|
+
false,
|
|
70
|
+
);
|
|
52
71
|
assert.ok(ROLE_PERMISSIONS.hr.includes(Permission.JOB_APPLICATIONS_READ));
|
|
53
|
-
assert.deepEqual(ROLE_PERMISSIONS.staff, [Permission.
|
|
72
|
+
assert.deepEqual(ROLE_PERMISSIONS.staff, [Permission.CONTACT_FORM_READ]);
|
|
54
73
|
|
|
55
74
|
assert.equal(hasPermission("super-admin", Permission.USERS_WRITE), true);
|
|
75
|
+
assert.equal(hasPermission("super-admin", Permission.OTP_ATTEMPTS_WRITE), true);
|
|
56
76
|
assert.equal(hasPermission(1, Permission.USERS_WRITE), false);
|
|
57
77
|
assert.equal(hasPermission("hr", Permission.CAREERS_WRITE), true);
|
|
58
78
|
assert.equal(hasPermission("staff", Permission.CAREERS_WRITE), false);
|
|
79
|
+
assert.equal(hasPermission("staff", Permission.CONTACT_FORM_READ), true);
|
|
80
|
+
assert.equal(hasPermission("admin", Permission.VIEWS_READ), true);
|
|
59
81
|
assert.equal(hasPermission(undefined, Permission.CAREERS_READ), false);
|
package/src/roles/index.ts
CHANGED
|
@@ -74,6 +74,11 @@ export const Permission = {
|
|
|
74
74
|
CONTACT_FORM_READ: "contact-form:read",
|
|
75
75
|
CONTACT_FORM_DELETE: "contact-form:delete",
|
|
76
76
|
JOB_APPLICATIONS_READ: "job-applications:read",
|
|
77
|
+
OTP_ATTEMPTS_READ: "otp-attempts:read",
|
|
78
|
+
OTP_ATTEMPTS_WRITE: "otp-attempts:write",
|
|
79
|
+
TWO_FACTOR_AUTH_READ: "two-factor-auth:read",
|
|
80
|
+
TWO_FACTOR_AUTH_WRITE: "two-factor-auth:write",
|
|
81
|
+
VIEWS_READ: "views:read",
|
|
77
82
|
} as const;
|
|
78
83
|
|
|
79
84
|
export type Permission = (typeof Permission)[keyof typeof Permission];
|
|
@@ -90,6 +95,11 @@ export const PERMISSION_I18N_KEY: Record<Permission, string> = {
|
|
|
90
95
|
[Permission.CONTACT_FORM_READ]: "permissions.contactFormRead",
|
|
91
96
|
[Permission.CONTACT_FORM_DELETE]: "permissions.contactFormDelete",
|
|
92
97
|
[Permission.JOB_APPLICATIONS_READ]: "permissions.jobApplicationsRead",
|
|
98
|
+
[Permission.OTP_ATTEMPTS_READ]: "permissions.otpAttemptsRead",
|
|
99
|
+
[Permission.OTP_ATTEMPTS_WRITE]: "permissions.otpAttemptsWrite",
|
|
100
|
+
[Permission.TWO_FACTOR_AUTH_READ]: "permissions.twoFactorAuthRead",
|
|
101
|
+
[Permission.TWO_FACTOR_AUTH_WRITE]: "permissions.twoFactorAuthWrite",
|
|
102
|
+
[Permission.VIEWS_READ]: "permissions.viewsRead",
|
|
93
103
|
};
|
|
94
104
|
|
|
95
105
|
export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
|
|
@@ -105,6 +115,11 @@ export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
|
|
|
105
115
|
Permission.CONTACT_FORM_READ,
|
|
106
116
|
Permission.CONTACT_FORM_DELETE,
|
|
107
117
|
Permission.JOB_APPLICATIONS_READ,
|
|
118
|
+
Permission.OTP_ATTEMPTS_READ,
|
|
119
|
+
Permission.OTP_ATTEMPTS_WRITE,
|
|
120
|
+
Permission.TWO_FACTOR_AUTH_READ,
|
|
121
|
+
Permission.TWO_FACTOR_AUTH_WRITE,
|
|
122
|
+
Permission.VIEWS_READ,
|
|
108
123
|
],
|
|
109
124
|
admin: [
|
|
110
125
|
Permission.ALLOWED_EMAILS_READ,
|
|
@@ -116,6 +131,7 @@ export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
|
|
|
116
131
|
Permission.CONTACT_FORM_READ,
|
|
117
132
|
Permission.CONTACT_FORM_DELETE,
|
|
118
133
|
Permission.JOB_APPLICATIONS_READ,
|
|
134
|
+
Permission.VIEWS_READ,
|
|
119
135
|
],
|
|
120
136
|
hr: [
|
|
121
137
|
Permission.CAREERS_READ,
|
|
@@ -123,7 +139,7 @@ export const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]> = {
|
|
|
123
139
|
Permission.CAREERS_DELETE,
|
|
124
140
|
Permission.JOB_APPLICATIONS_READ,
|
|
125
141
|
],
|
|
126
|
-
staff: [Permission.
|
|
142
|
+
staff: [Permission.CONTACT_FORM_READ],
|
|
127
143
|
};
|
|
128
144
|
|
|
129
145
|
export function hasPermission(
|