@memberjunction/core-entities 6.2.0-edge.6 → 6.2.0-edge.8
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/.tsbuildinfo +1 -1
- package/dist/custom/AnchoredConversationSecurity.d.ts +103 -0
- package/dist/custom/AnchoredConversationSecurity.d.ts.map +1 -0
- package/dist/custom/AnchoredConversationSecurity.js +401 -0
- package/dist/custom/AnchoredConversationSecurity.js.map +1 -0
- package/dist/custom/ConversationWriteAccess.d.ts +11 -3
- package/dist/custom/ConversationWriteAccess.d.ts.map +1 -1
- package/dist/custom/ConversationWriteAccess.js +100 -9
- package/dist/custom/ConversationWriteAccess.js.map +1 -1
- package/dist/custom/MJConversationDetailEntityExtended.d.ts.map +1 -1
- package/dist/custom/MJConversationDetailEntityExtended.js +18 -1
- package/dist/custom/MJConversationDetailEntityExtended.js.map +1 -1
- package/dist/custom/MJProjectEntityExtended.d.ts +12 -0
- package/dist/custom/MJProjectEntityExtended.d.ts.map +1 -0
- package/dist/custom/MJProjectEntityExtended.js +35 -0
- package/dist/custom/MJProjectEntityExtended.js.map +1 -0
- package/dist/custom/MJQueryEntityExtended.d.ts +56 -14
- package/dist/custom/MJQueryEntityExtended.d.ts.map +1 -1
- package/dist/custom/MJQueryEntityExtended.js +99 -15
- package/dist/custom/MJQueryEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js +3 -0
- package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js +2 -0
- package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js.map +1 -1
- package/dist/custom/Permissions/index.d.ts +1 -0
- package/dist/custom/Permissions/index.d.ts.map +1 -1
- package/dist/custom/Permissions/index.js +1 -0
- package/dist/custom/Permissions/index.js.map +1 -1
- package/dist/custom/Permissions/mentionNotification.d.ts +64 -0
- package/dist/custom/Permissions/mentionNotification.d.ts.map +1 -0
- package/dist/custom/Permissions/mentionNotification.js +315 -0
- package/dist/custom/Permissions/mentionNotification.js.map +1 -0
- package/dist/custom/QueryDiagnostics.d.ts +66 -0
- package/dist/custom/QueryDiagnostics.d.ts.map +1 -0
- package/dist/custom/QueryDiagnostics.js +84 -0
- package/dist/custom/QueryDiagnostics.js.map +1 -0
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.d.ts.map +1 -1
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js +12 -4
- package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js.map +1 -1
- package/dist/custom/ResourcePermissions/ResourcePermissionEngine.d.ts.map +1 -1
- package/dist/custom/ResourcePermissions/ResourcePermissionEngine.js +11 -2
- package/dist/custom/ResourcePermissions/ResourcePermissionEngine.js.map +1 -1
- package/dist/engines/BrandKitEngine.d.ts +77 -0
- package/dist/engines/BrandKitEngine.d.ts.map +1 -0
- package/dist/engines/BrandKitEngine.js +199 -0
- package/dist/engines/BrandKitEngine.js.map +1 -0
- package/dist/engines/QueryEngine.d.ts +22 -4
- package/dist/engines/QueryEngine.d.ts.map +1 -1
- package/dist/engines/QueryEngine.js +61 -8
- package/dist/engines/QueryEngine.js.map +1 -1
- package/dist/engines/RemoteOperationEngineBase.d.ts +5 -0
- package/dist/engines/RemoteOperationEngineBase.d.ts.map +1 -1
- package/dist/engines/RemoteOperationEngineBase.js +21 -1
- package/dist/engines/RemoteOperationEngineBase.js.map +1 -1
- package/dist/engines/VideoStudioEngine.d.ts +28 -0
- package/dist/engines/VideoStudioEngine.d.ts.map +1 -0
- package/dist/engines/VideoStudioEngine.js +75 -0
- package/dist/engines/VideoStudioEngine.js.map +1 -0
- package/dist/engines/component-metadata.d.ts.map +1 -1
- package/dist/engines/component-metadata.js +1 -0
- package/dist/engines/component-metadata.js.map +1 -1
- package/dist/engines/conversations.d.ts +327 -14
- package/dist/engines/conversations.d.ts.map +1 -1
- package/dist/engines/conversations.js +919 -52
- package/dist/engines/conversations.js.map +1 -1
- package/dist/engines/interactive-forms.d.ts.map +1 -1
- package/dist/engines/interactive-forms.js +1 -0
- package/dist/engines/interactive-forms.js.map +1 -1
- package/dist/generated/entities/__mj.d.ts +11147 -7017
- package/dist/generated/entities/__mj.d.ts.map +1 -1
- package/dist/generated/entities/__mj.js +5792 -555
- package/dist/generated/entities/__mj.js.map +1 -1
- package/dist/generated/remote_operations.d.ts +450 -0
- package/dist/generated/remote_operations.d.ts.map +1 -1
- package/dist/generated/remote_operations.js +288 -0
- package/dist/generated/remote_operations.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,11 +1,40 @@
|
|
|
1
1
|
import { UUIDsEqual } from '@memberjunction/global';
|
|
2
|
+
import { IsConversationHiddenByFieldSecurity, UserCanReadLinkedRecord } from './AnchoredConversationSecurity.js';
|
|
2
3
|
import { ResourcePermissionEngine } from './ResourcePermissions/ResourcePermissionEngine.js';
|
|
3
4
|
/** Resource type ID for conversations in the resource permission system. */
|
|
4
5
|
export const CONVERSATIONS_RESOURCE_TYPE_ID = '81D4BC3D-9FEB-EF11-B01A-286B35C04427';
|
|
6
|
+
/** Resource type ID for conversation folders (`MJ: Projects`) in the resource permission system. */
|
|
7
|
+
const PROJECTS_RESOURCE_TYPE_ID = '88D0DF27-AF8F-43AC-9EC4-2AC314F49355';
|
|
5
8
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
+
* Returns whether a conversation inherits access from its folder (`ProjectID`).
|
|
10
|
+
* Inheritance is opt-in: it is on only when `AdditionalData` sets `"inheritFolderAccess": true`.
|
|
11
|
+
* A local copy of the engine's `IsInheritingFolderAccess`: importing the engine module here would pull it
|
|
12
|
+
* into every entity subclass that checks write access.
|
|
13
|
+
*/
|
|
14
|
+
function IsInheritingFolderAccess(conversation) {
|
|
15
|
+
const raw = conversation?.AdditionalData;
|
|
16
|
+
if (!raw || typeof raw !== 'string')
|
|
17
|
+
return false;
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(raw);
|
|
20
|
+
return parsed?.['inheritFolderAccess'] === true;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return /"inheritFolderAccess"\s*:\s*true/.test(raw);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Whether a user may write rows that belong to a conversation:
|
|
28
|
+
* - For anchored record/artifact comment threads (`AnchorType != null` with `LinkedEntityID` and `LinkedRecordID`),
|
|
29
|
+
* any user who can read the linked record (including RLS) and is not denied read access on the anchored field
|
|
30
|
+
* or `restrictedFields` (FLS) may post and reply in the thread.
|
|
31
|
+
* - For standard chat conversations (`AnchorType == null`), the conversation owner, a user with an
|
|
32
|
+
* explicit `Edit`/`Owner` grant on the conversation, or (when {@link IsInheritingFolderAccess}
|
|
33
|
+
* is true) a user with an `Edit`/`Owner` grant on the conversation's folder (`MJ: Projects`).
|
|
34
|
+
* Conversations inside a Public folder (`Project.OwnerUserID IS NULL`) or a Shared folder with
|
|
35
|
+
* `View` access grant View-only access unless an explicit `Edit`/`Owner` grant says otherwise.
|
|
36
|
+
*
|
|
37
|
+
* Server-side only; a non-database provider trusts the enforcement that already ran upstream.
|
|
9
38
|
*/
|
|
10
39
|
export async function UserMayWriteConversation(provider, user, conversationId) {
|
|
11
40
|
if (provider?.ProviderType !== 'Database' || !user) {
|
|
@@ -15,7 +44,51 @@ export async function UserMayWriteConversation(provider, user, conversationId) {
|
|
|
15
44
|
if (!(await conversation.Load(conversationId))) {
|
|
16
45
|
return { Allowed: true, Reason: null, IsOwner: false, Loaded: false };
|
|
17
46
|
}
|
|
18
|
-
|
|
47
|
+
const isOwner = Boolean(conversation.UserID && UUIDsEqual(conversation.UserID, user.ID));
|
|
48
|
+
if (conversation.AnchorType != null && conversation.LinkedEntityID && conversation.LinkedRecordID) {
|
|
49
|
+
const entityInfo = (typeof provider.EntityByID === 'function'
|
|
50
|
+
? provider.EntityByID(conversation.LinkedEntityID)
|
|
51
|
+
: undefined) ??
|
|
52
|
+
provider.Entities?.find((e) => UUIDsEqual(e.ID, conversation.LinkedEntityID)) ??
|
|
53
|
+
null;
|
|
54
|
+
if (entityInfo) {
|
|
55
|
+
if (entityInfo.AllowRecordComments === false) {
|
|
56
|
+
return {
|
|
57
|
+
Allowed: false,
|
|
58
|
+
Reason: `Record commenting is disabled for ${entityInfo.DisplayNameOrName}.`,
|
|
59
|
+
IsOwner: isOwner,
|
|
60
|
+
Loaded: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (typeof entityInfo.CanUserComment === 'function' && !entityInfo.CanUserComment(user)) {
|
|
64
|
+
return {
|
|
65
|
+
Allowed: false,
|
|
66
|
+
Reason: `You do not have permission to post comments on ${entityInfo.DisplayNameOrName} records.`,
|
|
67
|
+
IsOwner: isOwner,
|
|
68
|
+
Loaded: true
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const recordAccess = await UserCanReadLinkedRecord(provider, user, conversation.LinkedEntityID, conversation.LinkedRecordID);
|
|
73
|
+
if (!recordAccess.Allowed || !recordAccess.EntityInfo) {
|
|
74
|
+
return {
|
|
75
|
+
Allowed: false,
|
|
76
|
+
Reason: recordAccess.Reason ?? 'You do not have access to the linked record.',
|
|
77
|
+
IsOwner: isOwner,
|
|
78
|
+
Loaded: true
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (IsConversationHiddenByFieldSecurity(recordAccess.EntityInfo, user, conversation.AnchorType, conversation.AnchorKey, conversation.AnchorMetadataObject ?? conversation.AnchorMetadata)) {
|
|
82
|
+
return {
|
|
83
|
+
Allowed: false,
|
|
84
|
+
Reason: 'You do not have permission to access the field referenced by this comment thread.',
|
|
85
|
+
IsOwner: isOwner,
|
|
86
|
+
Loaded: true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return { Allowed: true, Reason: null, IsOwner: isOwner, Loaded: true };
|
|
90
|
+
}
|
|
91
|
+
if (isOwner) {
|
|
19
92
|
return { Allowed: true, Reason: null, IsOwner: true, Loaded: true };
|
|
20
93
|
}
|
|
21
94
|
const engine = ResourcePermissionEngine.GetProviderInstance(provider, ResourcePermissionEngine);
|
|
@@ -23,12 +96,30 @@ export async function UserMayWriteConversation(provider, user, conversationId) {
|
|
|
23
96
|
const grant = engine
|
|
24
97
|
.GetUserAvailableResources(user, CONVERSATIONS_RESOURCE_TYPE_ID)
|
|
25
98
|
.find((p) => UUIDsEqual(p.ResourceRecordID, conversationId));
|
|
26
|
-
if (
|
|
27
|
-
return { Allowed: false, Reason: 'You do not have access to this conversation.', IsOwner: false, Loaded: true };
|
|
28
|
-
}
|
|
29
|
-
if (grant.PermissionLevel === 'Edit' || grant.PermissionLevel === 'Owner') {
|
|
99
|
+
if (grant && (grant.PermissionLevel === 'Edit' || grant.PermissionLevel === 'Owner')) {
|
|
30
100
|
return { Allowed: true, Reason: null, IsOwner: false, Loaded: true };
|
|
31
101
|
}
|
|
32
|
-
|
|
102
|
+
let hasViewAccess = grant?.PermissionLevel === 'View';
|
|
103
|
+
if (conversation.ProjectID && IsInheritingFolderAccess(conversation)) {
|
|
104
|
+
const folderPerm = engine.GetUserResourcePermissionLevel?.(PROJECTS_RESOURCE_TYPE_ID, conversation.ProjectID, user);
|
|
105
|
+
if (folderPerm === 'Edit' || folderPerm === 'Owner') {
|
|
106
|
+
return { Allowed: true, Reason: null, IsOwner: false, Loaded: true };
|
|
107
|
+
}
|
|
108
|
+
if (folderPerm === 'View') {
|
|
109
|
+
hasViewAccess = true;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const project = await provider.GetEntityObject('MJ: Projects', user);
|
|
113
|
+
if (await project.Load(conversation.ProjectID)) {
|
|
114
|
+
if (!project.OwnerUserID || (project.OwnerUserID && UUIDsEqual(project.OwnerUserID, user.ID))) {
|
|
115
|
+
hasViewAccess = true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (hasViewAccess) {
|
|
121
|
+
return { Allowed: false, Reason: 'You have view-only access to this conversation.', IsOwner: false, Loaded: true };
|
|
122
|
+
}
|
|
123
|
+
return { Allowed: false, Reason: 'You do not have access to this conversation.', IsOwner: false, Loaded: true };
|
|
33
124
|
}
|
|
34
125
|
//# sourceMappingURL=ConversationWriteAccess.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationWriteAccess.js","sourceRoot":"","sources":["../../src/custom/ConversationWriteAccess.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAE1F,4EAA4E;AAC5E,MAAM,CAAC,MAAM,8BAA8B,GAAG,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"ConversationWriteAccess.js","sourceRoot":"","sources":["../../src/custom/ConversationWriteAccess.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,mCAAmC,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC9G,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAE1F,4EAA4E;AAC5E,MAAM,CAAC,MAAM,8BAA8B,GAAG,sCAAsC,CAAC;AAErF,oGAAoG;AACpG,MAAM,yBAAyB,GAAG,sCAAsC,CAAC;AAEzE;;;;;GAKG;AACH,SAAS,wBAAwB,CAC7B,YAAmE;IAEnE,MAAM,GAAG,GAAG,YAAY,EAAE,cAAc,CAAC;IACzC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAA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AM,UAAU,GAAG,MAAM,CAAC,8BAA8B,EAAE,CACtD,yBAAyB,EACzB,YAAY,CAAC,SAAS,EACtB,IAAI,CACP,CAAC;QACF,IAAI,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;YAClD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACzE,CAAC;QACD,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;YACxB,aAAa,GAAG,IAAI,CAAC;QACzB,CAAC;aAAM,CAAC;YACJ,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,eAAe,CAAkB,cAAc,EAAE,IAAI,CAAC,CAAC;YACtF,IAAI,MAAM,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC7C,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,UAAU,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;oBAC5F,aAAa,GAAG,IAAI,CAAC;gBACzB,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IAED,IAAI,aAAa,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,iDAAiD,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACvH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,8CAA8C,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AACpH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MJConversationDetailEntityExtended.d.ts","sourceRoot":"","sources":["../../src/custom/MJConversationDetailEntityExtended.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,mBAAmB,EAEnB,iBAAiB,EAKpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,0BAA0B,EAAwB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"MJConversationDetailEntityExtended.d.ts","sourceRoot":"","sources":["../../src/custom/MJConversationDetailEntityExtended.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,mBAAmB,EAEnB,iBAAiB,EAKpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,0BAA0B,EAAwB,MAAM,gCAAgC,CAAC;AAwFlG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,qBACa,kCAAmC,SAAQ,0BAA0B;IAC9E,OAAO,CAAC,mBAAmB,CAAS;IAEpC;;;;;;;OAOG;IACI,uBAAuB,IAAI,IAAI;IAItC,2EAA2E;IAC3E,IAAW,qBAAqB,IAAI,OAAO,CAE1C;IAEc,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;IA6BnD,MAAM,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;YAOxD,mBAAmB;IA2DjC;;;;;;OAMG;YACW,aAAa;IAoB3B;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAWpB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAOzB,wGAAwG;IACxG,OAAO,CAAC,WAAW;IAgBnB;;;OAGG;IACH,OAAO,CAAC,aAAa;IA2BrB,iHAAiH;IACjH,OAAO,CAAC,aAAa;IASrB,2GAA2G;YAC7F,kBAAkB;IAahC;;;OAGG;IACH,OAAO,CAAC,6BAA6B;IAOrC,OAAO,CAAC,YAAY;IAIpB,sGAAsG;IACtG,OAAO,CAAC,iBAAiB;IAKzB;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;CASvB;AAED,6FAA6F;AAC7F,wBAAgB,sCAAsC,IAAI,IAAI,CAE7D"}
|
|
@@ -8,6 +8,7 @@ import { BaseEntity, BaseEntityResult, EntityFieldInfo, LogError, WellKnownUserS
|
|
|
8
8
|
import { RegisterClass, UUIDsEqual } from '@memberjunction/global';
|
|
9
9
|
import { MJConversationDetailEntity } from '../generated/entity_subclasses.js';
|
|
10
10
|
import { UserMayWriteConversation } from './ConversationWriteAccess.js';
|
|
11
|
+
import { DispatchConversationMentionNotifications } from './Permissions/mentionNotification.js';
|
|
11
12
|
/**
|
|
12
13
|
* Fields that represent the conversation owner's evaluation of an AI message.
|
|
13
14
|
* Storage is a single value per message (no per-user rating column), so only
|
|
@@ -150,14 +151,30 @@ let MJConversationDetailEntityExtended = class MJConversationDetailEntityExtende
|
|
|
150
151
|
}
|
|
151
152
|
async Save(options) {
|
|
152
153
|
const callerUserID = this.UserID; // the gate may fill in a grantee's; a save that fails keeps the caller's
|
|
154
|
+
const wasSaved = this.IsSaved;
|
|
155
|
+
const previousMessage = wasSaved ? this.originalFieldText('Message') : null;
|
|
153
156
|
if (!(await this.currentUserMayWrite('save'))) {
|
|
154
157
|
return false;
|
|
155
158
|
}
|
|
156
159
|
const saved = await super.Save(options);
|
|
157
160
|
if (!saved) {
|
|
158
161
|
this.UserID = callerUserID;
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const provider = this.ProviderToUse;
|
|
165
|
+
const user = this.ContextCurrentUser;
|
|
166
|
+
if (provider?.ProviderType === 'Database' && user && isPersonRole(this.Role) && this.Message) {
|
|
167
|
+
await DispatchConversationMentionNotifications({
|
|
168
|
+
Provider: provider,
|
|
169
|
+
ContextUser: user,
|
|
170
|
+
ConversationID: this.ConversationID,
|
|
171
|
+
ConversationDetailID: this.ID,
|
|
172
|
+
AuthorUserID: this.UserID || user.ID,
|
|
173
|
+
Message: this.Message,
|
|
174
|
+
PreviousMessage: wasSaved ? previousMessage : null
|
|
175
|
+
});
|
|
159
176
|
}
|
|
160
|
-
return
|
|
177
|
+
return true;
|
|
161
178
|
}
|
|
162
179
|
async Delete(options) {
|
|
163
180
|
if (!(await this.currentUserMayWrite('delete'))) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MJConversationDetailEntityExtended.js","sourceRoot":"","sources":["../../src/custom/MJConversationDetailEntityExtended.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,UAAU,EACV,gBAAgB,EAEhB,eAAe,EAGf,QAAQ,EAER,mBAAmB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAwB,MAAM,gCAAgC,CAAC;AAClG,OAAO,EAA6B,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"MJConversationDetailEntityExtended.js","sourceRoot":"","sources":["../../src/custom/MJConversationDetailEntityExtended.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,UAAU,EACV,gBAAgB,EAEhB,eAAe,EAGf,QAAQ,EAER,mBAAmB,EACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAwB,MAAM,gCAAgC,CAAC;AAClG,OAAO,EAA6B,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAChG,OAAO,EAAE,wCAAwC,EAAE,MAAM,mCAAmC,CAAC;AAE7F;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAElH;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,mBAA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AAC,EAAE,KAAK,CAAC;IAC9C,CAAC;IAED,sGAAsG;IAC9F,iBAAiB,CAAC,IAAY;QAClC,MAAM,QAAQ,GAAY,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;QAC9D,OAAO,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACjF,CAAC;IAED;;;;;;;;OAQG;IACK,YAAY,CAAC,OAAe,EAAE,IAAoC;QACtE,MAAM,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACtC,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC;QACvB,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;QACnB,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;QACzB,MAAM,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC9B,MAAM,CAAC,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;CACJ,CAAA;AAxRY,kCAAkC;IAD9C,aAAa,CAAC,UAAU,EAAE,0BAA0B,CAAC;GACzC,kCAAkC,CAwR9C;;AAED,6FAA6F;AAC7F,MAAM,UAAU,sCAAsC;IAClD,sBAAsB;AAC1B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MJProjectEntity } from '../generated/entity_subclasses.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extended subclass for `MJ: Projects` (conversation folders).
|
|
4
|
+
*
|
|
5
|
+
* Defaults new folders to private (`OwnerUserID = currentUser.ID`) so every
|
|
6
|
+
* newly created folder is personal unless the caller explicitly clears
|
|
7
|
+
* `OwnerUserID = null` to create a shared folder.
|
|
8
|
+
*/
|
|
9
|
+
export declare class MJProjectEntityExtended extends MJProjectEntity {
|
|
10
|
+
NewRecord(): boolean;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=MJProjectEntityExtended.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MJProjectEntityExtended.d.ts","sourceRoot":"","sources":["../../src/custom/MJProjectEntityExtended.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE;;;;;;GAMG;AACH,qBACa,uBAAwB,SAAQ,eAAe;IACxC,SAAS,IAAI,OAAO;CAavC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
8
|
+
import { BaseEntity } from '@memberjunction/core';
|
|
9
|
+
import { MJProjectEntity } from '../generated/entity_subclasses.js';
|
|
10
|
+
/**
|
|
11
|
+
* Extended subclass for `MJ: Projects` (conversation folders).
|
|
12
|
+
*
|
|
13
|
+
* Defaults new folders to private (`OwnerUserID = currentUser.ID`) so every
|
|
14
|
+
* newly created folder is personal unless the caller explicitly clears
|
|
15
|
+
* `OwnerUserID = null` to create a shared folder.
|
|
16
|
+
*/
|
|
17
|
+
let MJProjectEntityExtended = class MJProjectEntityExtended extends MJProjectEntity {
|
|
18
|
+
NewRecord() {
|
|
19
|
+
const result = super.NewRecord();
|
|
20
|
+
if (result) {
|
|
21
|
+
const currentUserId = this.ContextCurrentUser?.ID ??
|
|
22
|
+
this.ProviderToUse?.CurrentUser?.ID;
|
|
23
|
+
if (currentUserId) {
|
|
24
|
+
this.OwnerUserID = currentUserId;
|
|
25
|
+
this.GetFieldByName('OwnerUserID')?.ResetNeverSetFlag();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
MJProjectEntityExtended = __decorate([
|
|
32
|
+
RegisterClass(BaseEntity, 'MJ: Projects')
|
|
33
|
+
], MJProjectEntityExtended);
|
|
34
|
+
export { MJProjectEntityExtended };
|
|
35
|
+
//# sourceMappingURL=MJProjectEntityExtended.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MJProjectEntityExtended.js","sourceRoot":"","sources":["../../src/custom/MJProjectEntityExtended.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAqB,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE;;;;;;GAMG;AAEI,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,eAAe;IACxC,SAAS;QACrB,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QACjC,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,aAAa,GACf,IAAI,CAAC,kBAAkB,EAAE,EAAE;gBAC1B,IAAI,CAAC,aAA0D,EAAE,WAAW,EAAE,EAAE,CAAC;YACtF,IAAI,aAAa,EAAE,CAAC;gBAChB,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC;gBACjC,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,iBAAiB,EAAE,CAAC;YAC5D,CAAC;QACL,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ,CAAA;AAdY,uBAAuB;IADnC,aAAa,CAAC,UAAU,EAAE,cAAc,CAAC;GAC7B,uBAAuB,CAcnC"}
|
|
@@ -2,6 +2,29 @@ import { UserInfo, QueryCacheConfig, EntityInfo, FieldSecurityViolation } from "
|
|
|
2
2
|
import { SQLScreeningDialect } from "@memberjunction/global";
|
|
3
3
|
import { MJQueryEntity, MJQueryFieldEntity, MJQueryParameterEntity, MJQueryEntityEntity, MJQueryPermissionEntity, MJQueryDependencyEntity, MJQueryCategoryEntity } from "../generated/entity_subclasses.js";
|
|
4
4
|
import type { DatabasePlatform } from "@memberjunction/core";
|
|
5
|
+
/** Options for {@link MJQueryEntityExtended.UserCanRunRenderedSQL}. */
|
|
6
|
+
export interface RenderedSQLCheckOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The character offsets of the `*` of each projection star in the rendered SQL: a plain `*` or
|
|
9
|
+
* `alias.*` select item whose columns reach the caller only as output columns. Such stars are
|
|
10
|
+
* allowed; the denied columns they bring are dropped from the result by the caller.
|
|
11
|
+
*/
|
|
12
|
+
ProjectionStarOffsets?: ReadonlySet<number>;
|
|
13
|
+
}
|
|
14
|
+
/** The result of {@link MJQueryEntityExtended.UserCanRunRenderedSQL}. */
|
|
15
|
+
export interface RenderedSQLCheckResult {
|
|
16
|
+
/** Whether the user may run this rendering of the query. */
|
|
17
|
+
canRun: boolean;
|
|
18
|
+
/** Entities the SQL reads that the user may not read. Never shown to the user. */
|
|
19
|
+
deniedEntities: string[];
|
|
20
|
+
/** The field-level security finding behind a refusal, for logging. */
|
|
21
|
+
fieldSecurityViolation?: FieldSecurityViolation;
|
|
22
|
+
/**
|
|
23
|
+
* True when the query may run but a projection star can bring a column the user is denied:
|
|
24
|
+
* the caller must drop the denied columns from the rows before returning them.
|
|
25
|
+
*/
|
|
26
|
+
needsColumnFiltering?: boolean;
|
|
27
|
+
}
|
|
5
28
|
/**
|
|
6
29
|
* Extended query entity with child-relationship getters and business logic.
|
|
7
30
|
* All child data reads through `QueryEngine`'s event-driven cache — always
|
|
@@ -11,8 +34,25 @@ import type { DatabasePlatform } from "@memberjunction/core";
|
|
|
11
34
|
* extraction pipeline, dialect conversion) lives in `MJQueryEntityServer`.
|
|
12
35
|
*/
|
|
13
36
|
export declare class MJQueryEntityExtended extends MJQueryEntity {
|
|
37
|
+
/** Parameters declared with this query in a graph save (companion name `Parameters`). */
|
|
38
|
+
readonly DeclaredParameters: import("@memberjunction/core").RelatedRecordCollection<MJQueryParameterEntity>;
|
|
39
|
+
/** Output fields declared with this query in a graph save (companion name `Fields`). */
|
|
40
|
+
readonly DeclaredFields: import("@memberjunction/core").RelatedRecordCollection<MJQueryFieldEntity>;
|
|
41
|
+
/** Entity links declared with this query in a graph save (companion name `Entities`). */
|
|
42
|
+
readonly DeclaredEntities: import("@memberjunction/core").RelatedRecordCollection<MJQueryEntityEntity>;
|
|
14
43
|
/** All field definitions for this query */
|
|
15
44
|
get QueryFields(): MJQueryFieldEntity[];
|
|
45
|
+
/**
|
|
46
|
+
* The field definitions a user may see: every field of a query with `MJ: Query Permissions`
|
|
47
|
+
* rows (definer's rights, so the user receives every column), and otherwise the fields whose
|
|
48
|
+
* source entity field the user may read, plus those with no entity source. A column whose
|
|
49
|
+
* source the user may not read is left out of the results the user gets, so its definition is
|
|
50
|
+
* left out here too, and a UI listing these never names it.
|
|
51
|
+
*
|
|
52
|
+
* @param user The viewing user; with none, every field is returned (the server stays the boundary).
|
|
53
|
+
* @param catalog Every entity the provider knows, to resolve each field's source entity.
|
|
54
|
+
*/
|
|
55
|
+
QueryFieldsVisibleTo(user: UserInfo | null | undefined, catalog: readonly EntityInfo[]): MJQueryFieldEntity[];
|
|
16
56
|
/** All parameter definitions for this query */
|
|
17
57
|
get QueryParameters(): MJQueryParameterEntity[];
|
|
18
58
|
/** All entity associations for this query */
|
|
@@ -68,19 +108,24 @@ export declare class MJQueryEntityExtended extends MJQueryEntity {
|
|
|
68
108
|
* to {@link UserCanRun}, never instead of it.
|
|
69
109
|
*
|
|
70
110
|
* 1. A query with `MJ: Query Permissions` rows is authorized by its role list alone: a user who
|
|
71
|
-
* holds one of those roles may run it whatever it reads (
|
|
72
|
-
* who holds none may not.
|
|
111
|
+
* holds one of those roles may run it whatever it reads (definer's rights, like an EXECUTE
|
|
112
|
+
* grant on a stored procedure), and one who holds none may not. Field-level security does
|
|
113
|
+
* not apply to it.
|
|
73
114
|
* 2. Otherwise every entity whose base view or base table the SQL reads as a relation must be
|
|
74
115
|
* readable by the user ({@link FieldSecuritySQLGate.RelationEntities}). These come from the
|
|
75
116
|
* SQL, so a query whose `QueryEntities` rows are missing or stale is still checked. SQL that
|
|
76
117
|
* cannot be read is refused for a user who cannot read every entity in the catalog.
|
|
77
|
-
* 3. The SQL must not
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* field on, and SQL that cannot be read, are
|
|
81
|
-
* So is a relation that is not a
|
|
82
|
-
*
|
|
83
|
-
*
|
|
118
|
+
* 3. The SQL must not name a field the user is denied anywhere: the select list, WHERE, JOIN,
|
|
119
|
+
* GROUP BY, ORDER BY or HAVING, inside expressions and aggregates, through a CTE. A
|
|
120
|
+
* whole-row construct (`DISTINCT *`, set operations, `FOR JSON`, `row_to_json`, `NATURAL
|
|
121
|
+
* JOIN`, …) over an entity the user is denied a field on, and SQL that cannot be read, are
|
|
122
|
+
* refused too ({@link FieldSecuritySQLGate.FindViolation}). So is a relation that is not a
|
|
123
|
+
* CTE or a catalog entity's base view or base table, whose reads cannot be checked. A user
|
|
124
|
+
* denied no field on any entity is not scanned.
|
|
125
|
+
* 4. A plain `*` or `alias.*` that a structural reading of the statement has shown reaches the
|
|
126
|
+
* caller only as output columns (`options.ProjectionStarOffsets`) is not refused. The result
|
|
127
|
+
* then reports `needsColumnFiltering` when the user is denied a field on an entity the SQL
|
|
128
|
+
* reads: the caller must run the query and drop the denied columns from its rows.
|
|
84
129
|
*
|
|
85
130
|
* The result never names a denied field, so a refusal says only that the query cannot be run.
|
|
86
131
|
* `QueryFields` metadata plays no part: it is documentation, not a security source.
|
|
@@ -89,12 +134,9 @@ export declare class MJQueryEntityExtended extends MJQueryEntity {
|
|
|
89
134
|
* @param renderedSQL The SQL the run will execute
|
|
90
135
|
* @param catalog Every entity the executing provider knows
|
|
91
136
|
* @param dialect The database dialect the SQL runs under
|
|
137
|
+
* @param options The projection stars of `renderedSQL`, when the caller has read them
|
|
92
138
|
*/
|
|
93
|
-
UserCanRunRenderedSQL(user: UserInfo, renderedSQL: string, catalog: readonly EntityInfo[], dialect: SQLScreeningDialect):
|
|
94
|
-
canRun: boolean;
|
|
95
|
-
deniedEntities: string[];
|
|
96
|
-
fieldSecurityViolation?: FieldSecurityViolation;
|
|
97
|
-
};
|
|
139
|
+
UserCanRunRenderedSQL(user: UserInfo, renderedSQL: string, catalog: readonly EntityInfo[], dialect: SQLScreeningDialect, options?: RenderedSQLCheckOptions): RenderedSQLCheckResult;
|
|
98
140
|
/** The catalog entities this query's `QueryEntities` rows name; stale rows are left out. */
|
|
99
141
|
private declaredEntities;
|
|
100
142
|
/** Whether this query has been formally approved for production use */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MJQueryEntityExtended.d.ts","sourceRoot":"","sources":["../../src/custom/MJQueryEntityExtended.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,QAAQ,EAAE,gBAAgB,EAAqB,UAAU,EAAwB,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC3J,OAAO,EAA0C,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EACH,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACxB,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;;;;GAOG;AACH,qBACa,qBAAsB,SAAQ,aAAa;
|
|
1
|
+
{"version":3,"file":"MJQueryEntityExtended.d.ts","sourceRoot":"","sources":["../../src/custom/MJQueryEntityExtended.ts"],"names":[],"mappings":"AAAA,OAAO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ine } from "../engines/QueryEngine.js";
|
|
|
18
18
|
*/
|
|
19
19
|
let MJQueryEntityExtended = class MJQueryEntityExtended extends MJQueryEntity {
|
|
20
20
|
constructor() {
|
|
21
|
-
// ───
|
|
21
|
+
// ─── Declared child collections (graph saves) ───────────────────────────────
|
|
22
|
+
//
|
|
23
|
+
// These three collections let a caller save a query together with child rows it declares
|
|
24
|
+
// (hand-written parameters, fields and entity links) as ONE unit of work: the query row is
|
|
25
|
+
// written first, then the declared children, inside one transaction. On the server,
|
|
26
|
+
// `MJQueryEntityServer.Save` runs its extraction after `super.Save()` returns, so extraction
|
|
27
|
+
// sees the declared children already written. On a client the whole graph travels to the server
|
|
28
|
+
// and is saved there by the same code.
|
|
29
|
+
//
|
|
30
|
+
// They are NOT a read model: they start empty and load only on an explicit `Load()`. Reading a
|
|
31
|
+
// query's current children goes through the cache-backed `QueryParameters`, `QueryFields` and
|
|
32
|
+
// `QueryEntities` getters below. The companion names (`Parameters`, `Fields`, `Entities`) are
|
|
33
|
+
// the keys metadata files use under `collections`; the properties carry a `Declared` prefix
|
|
34
|
+
// because `BaseEntity.Fields` already names the entity's own field list.
|
|
22
35
|
super(...arguments);
|
|
36
|
+
/** Parameters declared with this query in a graph save (companion name `Parameters`). */
|
|
37
|
+
this.DeclaredParameters = this.DeclareRelatedRecords({
|
|
38
|
+
Name: 'Parameters',
|
|
39
|
+
RelatedEntity: 'MJ: Query Parameters',
|
|
40
|
+
RelatedEntityJoinField: 'QueryID',
|
|
41
|
+
OrderBy: 'Name ASC',
|
|
42
|
+
Load: 'explicit',
|
|
43
|
+
Source: 'database',
|
|
44
|
+
ReadOnly: false,
|
|
45
|
+
OnRemove: 'delete',
|
|
46
|
+
});
|
|
47
|
+
/** Output fields declared with this query in a graph save (companion name `Fields`). */
|
|
48
|
+
this.DeclaredFields = this.DeclareRelatedRecords({
|
|
49
|
+
Name: 'Fields',
|
|
50
|
+
RelatedEntity: 'MJ: Query Fields',
|
|
51
|
+
RelatedEntityJoinField: 'QueryID',
|
|
52
|
+
OrderBy: 'Sequence ASC',
|
|
53
|
+
Load: 'explicit',
|
|
54
|
+
Source: 'database',
|
|
55
|
+
ReadOnly: false,
|
|
56
|
+
OnRemove: 'delete',
|
|
57
|
+
});
|
|
58
|
+
/** Entity links declared with this query in a graph save (companion name `Entities`). */
|
|
59
|
+
this.DeclaredEntities = this.DeclareRelatedRecords({
|
|
60
|
+
Name: 'Entities',
|
|
61
|
+
RelatedEntity: 'MJ: Query Entities',
|
|
62
|
+
RelatedEntityJoinField: 'QueryID',
|
|
63
|
+
Load: 'explicit',
|
|
64
|
+
Source: 'database',
|
|
65
|
+
ReadOnly: false,
|
|
66
|
+
OnRemove: 'delete',
|
|
67
|
+
});
|
|
23
68
|
this._categoryPath = null;
|
|
24
69
|
// ─── Cache Configuration ────────────────────────────────────────────────────
|
|
25
70
|
this._cacheConfig = null;
|
|
26
71
|
}
|
|
72
|
+
// ─── Child Relationship Getters (read-through from QueryEngine) ─────────────
|
|
27
73
|
/** All field definitions for this query */
|
|
28
74
|
get QueryFields() {
|
|
29
75
|
return QueryEngine.Instance.GetQueryFields(this.ID);
|
|
30
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* The field definitions a user may see: every field of a query with `MJ: Query Permissions`
|
|
79
|
+
* rows (definer's rights, so the user receives every column), and otherwise the fields whose
|
|
80
|
+
* source entity field the user may read, plus those with no entity source. A column whose
|
|
81
|
+
* source the user may not read is left out of the results the user gets, so its definition is
|
|
82
|
+
* left out here too, and a UI listing these never names it.
|
|
83
|
+
*
|
|
84
|
+
* @param user The viewing user; with none, every field is returned (the server stays the boundary).
|
|
85
|
+
* @param catalog Every entity the provider knows, to resolve each field's source entity.
|
|
86
|
+
*/
|
|
87
|
+
QueryFieldsVisibleTo(user, catalog) {
|
|
88
|
+
const fields = this.QueryFields;
|
|
89
|
+
const permissions = this.QueryPermissions;
|
|
90
|
+
if (!user || (permissions && permissions.length > 0))
|
|
91
|
+
return fields;
|
|
92
|
+
const entities = IndexByUUID(catalog);
|
|
93
|
+
return fields.filter(f => {
|
|
94
|
+
if (!f.SourceEntityID || !f.SourceFieldName)
|
|
95
|
+
return true;
|
|
96
|
+
const entity = entities.Get(f.SourceEntityID);
|
|
97
|
+
if (!entity)
|
|
98
|
+
return true;
|
|
99
|
+
if (!entity.GetUserPermisions(user)?.CanRead)
|
|
100
|
+
return false;
|
|
101
|
+
return entity.IsFieldReadableByUser(f.SourceFieldName, user);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
31
104
|
/** All parameter definitions for this query */
|
|
32
105
|
get QueryParameters() {
|
|
33
106
|
return QueryEngine.Instance.GetQueryParameters(this.ID);
|
|
@@ -195,19 +268,24 @@ let MJQueryEntityExtended = class MJQueryEntityExtended extends MJQueryEntity {
|
|
|
195
268
|
* to {@link UserCanRun}, never instead of it.
|
|
196
269
|
*
|
|
197
270
|
* 1. A query with `MJ: Query Permissions` rows is authorized by its role list alone: a user who
|
|
198
|
-
* holds one of those roles may run it whatever it reads (
|
|
199
|
-
* who holds none may not.
|
|
271
|
+
* holds one of those roles may run it whatever it reads (definer's rights, like an EXECUTE
|
|
272
|
+
* grant on a stored procedure), and one who holds none may not. Field-level security does
|
|
273
|
+
* not apply to it.
|
|
200
274
|
* 2. Otherwise every entity whose base view or base table the SQL reads as a relation must be
|
|
201
275
|
* readable by the user ({@link FieldSecuritySQLGate.RelationEntities}). These come from the
|
|
202
276
|
* SQL, so a query whose `QueryEntities` rows are missing or stale is still checked. SQL that
|
|
203
277
|
* cannot be read is refused for a user who cannot read every entity in the catalog.
|
|
204
|
-
* 3. The SQL must not
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* field on, and SQL that cannot be read, are
|
|
208
|
-
* So is a relation that is not a
|
|
209
|
-
*
|
|
210
|
-
*
|
|
278
|
+
* 3. The SQL must not name a field the user is denied anywhere: the select list, WHERE, JOIN,
|
|
279
|
+
* GROUP BY, ORDER BY or HAVING, inside expressions and aggregates, through a CTE. A
|
|
280
|
+
* whole-row construct (`DISTINCT *`, set operations, `FOR JSON`, `row_to_json`, `NATURAL
|
|
281
|
+
* JOIN`, …) over an entity the user is denied a field on, and SQL that cannot be read, are
|
|
282
|
+
* refused too ({@link FieldSecuritySQLGate.FindViolation}). So is a relation that is not a
|
|
283
|
+
* CTE or a catalog entity's base view or base table, whose reads cannot be checked. A user
|
|
284
|
+
* denied no field on any entity is not scanned.
|
|
285
|
+
* 4. A plain `*` or `alias.*` that a structural reading of the statement has shown reaches the
|
|
286
|
+
* caller only as output columns (`options.ProjectionStarOffsets`) is not refused. The result
|
|
287
|
+
* then reports `needsColumnFiltering` when the user is denied a field on an entity the SQL
|
|
288
|
+
* reads: the caller must run the query and drop the denied columns from its rows.
|
|
211
289
|
*
|
|
212
290
|
* The result never names a denied field, so a refusal says only that the query cannot be run.
|
|
213
291
|
* `QueryFields` metadata plays no part: it is documentation, not a security source.
|
|
@@ -216,8 +294,9 @@ let MJQueryEntityExtended = class MJQueryEntityExtended extends MJQueryEntity {
|
|
|
216
294
|
* @param renderedSQL The SQL the run will execute
|
|
217
295
|
* @param catalog Every entity the executing provider knows
|
|
218
296
|
* @param dialect The database dialect the SQL runs under
|
|
297
|
+
* @param options The projection stars of `renderedSQL`, when the caller has read them
|
|
219
298
|
*/
|
|
220
|
-
UserCanRunRenderedSQL(user, renderedSQL, catalog, dialect) {
|
|
299
|
+
UserCanRunRenderedSQL(user, renderedSQL, catalog, dialect, options) {
|
|
221
300
|
const permissions = this.QueryPermissions;
|
|
222
301
|
if (permissions && permissions.length > 0) {
|
|
223
302
|
return { canRun: this.UserHasRunPermissions(user), deniedEntities: [] };
|
|
@@ -231,16 +310,21 @@ let MJQueryEntityExtended = class MJQueryEntityExtended extends MJQueryEntity {
|
|
|
231
310
|
if (deniedEntities.length > 0) {
|
|
232
311
|
return { canRun: false, deniedEntities };
|
|
233
312
|
}
|
|
313
|
+
const readEntities = [...this.declaredEntities(catalog), ...(read ?? [])];
|
|
314
|
+
const stars = options?.ProjectionStarOffsets;
|
|
234
315
|
const violation = FieldSecuritySQLGate.FindViolation(renderedSQL, {
|
|
235
316
|
User: user,
|
|
236
317
|
Dialect: dialect,
|
|
237
318
|
Catalog: catalog,
|
|
238
|
-
ReadEntities:
|
|
319
|
+
ReadEntities: readEntities,
|
|
239
320
|
RefuseUnknownRelations: true,
|
|
321
|
+
ProjectionStarOffsets: stars,
|
|
240
322
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
323
|
+
if (violation) {
|
|
324
|
+
return { canRun: false, deniedEntities: [], fieldSecurityViolation: violation };
|
|
325
|
+
}
|
|
326
|
+
const needsColumnFiltering = !!stars && stars.size > 0 && FieldSecuritySQLGate.UserCarriesDenials(readEntities, user);
|
|
327
|
+
return { canRun: true, deniedEntities: [], needsColumnFiltering };
|
|
244
328
|
}
|
|
245
329
|
/** The catalog entities this query's `QueryEntities` rows name; stale rows are left out. */
|
|
246
330
|
declaredEntities(catalog) {
|