@memberjunction/core-entities 2.7.1 → 2.9.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.
- package/dist/custom/ResourcePermissions/ResourcePermissionEngine.d.ts +63 -0
- package/dist/custom/ResourcePermissions/ResourcePermissionEngine.d.ts.map +1 -0
- package/dist/custom/ResourcePermissions/ResourcePermissionEngine.js +165 -0
- package/dist/custom/ResourcePermissions/ResourcePermissionEngine.js.map +1 -0
- package/dist/custom/ResourcePermissions/ResourcePermissionSubclass.d.ts +16 -0
- package/dist/custom/ResourcePermissions/ResourcePermissionSubclass.d.ts.map +1 -0
- package/dist/custom/ResourcePermissions/ResourcePermissionSubclass.js +104 -0
- package/dist/custom/ResourcePermissions/ResourcePermissionSubclass.js.map +1 -0
- package/dist/custom/UserViewEntity.d.ts +36 -0
- package/dist/custom/UserViewEntity.d.ts.map +1 -1
- package/dist/custom/UserViewEntity.js +166 -10
- package/dist/custom/UserViewEntity.js.map +1 -1
- package/dist/generated/entity_subclasses.d.ts +370 -4
- package/dist/generated/entity_subclasses.d.ts.map +1 -1
- package/dist/generated/entity_subclasses.js +684 -155
- package/dist/generated/entity_subclasses.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BaseEngine, UserInfo } from "@memberjunction/core";
|
|
2
|
+
import { ResourcePermissionEntity, ResourceTypeEntity } from "../../generated/entity_subclasses";
|
|
3
|
+
/**
|
|
4
|
+
* Resource Permission Engine is used for accessing metadata about permissions for resources and also determining if a user has access to a resource and at what level.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ResourcePermissionEngine extends BaseEngine<ResourcePermissionEngine> {
|
|
7
|
+
/**
|
|
8
|
+
* Returns the global instance of the class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of it, always use this method to get the instance.
|
|
9
|
+
*/
|
|
10
|
+
static get Instance(): ResourcePermissionEngine;
|
|
11
|
+
private _Permissions;
|
|
12
|
+
private _ResourceTypes;
|
|
13
|
+
Config(forceRefresh?: boolean, contextUser?: UserInfo): Promise<void>;
|
|
14
|
+
get ResourceTypes(): ResourceTypeEntity[];
|
|
15
|
+
get Permissions(): ResourcePermissionEntity[];
|
|
16
|
+
/**
|
|
17
|
+
* Convenience method to find all of the permissions for a given Resource Type and Resource Record ID, no additional filtering takes place in this method regarding
|
|
18
|
+
* the status or level of the permission.
|
|
19
|
+
* @param ResourceTypeID
|
|
20
|
+
* @param ResourceRecordID
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
GetResourcePermissions(ResourceTypeID: string, ResourceRecordID: string): ResourcePermissionEntity[];
|
|
24
|
+
/**
|
|
25
|
+
* Determines the highest level of resource permission a user has for a specific resource.
|
|
26
|
+
* This function checks both user-specific permissions and permissions assigned through roles
|
|
27
|
+
* and returns the highest level of permission ('View', 'Edit', 'Owner', or `null` if no permission is found).
|
|
28
|
+
* Note: This only returns ResourcePermissionEntity objects that have Status === Approved.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} ResourceTypeID - The ID of the resource type (e.g., document, project).
|
|
31
|
+
* @param {string} ResourceRecordID - The ID of the specific resource record.
|
|
32
|
+
* @param {UserInfo} user - The user object containing user details, including roles and ID.
|
|
33
|
+
*
|
|
34
|
+
* @returns {'View' | 'Edit' | 'Owner' | null} - The highest permission level the user has for the resource,
|
|
35
|
+
* or `null` if no permission exists.
|
|
36
|
+
*
|
|
37
|
+
* Permission Levels:
|
|
38
|
+
* - 'Owner': Full control over the resource.
|
|
39
|
+
* - 'Edit': Can modify the resource.
|
|
40
|
+
* - 'View': Can only view the resource.
|
|
41
|
+
* - `null`: No permissions found for the user on this resource.
|
|
42
|
+
*/
|
|
43
|
+
GetUserResourcePermissionLevel(ResourceTypeID: string, ResourceRecordID: string, user: UserInfo): 'View' | 'Edit' | 'Owner' | null;
|
|
44
|
+
/**
|
|
45
|
+
* Returns all the permissions a user has for a specific resource type based on both their user-specific permissions and permissions assigned through roles.
|
|
46
|
+
* This only returns ResourcePermissionEntity objects that have Status === Approved.
|
|
47
|
+
* @param user
|
|
48
|
+
* @param ResourceTypeID
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
GetUserAvailableResources(user: UserInfo, ResourceTypeID?: string): ResourcePermissionEntity[];
|
|
52
|
+
/**
|
|
53
|
+
* This method will use the MJ metadata to find the fields names for the fields that represent the OwnerID and the Name of the resource in the given resource type.
|
|
54
|
+
* Often, these fields are simply named OwnerID and Name in the underlying entity that represents the resource, but this method uses metadata lookups to find the first
|
|
55
|
+
* foreign key to the Users entity from the resource type's entity and looks for the field that is consider the "Name Field" for the entity and returns those values.
|
|
56
|
+
*/
|
|
57
|
+
GetResourceTypeInfoFields(ResourceTypeID: string): {
|
|
58
|
+
OwnerIDFieldName: string;
|
|
59
|
+
NameFieldName: string;
|
|
60
|
+
PrimaryKeyFieldName: string;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=ResourcePermissionEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourcePermissionEngine.d.ts","sourceRoot":"","sources":["../../../src/custom/ResourcePermissions/ResourcePermissionEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsC,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEjG;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,UAAU,CAAC,wBAAwB,CAAC;IAC9E;;OAEG;IACH,WAAkB,QAAQ,IAAI,wBAAwB,CAErD;IAED,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,cAAc,CAEpB;IACW,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,QAAQ;IAiBlE,IAAW,aAAa,IAAI,kBAAkB,EAAE,CAE/C;IAED,IAAW,WAAW,IAAI,wBAAwB,EAAE,CAEnD;IAGD;;;;;;OAMG;IACI,sBAAsB,CAAC,cAAc,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,wBAAwB,EAAE;IAI3G;;;;;;;;;;;;;;;;;;OAkBG;IACI,8BAA8B,CACjC,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,MAAM,EACxB,IAAI,EAAE,QAAQ,GACf,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI;IAiCnC;;;;;;OAMG;IACI,yBAAyB,CAAC,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,wBAAwB,EAAE;IAuCrG;;;;OAIG;IACI,yBAAyB,CAAC,cAAc,EAAE,MAAM,GAAG;QAAC,gBAAgB,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,MAAM,CAAA;KAAC;CAoB3I"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourcePermissionEngine = void 0;
|
|
4
|
+
const core_1 = require("@memberjunction/core");
|
|
5
|
+
/**
|
|
6
|
+
* Resource Permission Engine is used for accessing metadata about permissions for resources and also determining if a user has access to a resource and at what level.
|
|
7
|
+
*/
|
|
8
|
+
class ResourcePermissionEngine extends core_1.BaseEngine {
|
|
9
|
+
/**
|
|
10
|
+
* Returns the global instance of the class. This is a singleton class, so there is only one instance of it in the application. Do not directly create new instances of it, always use this method to get the instance.
|
|
11
|
+
*/
|
|
12
|
+
static get Instance() {
|
|
13
|
+
return super.getInstance();
|
|
14
|
+
}
|
|
15
|
+
async Config(forceRefresh, contextUser) {
|
|
16
|
+
const c = [
|
|
17
|
+
{
|
|
18
|
+
Type: 'entity',
|
|
19
|
+
EntityName: 'Resource Permissions',
|
|
20
|
+
PropertyName: "_Permissions"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
Type: 'dataset',
|
|
24
|
+
DatasetName: 'ResourceTypes',
|
|
25
|
+
PropertyName: "_ResourceTypes",
|
|
26
|
+
DatasetResultHandling: "single_property"
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
await this.Load(c, forceRefresh, contextUser);
|
|
30
|
+
}
|
|
31
|
+
get ResourceTypes() {
|
|
32
|
+
return this._ResourceTypes.ResourceTypes;
|
|
33
|
+
}
|
|
34
|
+
get Permissions() {
|
|
35
|
+
return this._Permissions;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Convenience method to find all of the permissions for a given Resource Type and Resource Record ID, no additional filtering takes place in this method regarding
|
|
39
|
+
* the status or level of the permission.
|
|
40
|
+
* @param ResourceTypeID
|
|
41
|
+
* @param ResourceRecordID
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
GetResourcePermissions(ResourceTypeID, ResourceRecordID) {
|
|
45
|
+
return this.Permissions.filter((r) => r.ResourceTypeID === ResourceTypeID && r.ResourceRecordID === ResourceRecordID);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Determines the highest level of resource permission a user has for a specific resource.
|
|
49
|
+
* This function checks both user-specific permissions and permissions assigned through roles
|
|
50
|
+
* and returns the highest level of permission ('View', 'Edit', 'Owner', or `null` if no permission is found).
|
|
51
|
+
* Note: This only returns ResourcePermissionEntity objects that have Status === Approved.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} ResourceTypeID - The ID of the resource type (e.g., document, project).
|
|
54
|
+
* @param {string} ResourceRecordID - The ID of the specific resource record.
|
|
55
|
+
* @param {UserInfo} user - The user object containing user details, including roles and ID.
|
|
56
|
+
*
|
|
57
|
+
* @returns {'View' | 'Edit' | 'Owner' | null} - The highest permission level the user has for the resource,
|
|
58
|
+
* or `null` if no permission exists.
|
|
59
|
+
*
|
|
60
|
+
* Permission Levels:
|
|
61
|
+
* - 'Owner': Full control over the resource.
|
|
62
|
+
* - 'Edit': Can modify the resource.
|
|
63
|
+
* - 'View': Can only view the resource.
|
|
64
|
+
* - `null`: No permissions found for the user on this resource.
|
|
65
|
+
*/
|
|
66
|
+
GetUserResourcePermissionLevel(ResourceTypeID, ResourceRecordID, user) {
|
|
67
|
+
// Get all permissions for the specified resource
|
|
68
|
+
const allPermissions = this.GetResourcePermissions(ResourceTypeID, ResourceRecordID);
|
|
69
|
+
// Filter permissions specifically granted to the user
|
|
70
|
+
const userPermissions = allPermissions.filter((p) => p.Type === 'User' && p.UserID === user.ID);
|
|
71
|
+
// Filter permissions granted through roles the user belongs to
|
|
72
|
+
const rolePermissions = allPermissions.filter((p) => p.Type === 'Role' &&
|
|
73
|
+
user.UserRoles.find(ur => ur.RoleID === p.RoleID) !== undefined);
|
|
74
|
+
// Combine user-specific permissions and role-based permissions
|
|
75
|
+
const allPermissionsForUser = userPermissions.concat(rolePermissions);
|
|
76
|
+
const approvedPermissionsForUser = allPermissionsForUser.filter((p) => p.Status === 'Approved');
|
|
77
|
+
// If no permissions are found, return null
|
|
78
|
+
if (approvedPermissionsForUser.length === 0) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Reduce permissions to find the highest permission level ('Owner' > 'Edit' > 'View')
|
|
83
|
+
return approvedPermissionsForUser.reduce((prev, current) => {
|
|
84
|
+
if (current.PermissionLevel === 'Owner') {
|
|
85
|
+
return 'Owner'; // 'Owner' has the highest priority
|
|
86
|
+
}
|
|
87
|
+
else if (current.PermissionLevel === 'Edit' && (prev === 'View' || prev === null)) {
|
|
88
|
+
return 'Edit'; // 'Edit' has a higher priority than 'View'
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return prev; // Keep the previous lower priority permission ('View' or null)
|
|
92
|
+
}
|
|
93
|
+
}, 'View');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns all the permissions a user has for a specific resource type based on both their user-specific permissions and permissions assigned through roles.
|
|
98
|
+
* This only returns ResourcePermissionEntity objects that have Status === Approved.
|
|
99
|
+
* @param user
|
|
100
|
+
* @param ResourceTypeID
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
GetUserAvailableResources(user, ResourceTypeID) {
|
|
104
|
+
let rolePermissions = this.Permissions.filter((r) => r.Type === 'Role' && user.UserRoles.find(ur => ur.RoleID === r.RoleID) !== undefined);
|
|
105
|
+
let permissions = this.Permissions.filter((r) => r.Type === 'User' && r.UserID === user.ID);
|
|
106
|
+
if (ResourceTypeID) {
|
|
107
|
+
permissions = permissions.filter((r) => r.ResourceTypeID === ResourceTypeID);
|
|
108
|
+
rolePermissions = rolePermissions.filter((r) => r.ResourceTypeID === ResourceTypeID);
|
|
109
|
+
}
|
|
110
|
+
permissions = permissions.concat(rolePermissions);
|
|
111
|
+
// now filter to ONLY approved permissions
|
|
112
|
+
permissions = permissions.filter((r) => r.Status === 'Approved');
|
|
113
|
+
// now, we reduce the array so that we only have the highest permission level for each resourcetypeid/resourcerecordid combination
|
|
114
|
+
let reducedPermissions = [];
|
|
115
|
+
permissions.forEach((p) => {
|
|
116
|
+
let existing = reducedPermissions.find((r) => r.ResourceTypeID === p.ResourceTypeID && r.ResourceRecordID === p.ResourceRecordID);
|
|
117
|
+
if (!existing) {
|
|
118
|
+
reducedPermissions.push(p);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// existing permission and see if this one is higher, if so, replace it in the array with the new one
|
|
122
|
+
let bSwap = false;
|
|
123
|
+
if (p.PermissionLevel === 'Owner' && existing.PermissionLevel !== 'Owner') {
|
|
124
|
+
bSwap = true;
|
|
125
|
+
}
|
|
126
|
+
else if (p.PermissionLevel === 'Edit' && existing.PermissionLevel === 'View') {
|
|
127
|
+
bSwap = true;
|
|
128
|
+
}
|
|
129
|
+
if (bSwap) {
|
|
130
|
+
// get rid of the existing permission
|
|
131
|
+
reducedPermissions = reducedPermissions.filter((r) => r !== existing);
|
|
132
|
+
// add the new permission
|
|
133
|
+
reducedPermissions.push(p);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return reducedPermissions;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* This method will use the MJ metadata to find the fields names for the fields that represent the OwnerID and the Name of the resource in the given resource type.
|
|
141
|
+
* Often, these fields are simply named OwnerID and Name in the underlying entity that represents the resource, but this method uses metadata lookups to find the first
|
|
142
|
+
* foreign key to the Users entity from the resource type's entity and looks for the field that is consider the "Name Field" for the entity and returns those values.
|
|
143
|
+
*/
|
|
144
|
+
GetResourceTypeInfoFields(ResourceTypeID) {
|
|
145
|
+
const md = new core_1.Metadata();
|
|
146
|
+
const rt = this.ResourceTypes.find((rt) => rt.ID === ResourceTypeID);
|
|
147
|
+
if (!rt)
|
|
148
|
+
throw new Error(`Resource Type ${ResourceTypeID} not found`);
|
|
149
|
+
const entity = md.EntityByID(rt.EntityID);
|
|
150
|
+
if (!entity)
|
|
151
|
+
throw new Error(`Entity ${rt.EntityID} not found`);
|
|
152
|
+
const usersEntity = md.EntityByName('Users');
|
|
153
|
+
if (!usersEntity)
|
|
154
|
+
throw new Error(`Entity Users not found`);
|
|
155
|
+
const ownerIDField = entity.Fields.find((f) => f.RelatedEntityID === usersEntity.ID);
|
|
156
|
+
const nameField = entity.NameField;
|
|
157
|
+
return {
|
|
158
|
+
OwnerIDFieldName: ownerIDField?.Name,
|
|
159
|
+
NameFieldName: nameField?.Name,
|
|
160
|
+
PrimaryKeyFieldName: entity.FirstPrimaryKey.Name
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.ResourcePermissionEngine = ResourcePermissionEngine;
|
|
165
|
+
//# sourceMappingURL=ResourcePermissionEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourcePermissionEngine.js","sourceRoot":"","s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AC;QACvD,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW;YACZ,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAE9C,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,KAAK,WAAW,CAAC,EAAE,CAAC,CAAC;QACrF,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,OAAO;YACH,gBAAgB,EAAE,YAAY,EAAE,IAAI;YACpC,aAAa,EAAE,SAAS,EAAE,IAAI;YAC9B,mBAAmB,EAAE,MAAM,CAAC,eAAe,CAAC,IAAI;SACnD,CAAA;IACL,CAAC;CACJ;AAhLD,4DAgLC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EntitySaveOptions } from "@memberjunction/core";
|
|
2
|
+
import { ResourcePermissionEntity } from "../../generated/entity_subclasses";
|
|
3
|
+
/**
|
|
4
|
+
* Subclass for the Resource Permissiosn entity that implements some workflow logic
|
|
5
|
+
*/
|
|
6
|
+
export declare class ResourcePermissionEntityExtended extends ResourcePermissionEntity {
|
|
7
|
+
/**
|
|
8
|
+
* This override encapsulates some busienss logic for the Resource Permissions entity as follows:
|
|
9
|
+
* 1) Whenever a new permission record is created that has a status of "Requested", we generate a new Notifications record for the owner of the resource being requested
|
|
10
|
+
* 2) Whenever a permisison record has a status that changes from "Requested" to something else, we notify the user who requested access to the resource
|
|
11
|
+
* We only do this logic when we're on the server side to avoid redundancy of notifications
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
14
|
+
Save(options?: EntitySaveOptions): Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ResourcePermissionSubclass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourcePermissionSubclass.d.ts","sourceRoot":"","sources":["../../../src/custom/ResourcePermissions/ResourcePermissionSubclass.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,iBAAiB,EAAsB,MAAM,sBAAsB,CAAC;AAEvG,OAAO,EAAE,wBAAwB,EAAsC,MAAM,mCAAmC,CAAC;AAGjH;;GAEG;AACH,qBACa,gCAAiC,SAAQ,wBAAwB;IAC1E;;;;;;OAMG;IACY,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;CA8ErE"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ResourcePermissionEntityExtended = void 0;
|
|
10
|
+
const core_1 = require("@memberjunction/core");
|
|
11
|
+
const global_1 = require("@memberjunction/global");
|
|
12
|
+
const entity_subclasses_1 = require("../../generated/entity_subclasses");
|
|
13
|
+
const ResourcePermissionEngine_1 = require("./ResourcePermissionEngine");
|
|
14
|
+
/**
|
|
15
|
+
* Subclass for the Resource Permissiosn entity that implements some workflow logic
|
|
16
|
+
*/
|
|
17
|
+
let ResourcePermissionEntityExtended = class ResourcePermissionEntityExtended extends entity_subclasses_1.ResourcePermissionEntity {
|
|
18
|
+
/**
|
|
19
|
+
* This override encapsulates some busienss logic for the Resource Permissions entity as follows:
|
|
20
|
+
* 1) Whenever a new permission record is created that has a status of "Requested", we generate a new Notifications record for the owner of the resource being requested
|
|
21
|
+
* 2) Whenever a permisison record has a status that changes from "Requested" to something else, we notify the user who requested access to the resource
|
|
22
|
+
* We only do this logic when we're on the server side to avoid redundancy of notifications
|
|
23
|
+
* @param options
|
|
24
|
+
*/
|
|
25
|
+
async Save(options) {
|
|
26
|
+
const md = new core_1.Metadata();
|
|
27
|
+
if (md.ProviderType === 'Database') {
|
|
28
|
+
// operating on the server side so we can do the notification logic
|
|
29
|
+
// first check to see if we're a new record and the status is "Requested"
|
|
30
|
+
const newRequest = !this.IsSaved && this.Status === 'Requested';
|
|
31
|
+
const statusField = this.Fields.find(f => f.Name.trim().toLowerCase() === 'status');
|
|
32
|
+
const statusChangedfromRequested = this.IsSaved && statusField.Dirty && statusField.OldValue.trim().toLowerCase() === 'requested';
|
|
33
|
+
// just in case, config the engine but it probably already has been configured in which case nothing will happen
|
|
34
|
+
await ResourcePermissionEngine_1.ResourcePermissionEngine.Instance.Config(false, this.ContextCurrentUser);
|
|
35
|
+
const rt = ResourcePermissionEngine_1.ResourcePermissionEngine.Instance.ResourceTypes.find((rt) => rt.ID === this.ResourceTypeID);
|
|
36
|
+
const rtEntityRecord = ResourcePermissionEngine_1.ResourcePermissionEngine.Instance.ResourceTypes.find((rt) => rt.Name.trim().toLowerCase() === "records");
|
|
37
|
+
// now get the field names for the given resource type based on its entity metadata with this helper method in the engine
|
|
38
|
+
const resourceTypeFields = ResourcePermissionEngine_1.ResourcePermissionEngine.Instance.GetResourceTypeInfoFields(this.ResourceTypeID);
|
|
39
|
+
if (resourceTypeFields && resourceTypeFields.NameFieldName && resourceTypeFields.OwnerIDFieldName) {
|
|
40
|
+
// grab the data from the resource record itself so we have it for the notification so it is easy for the user to read
|
|
41
|
+
const resourceRecord = await md.GetEntityObject(rt.Entity, this.ContextCurrentUser);
|
|
42
|
+
const ck = new core_1.CompositeKey([
|
|
43
|
+
{
|
|
44
|
+
FieldName: resourceTypeFields.PrimaryKeyFieldName,
|
|
45
|
+
Value: this.ResourceRecordID
|
|
46
|
+
}
|
|
47
|
+
]);
|
|
48
|
+
await resourceRecord.InnerLoad(ck);
|
|
49
|
+
// we have the resource record (e.g. the User View, Dashboard, Report, etc)
|
|
50
|
+
// now grab the record name and owner from it
|
|
51
|
+
const recordName = resourceRecord.Get(resourceTypeFields.NameFieldName);
|
|
52
|
+
const recordOwnerID = resourceRecord.Get(resourceTypeFields.OwnerIDFieldName);
|
|
53
|
+
// we now have our cached state values of newRequest and statusChanged and can proceed with the logic below
|
|
54
|
+
// after we call super.Save() to actually save the record
|
|
55
|
+
if (await super.Save(options)) {
|
|
56
|
+
// now proceed with workflow logic if we saved
|
|
57
|
+
const notification = await md.GetEntityObject('User Notifications', this.ContextCurrentUser);
|
|
58
|
+
if (newRequest) {
|
|
59
|
+
// notify the owner of the resource that a new request was made
|
|
60
|
+
const user = await md.GetEntityObject('Users', this.ContextCurrentUser);
|
|
61
|
+
await user.Load(this.UserID);
|
|
62
|
+
notification.Title = `New Request for Access to ${this.ResourceType}`;
|
|
63
|
+
notification.Message = `A new request for access to ${this.ResourceType} record "${recordName}" has been made by ${user.Name} (${user.Email})`;
|
|
64
|
+
notification.ResourceTypeID = rtEntityRecord.ID; // the resource type here is Entity Record which means that the user who gets this notification can easily click on THIS record to approve/reject/etc
|
|
65
|
+
notification.ResourceRecordID = this.ID;
|
|
66
|
+
notification.ResourceConfiguration = JSON.stringify({
|
|
67
|
+
Entity: "Resource Permissions",
|
|
68
|
+
ResourceRecordID: this.ResourceRecordID, // saving the resource record here to make it easy to find the request from the notification
|
|
69
|
+
ResourcePermissionID: this.ID // saving the resource permission here to make it easy to find the request from the notification
|
|
70
|
+
});
|
|
71
|
+
notification.UserID = recordOwnerID;
|
|
72
|
+
}
|
|
73
|
+
else if (statusChangedfromRequested) {
|
|
74
|
+
// notify the user who requested access that their request was approved or denied
|
|
75
|
+
notification.UserID = this.UserID;
|
|
76
|
+
notification.Title = `Request for Access to ${this.ResourceType} ${this.Status}`;
|
|
77
|
+
notification.Message = `Your request for access to ${this.ResourceType} record "${recordName}" has been ${this.Status}`;
|
|
78
|
+
notification.ResourceTypeID = this.ResourceTypeID;
|
|
79
|
+
notification.ResourceRecordID = this.ResourceRecordID;
|
|
80
|
+
notification.ResourceConfiguration = JSON.stringify({
|
|
81
|
+
ResourcePermissionID: this.ID // saving the resource permission here to make it easy to find the request from the notification
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return await notification.Save();
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return false; // don't do workflow as the save failed
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error(`Resource Type ${rt.Name} does not have the required fields for ResourceTypeInfoFields`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// call the super class to do the actual save
|
|
96
|
+
return super.Save(options);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
exports.ResourcePermissionEntityExtended = ResourcePermissionEntityExtended;
|
|
101
|
+
exports.ResourcePermissionEntityExtended = ResourcePermissionEntityExtended = __decorate([
|
|
102
|
+
(0, global_1.RegisterClass)(core_1.BaseEntity, 'Resource Permissions')
|
|
103
|
+
], ResourcePermissionEntityExtended);
|
|
104
|
+
//# sourceMappingURL=ResourcePermissionSubclass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourcePermissionSubclass.js","sourceRoot":"","sources":["../../../src/custom/ResourcePermissions/ResourcePermissionSubclass.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+CAAuG;AACvG,mDAAuD;AACvD,yEAAiH;AACjH,yEAAsE;AAEtE;;GAEG;AAEI,IAAM,gCAAgC,GAAtC,MAAM,gCAAiC,SAAQ,4CAAwB;IAC1E;;;;;;OAMG;IACM,KAAK,CAAC,IAAI,CAAC,OAA2B;QAC3C,MAAM,EAAE,GAAG,IAAI,eAAQ,EAAE,CAA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5C,IAAA,sBAAa,EAAC,iBAAU,EAAE,sBAAsB,CAAC;GACrC,gCAAgC,CAsF5C"}
|
|
@@ -27,7 +27,43 @@ export declare class UserViewEntityExtended extends UserViewEntity {
|
|
|
27
27
|
get ViewSortInfo(): ViewSortInfo[];
|
|
28
28
|
get OrderByClause(): string;
|
|
29
29
|
LoadFromData(data: any): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* This property determines if the specified user can edit the view object. All of the below assumes the user has base Create/Update permissions on the "User Views" entity.
|
|
32
|
+
* The flow of the logic is:
|
|
33
|
+
* 1) The view is a new record, by definition the user can edit this because it is new
|
|
34
|
+
* 2) The user is the owner of the current view - e.g. UserID in the view record matches the ID of the user provided, allowed
|
|
35
|
+
* 3) The user is a sysadmin (Type === 'Owner' in the User object), allowed
|
|
36
|
+
* 4) If neither of the above conditions are met, the Resource Permissions are checked to see if the user, directly or via Roles, has either Edit or Owner permissions on the current view
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
get UserCanEdit(): boolean;
|
|
40
|
+
private _cachedCanUserEdit;
|
|
41
|
+
/**
|
|
42
|
+
* This property determines if the specified user can view the view at all.
|
|
43
|
+
*/
|
|
44
|
+
get UserCanView(): boolean;
|
|
45
|
+
private CalculateUserCanView;
|
|
46
|
+
private _cachedCanUserView;
|
|
47
|
+
/**
|
|
48
|
+
* This property determines if the specified user can delete the view object. All of the below assumes the user has base Delete permissions on the "User Views" entity.
|
|
49
|
+
* The flow of the logic is:
|
|
50
|
+
* 1) The view is a new record, by definition the user can't delete this because it is new
|
|
51
|
+
* 2) The user is the owner of the current view - e.g. UserID in the view record matches the ID of the user provided, allowed
|
|
52
|
+
* 3) The user is a sysadmin (Type === 'Owner' in the User object), allowed
|
|
53
|
+
* 4) If neither of the above conditions are met, the Resource Permissions are checked to see if the user, directly or via Roles, has OWNER permissions on the current view
|
|
54
|
+
*/
|
|
55
|
+
get UserCanDelete(): boolean;
|
|
56
|
+
private _cachedUserCanDelete;
|
|
57
|
+
protected ResetCachedCanUserSettings(): void;
|
|
58
|
+
private CalculateUserCanDelete;
|
|
59
|
+
private CalculateUserCanEdit;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the ID of the Resource Type metadata record that corresponds to the User Views entity
|
|
62
|
+
*/
|
|
63
|
+
get ViewResourceTypeID(): string;
|
|
64
|
+
private _ViewResourceTypeID;
|
|
30
65
|
Load(ID: string, EntityRelationshipsToLoad?: string[]): Promise<boolean>;
|
|
66
|
+
Delete(): Promise<boolean>;
|
|
31
67
|
Save(options?: EntitySaveOptions): Promise<boolean>;
|
|
32
68
|
SetDefaultsFromEntity(e: EntityInfo): Promise<void>;
|
|
33
69
|
NewRecord(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserViewEntity.d.ts","sourceRoot":"","sources":["../../src/custom/UserViewEntity.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAU,QAAQ,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"UserViewEntity.d.ts","sourceRoot":"","sources":["../../src/custom/UserViewEntity.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAU,QAAQ,EAAE,iBAAiB,EAAuE,MAAM,sBAAsB,CAAC;AAC7M,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAIhE,qBACa,sBAAuB,SAAQ,cAAc;IACtD,OAAO,CAAC,eAAe,CAAmB;IAE1C;;;;;;;OAOG;IACH,IAAW,MAAM,IAAI,cAAc,EAAE,CAMpC;IAED;;;;OAIG;IACH,IAAW,OAAO,IAAI,cAAc,EAAE,CAwBrC;IAED;;;;;OAKG;IACH,IAAW,cAAc,IAAI,UAAU,CAEtC;IAED,IAAW,YAAY,IAAI,YAAY,EAAE,CAQxC;IAED,IAAW,aAAa,IAAI,MAAM,CAmBjC;IAEQ,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG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