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

Function assertOwnerWritable

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

Source from the content-addressed store, hash-verified

163
164/** Assert a create/upsert writes a row inside the bound partition. */
165export const assertOwnerWritable = (
166 tableName: string,
167 values: Record<string, unknown>,
168 context: ExecutorOwnerPolicyContext | undefined,
169): void => {
170 const ctx = requireContext(tableName, "write", context);
171 assertReachReadOnly(tableName, "write", ctx);
172 if (values.tenant !== ctx.tenant) {
173 policyViolation(`Storage write on table "${tableName}" is outside the executor tenant.`);
174 }
175 if (values.owner === "org") {
176 if (values.subject !== ORG_SUBJECT) {
177 policyViolation(`Storage write on table "${tableName}" set a subject on an org row.`);
178 }
179 return;
180 }
181 if (values.owner === "user") {
182 if (ctx.subject == null || values.subject !== ctx.subject) {
183 policyViolation(
184 `Storage write on table "${tableName}" targets a user row outside the bound subject.`,
185 );
186 }
187 return;
188 }
189 policyViolation(
190 `Storage write on table "${tableName}" has an invalid owner "${String(values.owner)}".`,
191 );
192};
193
194/** Assert a patch (`set`) doesn't move a row out of the bound partition. Only
195 * 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