Simplify row action permissions response

This commit is contained in:
Adria Navarro 2024-10-23 12:47:06 +02:00
parent 076f21108f
commit 7781e75491
2 changed files with 22 additions and 24 deletions

View File

@ -2,9 +2,9 @@ import {
CreateRowActionRequest,
Ctx,
RowActionPermissions,
RowActionPermissionsResponse,
RowActionResponse,
RowActionsResponse,
UpdateRowActionRequest,
} from "@budibase/types"
import sdk from "../../../sdk"
@ -76,22 +76,22 @@ export async function remove(ctx: Ctx<void, void>) {
ctx.status = 204
}
export async function setTablePermission(ctx: Ctx<void, RowActionResponse>) {
export async function setTablePermission(
ctx: Ctx<void, RowActionPermissionsResponse>
) {
const table = await getTable(ctx)
const tableId = table._id!
const { actionId } = ctx.params
const action = await sdk.rowActions.setTablePermission(tableId, actionId)
ctx.body = {
tableId,
id: action.id,
name: action.name,
automationId: action.automationId,
allowedSources: flattenAllowedSources(tableId, action.permissions),
}
}
export async function unsetTablePermission(ctx: Ctx<void, RowActionResponse>) {
export async function unsetTablePermission(
ctx: Ctx<void, RowActionPermissionsResponse>
) {
const table = await getTable(ctx)
const tableId = table._id!
const { actionId } = ctx.params
@ -99,15 +99,13 @@ export async function unsetTablePermission(ctx: Ctx<void, RowActionResponse>) {
const action = await sdk.rowActions.unsetTablePermission(tableId, actionId)
ctx.body = {
tableId,
id: action.id,
name: action.name,
automationId: action.automationId,
allowedSources: flattenAllowedSources(tableId, action.permissions),
}
}
export async function setViewPermission(ctx: Ctx<void, RowActionResponse>) {
export async function setViewPermission(
ctx: Ctx<void, RowActionPermissionsResponse>
) {
const table = await getTable(ctx)
const tableId = table._id!
const { actionId, viewId } = ctx.params
@ -118,15 +116,13 @@ export async function setViewPermission(ctx: Ctx<void, RowActionResponse>) {
viewId
)
ctx.body = {
tableId,
id: action.id,
name: action.name,
automationId: action.automationId,
allowedSources: flattenAllowedSources(tableId, action.permissions),
}
}
export async function unsetViewPermission(ctx: Ctx<void, RowActionResponse>) {
export async function unsetViewPermission(
ctx: Ctx<void, RowActionPermissionsResponse>
) {
const table = await getTable(ctx)
const tableId = table._id!
const { actionId, viewId } = ctx.params
@ -138,10 +134,6 @@ export async function unsetViewPermission(ctx: Ctx<void, RowActionResponse>) {
)
ctx.body = {
tableId,
id: action.id,
name: action.name,
automationId: action.automationId,
allowedSources: flattenAllowedSources(tableId, action.permissions),
}
}

View File

@ -1,14 +1,17 @@
interface RowActionData {
name: string
}
interface RowActionPermissionsData {
allowedSources: string[] | undefined
}
export interface CreateRowActionRequest extends RowActionData {}
export interface UpdateRowActionRequest extends RowActionData {}
export interface RowActionResponse extends RowActionData {
export interface RowActionResponse
extends RowActionData,
RowActionPermissionsData {
id: string
tableId: string
automationId: string
allowedSources: string[] | undefined
}
export interface RowActionsResponse {
@ -18,3 +21,6 @@ export interface RowActionsResponse {
export interface RowActionTriggerRequest {
rowId: string
}
export interface RowActionPermissionsResponse
extends RowActionPermissionsData {}