@edular/permissions 3.2.5 → 4.0.0

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.
@@ -0,0 +1,48 @@
1
+ export declare enum UserProfileType {
2
+ ApiKey = "api_key",
3
+ Admin = "admin",
4
+ Staff = "staff",
5
+ Student = "student",
6
+ Others = "others"
7
+ }
8
+ export declare type PermissionDetails = {
9
+ permissionId: number;
10
+ name: string;
11
+ departmentId?: number;
12
+ subunitId?: number;
13
+ };
14
+ export declare enum PermissionType {
15
+ View = "view",
16
+ Add = "add",
17
+ Edit = "edit",
18
+ Delete = "delete"
19
+ }
20
+ export declare enum DepartmentPermissionTarget {
21
+ DocumentsListView = "documents.list_view",
22
+ DocumentsDetailView = "documents.detail_view",
23
+ Activities = "activities",
24
+ Tasks = "tasks",
25
+ TasksAccessOthers = "tasks.access_others"
26
+ }
27
+ export declare const DepartmentPermissionTargetTypes: {
28
+ "documents.list_view": PermissionType[];
29
+ "documents.detail_view": PermissionType[];
30
+ activities: PermissionType[];
31
+ tasks: PermissionType[];
32
+ "tasks.access_others": PermissionType[];
33
+ };
34
+ export declare type ProfilePermissionsDetails = {
35
+ type: UserProfileType.Staff;
36
+ enabledPermissionIds: number[];
37
+ enabledDepartmentPermissionIds: number[];
38
+ } | {
39
+ type: UserProfileType.Student;
40
+ enabledPermissionIds: number[];
41
+ } | {
42
+ type: UserProfileType.Admin;
43
+ } | {
44
+ type: UserProfileType.ApiKey;
45
+ } | {
46
+ type: UserProfileType.Others;
47
+ enabledPermissionIds: number[];
48
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var _a;
3
+ exports.__esModule = true;
4
+ exports.DepartmentPermissionTargetTypes = exports.DepartmentPermissionTarget = exports.PermissionType = exports.UserProfileType = void 0;
5
+ var UserProfileType;
6
+ (function (UserProfileType) {
7
+ UserProfileType["ApiKey"] = "api_key";
8
+ UserProfileType["Admin"] = "admin";
9
+ UserProfileType["Staff"] = "staff";
10
+ UserProfileType["Student"] = "student";
11
+ UserProfileType["Others"] = "others";
12
+ })(UserProfileType = exports.UserProfileType || (exports.UserProfileType = {}));
13
+ var PermissionType;
14
+ (function (PermissionType) {
15
+ PermissionType["View"] = "view";
16
+ PermissionType["Add"] = "add";
17
+ PermissionType["Edit"] = "edit";
18
+ PermissionType["Delete"] = "delete";
19
+ })(PermissionType = exports.PermissionType || (exports.PermissionType = {}));
20
+ var DepartmentPermissionTarget;
21
+ (function (DepartmentPermissionTarget) {
22
+ DepartmentPermissionTarget["DocumentsListView"] = "documents.list_view";
23
+ DepartmentPermissionTarget["DocumentsDetailView"] = "documents.detail_view";
24
+ DepartmentPermissionTarget["Activities"] = "activities";
25
+ DepartmentPermissionTarget["Tasks"] = "tasks";
26
+ DepartmentPermissionTarget["TasksAccessOthers"] = "tasks.access_others";
27
+ })(DepartmentPermissionTarget = exports.DepartmentPermissionTarget || (exports.DepartmentPermissionTarget = {}));
28
+ exports.DepartmentPermissionTargetTypes = (_a = {},
29
+ _a[DepartmentPermissionTarget.DocumentsListView] = [PermissionType.View],
30
+ _a[DepartmentPermissionTarget.DocumentsDetailView] = [
31
+ PermissionType.View,
32
+ PermissionType.Add,
33
+ PermissionType.Edit,
34
+ PermissionType.Delete,
35
+ ],
36
+ _a[DepartmentPermissionTarget.Activities] = [
37
+ PermissionType.View,
38
+ PermissionType.Add,
39
+ PermissionType.Edit,
40
+ PermissionType.Delete,
41
+ ],
42
+ _a[DepartmentPermissionTarget.Tasks] = [
43
+ PermissionType.View,
44
+ PermissionType.Add,
45
+ PermissionType.Edit,
46
+ PermissionType.Delete,
47
+ ],
48
+ _a[DepartmentPermissionTarget.TasksAccessOthers] = [
49
+ PermissionType.View,
50
+ PermissionType.Edit,
51
+ PermissionType.Delete,
52
+ ],
53
+ _a);
@@ -0,0 +1,4 @@
1
+ import { DepartmentPermissionTarget, PermissionDetails, PermissionType, ProfilePermissionsDetails } from './constants';
2
+ export declare const checkIfProfileHasNeededPermissions: (profilePermissions: ProfilePermissionsDetails, permissionIds: number[]) => boolean;
3
+ export declare const getEnabledPermissionsForTarget: (permissions: PermissionDetails[], target: DepartmentPermissionTarget, type: PermissionType) => PermissionDetails[];
4
+ export declare const checkPermissionsForSubunits: (permissions: PermissionDetails[], target: DepartmentPermissionTarget, type: PermissionType, subunitIds: number[]) => boolean;
package/lib/helpers.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.checkPermissionsForSubunits = exports.getEnabledPermissionsForTarget = exports.checkIfProfileHasNeededPermissions = void 0;
4
+ var constants_1 = require("./constants");
5
+ var checkIfProfileHasNeededPermissions = function (profilePermissions, permissionIds) {
6
+ if (permissionIds.length === 0) {
7
+ throw new Error("Permission IDs can't be an empty array");
8
+ }
9
+ if (profilePermissions.type === constants_1.UserProfileType.Admin ||
10
+ profilePermissions.type === constants_1.UserProfileType.ApiKey) {
11
+ return true;
12
+ }
13
+ return permissionIds.every(function (permissionId) {
14
+ return profilePermissions.enabledPermissionIds.includes(permissionId);
15
+ });
16
+ };
17
+ exports.checkIfProfileHasNeededPermissions = checkIfProfileHasNeededPermissions;
18
+ var getEnabledPermissionsForTarget = function (permissions, target, type) {
19
+ return permissions.filter(function (permission) {
20
+ return permission.name.endsWith(target + "." + type);
21
+ });
22
+ };
23
+ exports.getEnabledPermissionsForTarget = getEnabledPermissionsForTarget;
24
+ var checkPermissionsForSubunits = function (permissions, target, type, subunitIds) {
25
+ var enabledPermissions = (0, exports.getEnabledPermissionsForTarget)(permissions, target, type);
26
+ return subunitIds.every(function (subunitId) {
27
+ return enabledPermissions.find(function (permission) { return permission.subunitId === subunitId; });
28
+ });
29
+ };
30
+ exports.checkPermissionsForSubunits = checkPermissionsForSubunits;
package/lib/index.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from './permissions';
2
+ export * from './constants';
3
+ export * from './helpers';
package/lib/index.js CHANGED
@@ -11,3 +11,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  exports.__esModule = true;
13
13
  __exportStar(require("./permissions"), exports);
14
+ __exportStar(require("./constants"), exports);
15
+ __exportStar(require("./helpers"), exports);
@@ -610,6 +610,12 @@ export declare const Permissions: {
610
610
  Edit: number;
611
611
  Delete: number;
612
612
  };
613
+ Access: {
614
+ View: number;
615
+ Add: number;
616
+ Edit: number;
617
+ Delete: number;
618
+ };
613
619
  };
614
620
  Tasks: {
615
621
  Assigned: {
@@ -612,6 +612,12 @@ exports.Permissions = {
612
612
  Add: 2782,
613
613
  Edit: 2783,
614
614
  Delete: 2784
615
+ },
616
+ Access: {
617
+ View: 5911,
618
+ Add: 5912,
619
+ Edit: 5913,
620
+ Delete: 5914
615
621
  }
616
622
  },
617
623
  Tasks: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edular/permissions",
3
- "version": "3.2.5",
3
+ "version": "4.0.0",
4
4
  "author": "Edular",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",