From 54c11e33c5f649f52389e39a77b343d84cec1a62 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 5 Dec 2024 15:56:04 +0000 Subject: [PATCH] Role API typing. --- packages/types/src/api/web/global/index.ts | 1 + packages/types/src/api/web/global/role.ts | 17 +++++++++++++++++ .../worker/src/api/controllers/global/roles.ts | 14 ++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 packages/types/src/api/web/global/role.ts diff --git a/packages/types/src/api/web/global/index.ts b/packages/types/src/api/web/global/index.ts index 0cabb97974..e0c585a932 100644 --- a/packages/types/src/api/web/global/index.ts +++ b/packages/types/src/api/web/global/index.ts @@ -6,3 +6,4 @@ export * from "./scim" export * from "./license" export * from "./oldMigration" export * from "./email" +export * from "./role" diff --git a/packages/types/src/api/web/global/role.ts b/packages/types/src/api/web/global/role.ts new file mode 100644 index 0000000000..1d45995fd2 --- /dev/null +++ b/packages/types/src/api/web/global/role.ts @@ -0,0 +1,17 @@ +import { Role } from "../../../documents" + +interface GlobalRoleResponse { + roles: Role[] + name: string + version: string + url?: string +} + +export interface FetchGlobalRolesResponse + extends Record {} + +export interface FindGlobalRoleResponse extends GlobalRoleResponse {} + +export interface RemoveAppRoleResponse { + message: string +} diff --git a/packages/worker/src/api/controllers/global/roles.ts b/packages/worker/src/api/controllers/global/roles.ts index e1a3130924..fb93ab504c 100644 --- a/packages/worker/src/api/controllers/global/roles.ts +++ b/packages/worker/src/api/controllers/global/roles.ts @@ -6,9 +6,15 @@ import { tenancy, } from "@budibase/backend-core" import sdk from "../../../sdk" -import { Ctx, App } from "@budibase/types" +import { + Ctx, + App, + FetchGlobalRolesResponse, + FindGlobalRoleResponse, + RemoveAppRoleResponse, +} from "@budibase/types" -export async function fetch(ctx: Ctx) { +export async function fetch(ctx: Ctx) { const tenantId = ctx.user!.tenantId // always use the dev apps as they'll be most up to date (true) const apps = (await dbCore.getAllApps({ tenantId, all: true })) as App[] @@ -31,7 +37,7 @@ export async function fetch(ctx: Ctx) { ctx.body = response } -export async function find(ctx: Ctx) { +export async function find(ctx: Ctx) { const appId = ctx.params.appId await context.doInAppContext(dbCore.getDevAppID(appId), async () => { const db = context.getAppDB() @@ -45,7 +51,7 @@ export async function find(ctx: Ctx) { }) } -export async function removeAppRole(ctx: Ctx) { +export async function removeAppRole(ctx: Ctx) { const { appId } = ctx.params const db = tenancy.getGlobalDB() const users = await sdk.users.db.allUsers()