* Check if a user has write access to a table. * Write access requires write or admin workspace permission.
(tableId: string, userId: string)
| 164 | * Write access requires write or admin workspace permission. |
| 165 | */ |
| 166 | async function checkTableWriteAccess(tableId: string, userId: string): Promise<TableAccessCheck> { |
| 167 | const table = await getTableById(tableId) |
| 168 | |
| 169 | if (!table) { |
| 170 | return { hasAccess: false, notFound: true } |
| 171 | } |
| 172 | |
| 173 | const userPermission = await getUserEntityPermissions(userId, 'workspace', table.workspaceId) |
| 174 | if (permissionSatisfies(userPermission, 'write')) { |
| 175 | return { hasAccess: true, table } |
| 176 | } |
| 177 | |
| 178 | return { hasAccess: false, reason: 'User does not have write access to this table' } |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Access check returning `{ ok, table }` or `{ ok: false, status }`. |
nothing calls this directly
no test coverage detected