@jsb188/mday 1.1.10 → 1.1.12
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 +140 -54
- package/src/constants/agentMemory.ts +123 -0
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +10 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +236 -0
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +21 -21
- package/src/constants/dataTableFieldTypes.generated.ts +59 -0
- package/src/constants/docAccess.ts +33 -0
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +125 -7
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/integration.ts +8 -9
- package/src/constants/log.ts +14 -408
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +2207 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -21
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +126 -14
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +6 -6
- package/src/constants/storage.ts +80 -7
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +836 -780
- package/src/schemas/inboundContact.ts +60 -55
- package/src/schemas/logsQuery.ts +55 -49
- package/src/types/account.d.ts +4 -1
- package/src/types/agentMemory.d.ts +98 -0
- package/src/types/agentNote.d.ts +443 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1533 -0
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +115 -403
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +184 -24
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +702 -0
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +10 -1
- package/src/types/log.d.ts +254 -295
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +91 -43
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +678 -129
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +449 -129
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +315 -54
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +43 -0
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +1174 -0
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +95 -618
- package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +317 -51
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +157 -0
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +276 -192
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +262 -0
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +395 -0
- package/src/utils/noteDoc.ts +609 -0
- package/src/utils/organization.ts +337 -84
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +199 -107
- package/src/utils/sheetAxisMove.ts +616 -0
- package/src/utils/sheetBootstrap.ts +1402 -0
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +358 -0
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +186 -0
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +899 -0
- package/src/utils/sheetFormulaEvaluator.ts +997 -0
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +200 -0
- package/src/utils/sheetNumberFormat.ts +1012 -0
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +118 -0
- package/src/utils/sheetSnapshot.ts +739 -0
- package/src/utils/sheetStructureEdit.ts +914 -0
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/square.ts +22 -12
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +127 -11
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +334 -40
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +514 -0
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +352 -0
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +468 -0
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +22 -0
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +537 -0
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/tsconfig.json +10 -10
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -235
- package/src/constants/product.ts +0 -42
- package/src/constants/report.ts +0 -44
- package/src/schemas/organization.ts +0 -65
- package/src/schemas/productsQuery.ts +0 -53
- package/src/schemas/reportsQuery.ts +0 -20
- package/src/types/product.d.ts +0 -84
- package/src/types/report.d.ts +0 -290
- package/src/utils/product-calEvent.ts +0 -455
- package/src/utils/report.ts +0 -158
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DocAccessGrantObj,
|
|
3
|
+
DocAccessObj,
|
|
4
|
+
DocAccessViewerCtx,
|
|
5
|
+
} from '@jsb188/mday/types/docAccess.d.ts';
|
|
6
|
+
import { getEffectiveDocPermission } from '@jsb188/mday/utils/docAccess.ts';
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* getEffectiveDocPermission is the single decision every access-controlled
|
|
11
|
+
* document type routes through: Sheets, Notes, and schedule calendars all
|
|
12
|
+
* reduce their own authorization question to this one call, and the ICS feed
|
|
13
|
+
* reconstructs a viewer context by hand just to ask it. Nothing downstream
|
|
14
|
+
* second-guesses the answer — "NONE" is the only thing standing between a
|
|
15
|
+
* document and somebody outside the organization that owns it.
|
|
16
|
+
*
|
|
17
|
+
* The function is also unusually easy to break silently. Its inputs are five
|
|
18
|
+
* independent booleans and three permission strings, the grant lookups compare
|
|
19
|
+
* ids that arrive as strings, numbers, or bigints depending on the caller, and
|
|
20
|
+
* the "no grant" / "explicit NONE grant" distinction is carried by null rather
|
|
21
|
+
* than by a value. A refactor that reads naturally can flip an entire class of
|
|
22
|
+
* viewers from denied to allowed without failing a type check.
|
|
23
|
+
*
|
|
24
|
+
* These tests pin the full matrix so that flip cannot happen unnoticed.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Build one document's stored access settings. The defaults mirror the
|
|
29
|
+
* restrictive end of the policy (private link, no network access) so each test
|
|
30
|
+
* only states the rule it is about.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
function makeAccess(overrides: Partial<DocAccessObj> = {}): DocAccessObj {
|
|
34
|
+
return {
|
|
35
|
+
team: 'EDIT',
|
|
36
|
+
public: 'NONE',
|
|
37
|
+
network: 'NONE',
|
|
38
|
+
grants: [],
|
|
39
|
+
...overrides,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* Build one viewer context. The defaults describe a signed-in stranger: no
|
|
45
|
+
* membership anywhere near the owner organization.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
function makeViewer(
|
|
49
|
+
overrides: Partial<DocAccessViewerCtx> = {},
|
|
50
|
+
): DocAccessViewerCtx {
|
|
51
|
+
return {
|
|
52
|
+
accountId: '100',
|
|
53
|
+
isOwnerOrgMember: false,
|
|
54
|
+
isAdminOrOwner: false,
|
|
55
|
+
hasWriteACL: false,
|
|
56
|
+
isNetworkOrgMember: false,
|
|
57
|
+
viewerOrganizationIds: [],
|
|
58
|
+
...overrides,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* Build one grant targeting a single account.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
function makeAccountGrant(
|
|
67
|
+
accountId: string | number | bigint,
|
|
68
|
+
permission: DocAccessGrantObj['permission'],
|
|
69
|
+
): DocAccessGrantObj {
|
|
70
|
+
return { granteeType: 'ACCOUNT', granteeId: accountId, permission };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
* Build one grant targeting a single organization.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
function makeOrgGrant(
|
|
78
|
+
organizationId: string | number | bigint,
|
|
79
|
+
permission: DocAccessGrantObj['permission'],
|
|
80
|
+
): DocAccessGrantObj {
|
|
81
|
+
return { granteeType: 'ORGANIZATION', granteeId: organizationId, permission };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
describe('getEffectiveDocPermission base policy matrix', () => {
|
|
85
|
+
it('gives owner-org members with the write ACL exactly the team policy', () => {
|
|
86
|
+
const viewer = makeViewer({ isOwnerOrgMember: true, hasWriteACL: true });
|
|
87
|
+
|
|
88
|
+
expect(
|
|
89
|
+
getEffectiveDocPermission(makeAccess({ team: 'EDIT' }), viewer),
|
|
90
|
+
).toBe('EDIT');
|
|
91
|
+
expect(
|
|
92
|
+
getEffectiveDocPermission(makeAccess({ team: 'VIEW' }), viewer),
|
|
93
|
+
).toBe('VIEW');
|
|
94
|
+
expect(
|
|
95
|
+
getEffectiveDocPermission(makeAccess({ team: 'NONE' }), viewer),
|
|
96
|
+
).toBe('NONE');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('defaults a missing policy to team EDIT and a private link', () => {
|
|
100
|
+
const member = makeViewer({ isOwnerOrgMember: true, hasWriteACL: true });
|
|
101
|
+
|
|
102
|
+
expect(getEffectiveDocPermission(null, member)).toBe('EDIT');
|
|
103
|
+
expect(getEffectiveDocPermission(undefined, member)).toBe('EDIT');
|
|
104
|
+
// The same missing policy grants an outsider nothing
|
|
105
|
+
expect(getEffectiveDocPermission(null, makeViewer())).toBe('NONE');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('applies the network policy only to members of a network organization', () => {
|
|
109
|
+
const access = makeAccess({ network: 'EDIT' });
|
|
110
|
+
|
|
111
|
+
expect(
|
|
112
|
+
getEffectiveDocPermission(
|
|
113
|
+
access,
|
|
114
|
+
makeViewer({ isNetworkOrgMember: true }),
|
|
115
|
+
),
|
|
116
|
+
).toBe('EDIT');
|
|
117
|
+
expect(
|
|
118
|
+
getEffectiveDocPermission(
|
|
119
|
+
access,
|
|
120
|
+
makeViewer({ isNetworkOrgMember: false }),
|
|
121
|
+
),
|
|
122
|
+
).toBe('NONE');
|
|
123
|
+
expect(
|
|
124
|
+
getEffectiveDocPermission(
|
|
125
|
+
makeAccess({ network: 'VIEW' }),
|
|
126
|
+
makeViewer({ isNetworkOrgMember: true }),
|
|
127
|
+
),
|
|
128
|
+
).toBe('VIEW');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('never lets the team policy reach anyone outside the owner org', () => {
|
|
132
|
+
// team EDIT is the default policy on every document, so a leak here
|
|
133
|
+
// would expose essentially everything
|
|
134
|
+
expect(
|
|
135
|
+
getEffectiveDocPermission(
|
|
136
|
+
makeAccess({ team: 'EDIT' }),
|
|
137
|
+
makeViewer({ isNetworkOrgMember: true }),
|
|
138
|
+
),
|
|
139
|
+
).toBe('NONE');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('gives everyone the public policy once the link is open', () => {
|
|
143
|
+
const access = makeAccess({ public: 'VIEW' });
|
|
144
|
+
|
|
145
|
+
expect(getEffectiveDocPermission(access, makeViewer())).toBe('VIEW');
|
|
146
|
+
expect(
|
|
147
|
+
getEffectiveDocPermission(access, makeViewer({ accountId: null })),
|
|
148
|
+
).toBe('VIEW');
|
|
149
|
+
expect(
|
|
150
|
+
getEffectiveDocPermission(
|
|
151
|
+
access,
|
|
152
|
+
makeViewer({ isNetworkOrgMember: true }),
|
|
153
|
+
),
|
|
154
|
+
).toBe('VIEW');
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('getEffectiveDocPermission public floor', () => {
|
|
159
|
+
it('floors owner-org members at the public permission', () => {
|
|
160
|
+
// A member must never end up with less than an anonymous link visitor:
|
|
161
|
+
// the member can always open the link in a signed-out tab
|
|
162
|
+
const access = makeAccess({ team: 'NONE', public: 'VIEW' });
|
|
163
|
+
|
|
164
|
+
expect(
|
|
165
|
+
getEffectiveDocPermission(
|
|
166
|
+
access,
|
|
167
|
+
makeViewer({ isOwnerOrgMember: true, hasWriteACL: true }),
|
|
168
|
+
),
|
|
169
|
+
).toBe('VIEW');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('floors an explicitly blocked grantee at the public permission', () => {
|
|
173
|
+
const access = makeAccess({
|
|
174
|
+
team: 'EDIT',
|
|
175
|
+
public: 'VIEW',
|
|
176
|
+
grants: [makeAccountGrant('100', 'NONE')],
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
expect(
|
|
180
|
+
getEffectiveDocPermission(
|
|
181
|
+
access,
|
|
182
|
+
makeViewer({ isOwnerOrgMember: true, hasWriteACL: true }),
|
|
183
|
+
),
|
|
184
|
+
).toBe('VIEW');
|
|
185
|
+
expect(getEffectiveDocPermission(access, makeViewer())).toBe('VIEW');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('never lowers a permission the viewer already earned', () => {
|
|
189
|
+
const access = makeAccess({ team: 'EDIT', public: 'VIEW' });
|
|
190
|
+
|
|
191
|
+
expect(
|
|
192
|
+
getEffectiveDocPermission(
|
|
193
|
+
access,
|
|
194
|
+
makeViewer({ isOwnerOrgMember: true, hasWriteACL: true }),
|
|
195
|
+
),
|
|
196
|
+
).toBe('EDIT');
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe('getEffectiveDocPermission signed-out downgrade', () => {
|
|
201
|
+
it('caps public EDIT at VIEW for a viewer with no account', () => {
|
|
202
|
+
// Editing has to be attributable to somebody, so an open-to-edit link
|
|
203
|
+
// still only reads for an anonymous visitor
|
|
204
|
+
const access = makeAccess({ public: 'EDIT' });
|
|
205
|
+
|
|
206
|
+
expect(
|
|
207
|
+
getEffectiveDocPermission(access, makeViewer({ accountId: null })),
|
|
208
|
+
).toBe('VIEW');
|
|
209
|
+
expect(
|
|
210
|
+
getEffectiveDocPermission(access, makeViewer({ accountId: undefined })),
|
|
211
|
+
).toBe('VIEW');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('keeps public EDIT for a signed-in viewer', () => {
|
|
215
|
+
const access = makeAccess({ public: 'EDIT' });
|
|
216
|
+
|
|
217
|
+
expect(getEffectiveDocPermission(access, makeViewer())).toBe('EDIT');
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('caps a signed-out owner-org-flagged viewer at VIEW as well', () => {
|
|
221
|
+
// Defensive: a caller that sets isOwnerOrgMember without an accountId
|
|
222
|
+
// must not route around the downgrade
|
|
223
|
+
const access = makeAccess({ team: 'NONE', public: 'EDIT' });
|
|
224
|
+
|
|
225
|
+
expect(
|
|
226
|
+
getEffectiveDocPermission(
|
|
227
|
+
access,
|
|
228
|
+
makeViewer({
|
|
229
|
+
accountId: null,
|
|
230
|
+
isOwnerOrgMember: true,
|
|
231
|
+
hasWriteACL: true,
|
|
232
|
+
}),
|
|
233
|
+
),
|
|
234
|
+
).toBe('VIEW');
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe('getEffectiveDocPermission read-only member cap', () => {
|
|
239
|
+
it('caps a member without the org write ACL at VIEW', () => {
|
|
240
|
+
const readOnlyMember = makeViewer({
|
|
241
|
+
isOwnerOrgMember: true,
|
|
242
|
+
hasWriteACL: false,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
expect(
|
|
246
|
+
getEffectiveDocPermission(makeAccess({ team: 'EDIT' }), readOnlyMember),
|
|
247
|
+
).toBe('VIEW');
|
|
248
|
+
expect(
|
|
249
|
+
getEffectiveDocPermission(makeAccess({ team: 'VIEW' }), readOnlyMember),
|
|
250
|
+
).toBe('VIEW');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('does not raise a read-only member above a restrictive team policy', () => {
|
|
254
|
+
const readOnlyMember = makeViewer({
|
|
255
|
+
isOwnerOrgMember: true,
|
|
256
|
+
hasWriteACL: false,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
expect(
|
|
260
|
+
getEffectiveDocPermission(makeAccess({ team: 'NONE' }), readOnlyMember),
|
|
261
|
+
).toBe('NONE');
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('lets an explicit account grant lift a read-only member to EDIT', () => {
|
|
265
|
+
// A targeted grant is a deliberate elevation, so it outranks the ACL
|
|
266
|
+
// default that produced the cap
|
|
267
|
+
const access = makeAccess({
|
|
268
|
+
team: 'EDIT',
|
|
269
|
+
grants: [makeAccountGrant('100', 'EDIT')],
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
expect(
|
|
273
|
+
getEffectiveDocPermission(
|
|
274
|
+
access,
|
|
275
|
+
makeViewer({ isOwnerOrgMember: true, hasWriteACL: false }),
|
|
276
|
+
),
|
|
277
|
+
).toBe('EDIT');
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe('getEffectiveDocPermission account grants', () => {
|
|
282
|
+
it('overrides the team policy in both directions', () => {
|
|
283
|
+
const member = makeViewer({ isOwnerOrgMember: true, hasWriteACL: true });
|
|
284
|
+
|
|
285
|
+
expect(
|
|
286
|
+
getEffectiveDocPermission(
|
|
287
|
+
makeAccess({ team: 'VIEW', grants: [makeAccountGrant('100', 'EDIT')] }),
|
|
288
|
+
member,
|
|
289
|
+
),
|
|
290
|
+
).toBe('EDIT');
|
|
291
|
+
expect(
|
|
292
|
+
getEffectiveDocPermission(
|
|
293
|
+
makeAccess({ team: 'EDIT', grants: [makeAccountGrant('100', 'VIEW')] }),
|
|
294
|
+
member,
|
|
295
|
+
),
|
|
296
|
+
).toBe('VIEW');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('blocks an owner-org member outright with an explicit NONE grant', () => {
|
|
300
|
+
// "no grant" and "NONE grant" are different answers: the second is a
|
|
301
|
+
// deliberate block that has to beat the default team EDIT policy
|
|
302
|
+
const access = makeAccess({
|
|
303
|
+
team: 'EDIT',
|
|
304
|
+
grants: [makeAccountGrant('100', 'NONE')],
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
expect(
|
|
308
|
+
getEffectiveDocPermission(
|
|
309
|
+
access,
|
|
310
|
+
makeViewer({ isOwnerOrgMember: true, hasWriteACL: true }),
|
|
311
|
+
),
|
|
312
|
+
).toBe('NONE');
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('grants an outsider access with no membership of any kind', () => {
|
|
316
|
+
const access = makeAccess({ grants: [makeAccountGrant('100', 'EDIT')] });
|
|
317
|
+
|
|
318
|
+
expect(getEffectiveDocPermission(access, makeViewer())).toBe('EDIT');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('only matches the grant belonging to this viewer', () => {
|
|
322
|
+
const access = makeAccess({
|
|
323
|
+
team: 'EDIT',
|
|
324
|
+
grants: [makeAccountGrant('999', 'NONE')],
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
expect(
|
|
328
|
+
getEffectiveDocPermission(
|
|
329
|
+
access,
|
|
330
|
+
makeViewer({ isOwnerOrgMember: true, hasWriteACL: true }),
|
|
331
|
+
),
|
|
332
|
+
).toBe('EDIT');
|
|
333
|
+
expect(getEffectiveDocPermission(access, makeViewer())).toBe('NONE');
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('matches grantee ids across string, number, and bigint spellings', () => {
|
|
337
|
+
// Ids reach this function as strings from GraphQL and as numbers or
|
|
338
|
+
// bigints from Postgres; a strict comparison would silently drop grants
|
|
339
|
+
const viewer = makeViewer({ accountId: 100 });
|
|
340
|
+
|
|
341
|
+
expect(
|
|
342
|
+
getEffectiveDocPermission(
|
|
343
|
+
makeAccess({ grants: [makeAccountGrant('100', 'EDIT')] }),
|
|
344
|
+
viewer,
|
|
345
|
+
),
|
|
346
|
+
).toBe('EDIT');
|
|
347
|
+
expect(
|
|
348
|
+
getEffectiveDocPermission(
|
|
349
|
+
makeAccess({ grants: [makeAccountGrant(100n, 'EDIT')] }),
|
|
350
|
+
viewer,
|
|
351
|
+
),
|
|
352
|
+
).toBe('EDIT');
|
|
353
|
+
expect(
|
|
354
|
+
getEffectiveDocPermission(
|
|
355
|
+
makeAccess({ grants: [makeAccountGrant(100, 'EDIT')] }),
|
|
356
|
+
makeViewer({ accountId: '100' }),
|
|
357
|
+
),
|
|
358
|
+
).toBe('EDIT');
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it('ignores every grant for a viewer with no account', () => {
|
|
362
|
+
const access = makeAccess({ grants: [makeAccountGrant('100', 'EDIT')] });
|
|
363
|
+
|
|
364
|
+
expect(
|
|
365
|
+
getEffectiveDocPermission(access, makeViewer({ accountId: null })),
|
|
366
|
+
).toBe('NONE');
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('outranks the organization grant for the same viewer', () => {
|
|
370
|
+
const access = makeAccess({
|
|
371
|
+
grants: [makeAccountGrant('100', 'NONE'), makeOrgGrant('7', 'EDIT')],
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
expect(
|
|
375
|
+
getEffectiveDocPermission(
|
|
376
|
+
access,
|
|
377
|
+
makeViewer({ viewerOrganizationIds: ['7'] }),
|
|
378
|
+
),
|
|
379
|
+
).toBe('NONE');
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
describe('getEffectiveDocPermission organization grants', () => {
|
|
384
|
+
it('applies only to organizations the viewer actually belongs to', () => {
|
|
385
|
+
const access = makeAccess({ grants: [makeOrgGrant('7', 'EDIT')] });
|
|
386
|
+
|
|
387
|
+
expect(
|
|
388
|
+
getEffectiveDocPermission(
|
|
389
|
+
access,
|
|
390
|
+
makeViewer({ viewerOrganizationIds: ['7'] }),
|
|
391
|
+
),
|
|
392
|
+
).toBe('EDIT');
|
|
393
|
+
expect(
|
|
394
|
+
getEffectiveDocPermission(
|
|
395
|
+
access,
|
|
396
|
+
makeViewer({ viewerOrganizationIds: ['8'] }),
|
|
397
|
+
),
|
|
398
|
+
).toBe('NONE');
|
|
399
|
+
expect(
|
|
400
|
+
getEffectiveDocPermission(
|
|
401
|
+
access,
|
|
402
|
+
makeViewer({ viewerOrganizationIds: [] }),
|
|
403
|
+
),
|
|
404
|
+
).toBe('NONE');
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('takes the best permission when the viewer belongs to several granted orgs', () => {
|
|
408
|
+
const access = makeAccess({
|
|
409
|
+
grants: [makeOrgGrant('7', 'VIEW'), makeOrgGrant('8', 'EDIT')],
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
expect(
|
|
413
|
+
getEffectiveDocPermission(
|
|
414
|
+
access,
|
|
415
|
+
makeViewer({ viewerOrganizationIds: ['7', '8'] }),
|
|
416
|
+
),
|
|
417
|
+
).toBe('EDIT');
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('overrides the network policy in both directions', () => {
|
|
421
|
+
const networkViewer = makeViewer({
|
|
422
|
+
isNetworkOrgMember: true,
|
|
423
|
+
viewerOrganizationIds: ['7'],
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
expect(
|
|
427
|
+
getEffectiveDocPermission(
|
|
428
|
+
makeAccess({ network: 'VIEW', grants: [makeOrgGrant('7', 'EDIT')] }),
|
|
429
|
+
networkViewer,
|
|
430
|
+
),
|
|
431
|
+
).toBe('EDIT');
|
|
432
|
+
expect(
|
|
433
|
+
getEffectiveDocPermission(
|
|
434
|
+
makeAccess({ network: 'EDIT', grants: [makeOrgGrant('7', 'NONE')] }),
|
|
435
|
+
networkViewer,
|
|
436
|
+
),
|
|
437
|
+
).toBe('NONE');
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('matches organization ids across string, number, and bigint spellings', () => {
|
|
441
|
+
expect(
|
|
442
|
+
getEffectiveDocPermission(
|
|
443
|
+
makeAccess({ grants: [makeOrgGrant(7n, 'VIEW')] }),
|
|
444
|
+
makeViewer({ viewerOrganizationIds: ['7'] }),
|
|
445
|
+
),
|
|
446
|
+
).toBe('VIEW');
|
|
447
|
+
expect(
|
|
448
|
+
getEffectiveDocPermission(
|
|
449
|
+
makeAccess({ grants: [makeOrgGrant('7', 'VIEW')] }),
|
|
450
|
+
makeViewer({ viewerOrganizationIds: [7] }),
|
|
451
|
+
),
|
|
452
|
+
).toBe('VIEW');
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('is ignored entirely for owner-org members', () => {
|
|
456
|
+
// Owner-org members are judged by the team policy and their own account
|
|
457
|
+
// grant; an org grant naming the owner org must not re-open a document
|
|
458
|
+
// the team policy closed
|
|
459
|
+
const access = makeAccess({
|
|
460
|
+
team: 'NONE',
|
|
461
|
+
grants: [makeOrgGrant('7', 'EDIT')],
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
expect(
|
|
465
|
+
getEffectiveDocPermission(
|
|
466
|
+
access,
|
|
467
|
+
makeViewer({
|
|
468
|
+
isOwnerOrgMember: true,
|
|
469
|
+
hasWriteACL: true,
|
|
470
|
+
viewerOrganizationIds: ['7'],
|
|
471
|
+
}),
|
|
472
|
+
),
|
|
473
|
+
).toBe('NONE');
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
describe('getEffectiveDocPermission owner-org admins and owners', () => {
|
|
478
|
+
const admin = makeViewer({
|
|
479
|
+
isOwnerOrgMember: true,
|
|
480
|
+
isAdminOrOwner: true,
|
|
481
|
+
hasWriteACL: false,
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it('keeps full access against the most restrictive policy', () => {
|
|
485
|
+
expect(getEffectiveDocPermission(makeAccess({ team: 'NONE' }), admin)).toBe(
|
|
486
|
+
'EDIT',
|
|
487
|
+
);
|
|
488
|
+
expect(getEffectiveDocPermission(makeAccess({ team: 'VIEW' }), admin)).toBe(
|
|
489
|
+
'EDIT',
|
|
490
|
+
);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
it('keeps full access against an explicit NONE grant', () => {
|
|
494
|
+
// Somebody who can read the row in the database must not be lockable
|
|
495
|
+
// out of it through the sharing UI
|
|
496
|
+
const access = makeAccess({
|
|
497
|
+
team: 'NONE',
|
|
498
|
+
grants: [makeAccountGrant('100', 'NONE'), makeOrgGrant('7', 'NONE')],
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
expect(
|
|
502
|
+
getEffectiveDocPermission(access, {
|
|
503
|
+
...admin,
|
|
504
|
+
viewerOrganizationIds: ['7'],
|
|
505
|
+
}),
|
|
506
|
+
).toBe('EDIT');
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it('keeps full access without the org write ACL', () => {
|
|
510
|
+
expect(getEffectiveDocPermission(makeAccess({ team: 'EDIT' }), admin)).toBe(
|
|
511
|
+
'EDIT',
|
|
512
|
+
);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
it('does not extend to admins of some other organization', () => {
|
|
516
|
+
// isAdminOrOwner is always resolved against the OWNER org; being an
|
|
517
|
+
// admin somewhere else must grant nothing here
|
|
518
|
+
expect(
|
|
519
|
+
getEffectiveDocPermission(
|
|
520
|
+
makeAccess(),
|
|
521
|
+
makeViewer({ isOwnerOrgMember: false, isAdminOrOwner: true }),
|
|
522
|
+
),
|
|
523
|
+
).toBe('NONE');
|
|
524
|
+
});
|
|
525
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { expect, it } from 'vitest';
|
|
2
|
+
import { makeLogMetadataSchema } from '../src/schemas/editLogEntry.ts';
|
|
3
|
+
import type { LogTaxonomyGQL } from '../src/types/log.d.ts';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Build the smallest taxonomy needed to exercise accounting-field visibility.
|
|
7
|
+
*/
|
|
8
|
+
function makeTaxonomy(activityKey: string, groupKey: string): LogTaxonomyGQL {
|
|
9
|
+
return {
|
|
10
|
+
operation: 'ARABLE',
|
|
11
|
+
groups: [
|
|
12
|
+
{
|
|
13
|
+
key: groupKey,
|
|
14
|
+
label: groupKey,
|
|
15
|
+
ordinal: 0,
|
|
16
|
+
requiredFields: activityKey === 'SEED_PURCHASE_INFO' ? ['item'] : [],
|
|
17
|
+
orRequiredFields: [],
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
activities: [
|
|
21
|
+
{
|
|
22
|
+
key: activityKey,
|
|
23
|
+
groupKey,
|
|
24
|
+
agentText: activityKey,
|
|
25
|
+
ordinal: 0,
|
|
26
|
+
requiredFields: null,
|
|
27
|
+
orRequiredFields: null,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
fieldDefs: [
|
|
31
|
+
{
|
|
32
|
+
key: 'tax',
|
|
33
|
+
fieldType: 'MONEY',
|
|
34
|
+
required: false,
|
|
35
|
+
ordinal: 0,
|
|
36
|
+
agentHint: null,
|
|
37
|
+
options: null,
|
|
38
|
+
allowedUnits: null,
|
|
39
|
+
groupKey: null,
|
|
40
|
+
activityKey: null,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
* Return the form field names emitted for one activity's editor.
|
|
48
|
+
*/
|
|
49
|
+
function getSchemaFieldNames(activityKey: string, groupKey: string): string[] {
|
|
50
|
+
const schema = makeLogMetadataSchema(
|
|
51
|
+
{
|
|
52
|
+
details: {
|
|
53
|
+
activity: activityKey,
|
|
54
|
+
__groupKey: groupKey,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
__typename: 'LogEntryDetails',
|
|
59
|
+
scrollAreaDOMId: 'test-scroll-area',
|
|
60
|
+
formId: 'test-form',
|
|
61
|
+
timeZone: 'America/Los_Angeles',
|
|
62
|
+
focusedName: '',
|
|
63
|
+
isCreateNew: false,
|
|
64
|
+
taxonomy: makeTaxonomy(activityKey, groupKey),
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return schema
|
|
69
|
+
.map((schemaItem) => schemaItem?.item?.name)
|
|
70
|
+
.filter((fieldName): fieldName is string => typeof fieldName === 'string');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
it('omits accounting-only fields from non-financial log editors', () => {
|
|
74
|
+
const fieldNames = getSchemaFieldNames(
|
|
75
|
+
'EQUIPMENT_MATERIAL',
|
|
76
|
+
'CLEANING_AND_SANITATION',
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(
|
|
80
|
+
fieldNames.filter((fieldName) =>
|
|
81
|
+
[
|
|
82
|
+
'details.price',
|
|
83
|
+
'details.otherParty',
|
|
84
|
+
'details.fields.tax',
|
|
85
|
+
'details.referenceNumber',
|
|
86
|
+
'details.voided',
|
|
87
|
+
].includes(fieldName),
|
|
88
|
+
),
|
|
89
|
+
).toEqual([]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('retains accounting fields in financial log editors', () => {
|
|
93
|
+
const fieldNames = getSchemaFieldNames('SEED_PURCHASE_INFO', 'SEED');
|
|
94
|
+
|
|
95
|
+
expect(
|
|
96
|
+
fieldNames.filter((fieldName) =>
|
|
97
|
+
[
|
|
98
|
+
'details.price',
|
|
99
|
+
'details.otherParty',
|
|
100
|
+
'details.fields.tax',
|
|
101
|
+
'details.referenceNumber',
|
|
102
|
+
'details.voided',
|
|
103
|
+
].includes(fieldName),
|
|
104
|
+
),
|
|
105
|
+
).toEqual([
|
|
106
|
+
'details.price',
|
|
107
|
+
'details.otherParty',
|
|
108
|
+
'details.fields.tax',
|
|
109
|
+
'details.referenceNumber',
|
|
110
|
+
'details.voided',
|
|
111
|
+
]);
|
|
112
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
getEmailAddressListMailboxes,
|
|
4
|
+
getOutboundEmailQueueDisposition,
|
|
5
|
+
} from '../src/utils/email.ts';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Assert one parsed mailbox list exactly matches the expected values.
|
|
9
|
+
*/
|
|
10
|
+
function expectMailboxes(value: string, expected: string[]) {
|
|
11
|
+
const actual = getEmailAddressListMailboxes(value);
|
|
12
|
+
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`Expected ${JSON.stringify(expected)}, received ${JSON.stringify(actual)}`,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
it('email address lists preserve commas inside quoted display names', () => {
|
|
20
|
+
expectMailboxes(
|
|
21
|
+
'"Doe, Jane" <Jane@Example.com>, John Smith <john.smith@example.com>',
|
|
22
|
+
['jane@example.com', 'john.smith@example.com'],
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('email address lists preserve commas inside comments and normalize plain mailboxes', () => {
|
|
27
|
+
expectMailboxes('jane@example.com (Doe, Jane), TEAM@EXAMPLE.ORG', [
|
|
28
|
+
'jane@example.com',
|
|
29
|
+
'team@example.org',
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('suppressed outbound emails are terminal and can never be requeued', () => {
|
|
34
|
+
if (getOutboundEmailQueueDisposition('SUPPRESSED') !== 'TERMINAL_FAILURE') {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'SUPPRESSED must remain a terminal outbound-email failure.',
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
});
|