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