Set/unset

This commit is contained in:
Adria Navarro 2024-08-26 11:23:02 +02:00
parent 5f3dcda73a
commit 2aa71ab419
3 changed files with 45 additions and 0 deletions

View File

@ -87,3 +87,19 @@ export async function remove(ctx: Ctx<void, void>) {
await sdk.rowActions.remove(table._id!, actionId)
ctx.status = 204
}
export async function setViewPermission(ctx: Ctx<void, void>) {
const table = await getTable(ctx)
const { actionId, viewId } = ctx.params
await sdk.rowActions.setViewPermission(table._id!, actionId, viewId)
ctx.status = 204
}
export async function unsetViewPermission(ctx: Ctx<void, void>) {
const table = await getTable(ctx)
const { actionId, viewId } = ctx.params
await sdk.rowActions.unsetViewPermission(table._id!, actionId, viewId)
ctx.status = 204
}

View File

@ -50,6 +50,16 @@ router
authorizedResource(PermissionType.TABLE, PermissionLevel.READ, "tableId"),
rowActionController.remove
)
.post(
"/api/tables/:tableId/actions/:actionId/permissions/:viewId",
authorizedResource(PermissionType.TABLE, PermissionLevel.READ, "tableId"),
rowActionController.setViewPermission
)
.delete(
"/api/tables/:tableId/actions/:actionId/permissions/:viewId",
authorizedResource(PermissionType.TABLE, PermissionLevel.READ, "tableId"),
rowActionController.unsetViewPermission
)
// Other endpoints
.post(

View File

@ -158,6 +158,25 @@ export async function setViewPermission(
}
}
export async function unsetViewPermission(
tableId: string,
rowActionId: string,
viewId: string
) {
const actionsDoc = await get(tableId)
const rowAction = getRowAction(actionsDoc, rowActionId)
delete rowAction.permissions.views[viewId]
const db = context.getAppDB()
await db.put(actionsDoc)
return {
id: rowActionId,
...rowAction,
}
}
export async function remove(tableId: string, rowActionId: string) {
const actionsDoc = await get(tableId)