( tableName: string, values: Record<string, unknown>, context: ExecutorOwnerPolicyContext | undefined, )
| 146 | |
| 147 | /** Assert a create/upsert writes a row inside the bound partition. */ |
| 148 | export 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. */ |
no test coverage detected