MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / assertOwnerWritable

Function assertOwnerWritable

packages/core/sdk/src/owner-policy.ts:148–175  ·  view source on GitHub ↗
(
  tableName: string,
  values: Record<string, unknown>,
  context: ExecutorOwnerPolicyContext | undefined,
)

Source from the content-addressed store, hash-verified

146
147/** Assert a create/upsert writes a row inside the bound partition. */
148export const assertOwnerWritable = (
149 tableName: string,
150 values: Record<string, unknown>,
151 context: ExecutorOwnerPolicyContext | undefined,
152): void => {
153 const ctx = requireContext(tableName, "write", context);
154 assertReachReadOnly(tableName, "write", ctx);
155 if (values.tenant !== ctx.tenant) {
156 policyViolation(`Storage write on table "${tableName}" is outside the executor tenant.`);
157 }
158 if (values.owner === "org") {
159 if (values.subject !== ORG_SUBJECT) {
160 policyViolation(`Storage write on table "${tableName}" set a subject on an org row.`);
161 }
162 return;
163 }
164 if (values.owner === "user") {
165 if (ctx.subject == null || values.subject !== ctx.subject) {
166 policyViolation(
167 `Storage write on table "${tableName}" targets a user row outside the bound subject.`,
168 );
169 }
170 return;
171 }
172 policyViolation(
173 `Storage write on table "${tableName}" has an invalid owner "${String(values.owner)}".`,
174 );
175};
176
177/** Assert a patch (`set`) doesn't move a row out of the bound partition. Only
178 * validates the partition columns that are actually being written. */

Callers 1

ownedExecutorTableFunction · 0.90

Calls 3

requireContextFunction · 0.85
assertReachReadOnlyFunction · 0.85
policyViolationFunction · 0.85

Tested by

no test coverage detected