( tableName: string, values: Record<string, unknown>, context: ExecutorOwnerPolicyContext | undefined, )
| 71 | |
| 72 | /** Assert a create/upsert writes a row inside the bound partition. */ |
| 73 | export const assertOwnerWritable = ( |
| 74 | tableName: string, |
| 75 | values: Record<string, unknown>, |
| 76 | context: ExecutorOwnerPolicyContext | undefined, |
| 77 | ): void => { |
| 78 | const ctx = requireContext(tableName, "write", context); |
| 79 | if (values.tenant !== ctx.tenant) { |
| 80 | policyViolation(`Storage write on table "${tableName}" is outside the executor tenant.`); |
| 81 | } |
| 82 | if (values.owner === "org") { |
| 83 | if (values.subject !== ORG_SUBJECT) { |
| 84 | policyViolation(`Storage write on table "${tableName}" set a subject on an org row.`); |
| 85 | } |
| 86 | return; |
| 87 | } |
| 88 | if (values.owner === "user") { |
| 89 | if (ctx.subject == null || values.subject !== ctx.subject) { |
| 90 | policyViolation( |
| 91 | `Storage write on table "${tableName}" targets a user row outside the bound subject.`, |
| 92 | ); |
| 93 | } |
| 94 | return; |
| 95 | } |
| 96 | policyViolation( |
| 97 | `Storage write on table "${tableName}" has an invalid owner "${String(values.owner)}".`, |
| 98 | ); |
| 99 | }; |
| 100 | |
| 101 | /** Assert a patch (`set`) doesn't move a row out of the bound partition. Only |
| 102 | * validates the partition columns that are actually being written. */ |
no test coverage detected