Return types
This commit is contained in:
parent
42f849d9a1
commit
d1c6edc437
|
@ -36,6 +36,7 @@ export async function find(ctx: Ctx<void, RowActionsResponse>) {
|
||||||
tableId: table._id!,
|
tableId: table._id!,
|
||||||
name: action.name,
|
name: action.name,
|
||||||
automationId: action.automationId,
|
automationId: action.automationId,
|
||||||
|
allowedViews: flattenAllowedViews(action.permissions.views),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
{}
|
{}
|
||||||
|
@ -58,6 +59,7 @@ export async function create(
|
||||||
id: createdAction.id,
|
id: createdAction.id,
|
||||||
name: createdAction.name,
|
name: createdAction.name,
|
||||||
automationId: createdAction.automationId,
|
automationId: createdAction.automationId,
|
||||||
|
allowedViews: undefined,
|
||||||
}
|
}
|
||||||
ctx.status = 201
|
ctx.status = 201
|
||||||
}
|
}
|
||||||
|
@ -77,6 +79,7 @@ export async function update(
|
||||||
id: action.id,
|
id: action.id,
|
||||||
name: action.name,
|
name: action.name,
|
||||||
automationId: action.automationId,
|
automationId: action.automationId,
|
||||||
|
allowedViews: undefined,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,18 +91,52 @@ export async function remove(ctx: Ctx<void, void>) {
|
||||||
ctx.status = 204
|
ctx.status = 204
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setViewPermission(ctx: Ctx<void, void>) {
|
export async function setViewPermission(ctx: Ctx<void, RowActionResponse>) {
|
||||||
const table = await getTable(ctx)
|
const table = await getTable(ctx)
|
||||||
const { actionId, viewId } = ctx.params
|
const { actionId, viewId } = ctx.params
|
||||||
|
|
||||||
await sdk.rowActions.setViewPermission(table._id!, actionId, viewId)
|
const action = await sdk.rowActions.setViewPermission(
|
||||||
ctx.status = 204
|
table._id!,
|
||||||
|
actionId,
|
||||||
|
viewId
|
||||||
|
)
|
||||||
|
ctx.body = {
|
||||||
|
tableId: table._id!,
|
||||||
|
id: action.id,
|
||||||
|
name: action.name,
|
||||||
|
automationId: action.automationId,
|
||||||
|
allowedViews: flattenAllowedViews(action.permissions.views),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unsetViewPermission(ctx: Ctx<void, void>) {
|
export async function unsetViewPermission(ctx: Ctx<void, RowActionResponse>) {
|
||||||
const table = await getTable(ctx)
|
const table = await getTable(ctx)
|
||||||
const { actionId, viewId } = ctx.params
|
const { actionId, viewId } = ctx.params
|
||||||
|
|
||||||
await sdk.rowActions.unsetViewPermission(table._id!, actionId, viewId)
|
const action = await sdk.rowActions.unsetViewPermission(
|
||||||
ctx.status = 204
|
table._id!,
|
||||||
|
actionId,
|
||||||
|
viewId
|
||||||
|
)
|
||||||
|
|
||||||
|
ctx.body = {
|
||||||
|
tableId: table._id!,
|
||||||
|
id: action.id,
|
||||||
|
name: action.name,
|
||||||
|
automationId: action.automationId,
|
||||||
|
allowedViews: flattenAllowedViews(action.permissions.views),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function flattenAllowedViews(
|
||||||
|
permissions: Record<string, { runAllowed: boolean }>
|
||||||
|
) {
|
||||||
|
const allowedPermissions = Object.entries(permissions || {})
|
||||||
|
.filter(([_, p]) => p.runAllowed)
|
||||||
|
.map(([viewId]) => viewId)
|
||||||
|
if (!allowedPermissions.length) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
return allowedPermissions
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ export async function create(tableId: string, rowAction: { name: string }) {
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
doc = { _id: rowActionsId, tableId, actions: {} }
|
doc = { _id: rowActionsId, actions: {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureUniqueAndThrow(doc, action.name)
|
ensureUniqueAndThrow(doc, action.name)
|
||||||
|
|
|
@ -81,10 +81,7 @@ export class RowActionAPI extends TestAPI {
|
||||||
return await this._post<RowActionResponse>(
|
return await this._post<RowActionResponse>(
|
||||||
`/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
|
`/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
|
||||||
{
|
{
|
||||||
expectations: {
|
expectations,
|
||||||
...expectations,
|
|
||||||
status: expectations?.status || 204,
|
|
||||||
},
|
|
||||||
...config,
|
...config,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -100,10 +97,7 @@ export class RowActionAPI extends TestAPI {
|
||||||
return await this._delete<RowActionResponse>(
|
return await this._delete<RowActionResponse>(
|
||||||
`/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
|
`/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
|
||||||
{
|
{
|
||||||
expectations: {
|
expectations,
|
||||||
...expectations,
|
|
||||||
status: expectations?.status || 204,
|
|
||||||
},
|
|
||||||
...config,
|
...config,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { Document } from "../document"
|
||||||
|
|
||||||
export interface TableRowActions extends Document {
|
export interface TableRowActions extends Document {
|
||||||
_id: string
|
_id: string
|
||||||
tableId: string
|
|
||||||
actions: Record<string, RowActionData>
|
actions: Record<string, RowActionData>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue