Updating types to be based on the open API definition rather than types.

This commit is contained in:
mike12345567 2023-08-15 17:33:22 +01:00
parent a6a70c2d09
commit 8f81a16340
11 changed files with 340 additions and 147 deletions

View File

@ -1519,6 +1519,34 @@
"forceResetPassword": {
"description": "If set to true forces the user to reset their password on first login.",
"type": "boolean"
},
"builder": {
"description": "Describes if the user is a builder user or not. This field can only be set on a business or enterprise license.",
"type": "object",
"properties": {
"global": {
"description": "If set to true the user will be able to build any app in the system.",
"type": "boolean"
}
}
},
"admin": {
"description": "Describes if the user is an admin user or not. This field can only be set on a business or enterprise license.",
"type": "object",
"properties": {
"global": {
"description": "If set to true the user will be able to administrate the system.",
"type": "boolean"
}
}
},
"roles": {
"description": "Contains the roles of the user per app (assuming they are not a builder user). This field can only be set on a business or enterprise license.",
"type": "object",
"additionalProperties": {
"type": "string",
"description": "A map of app ID (production app ID, minus the _dev component) to a role ID, e.g. ADMIN."
}
}
},
"required": [
@ -1559,6 +1587,34 @@
"description": "If set to true forces the user to reset their password on first login.",
"type": "boolean"
},
"builder": {
"description": "Describes if the user is a builder user or not. This field can only be set on a business or enterprise license.",
"type": "object",
"properties": {
"global": {
"description": "If set to true the user will be able to build any app in the system.",
"type": "boolean"
}
}
},
"admin": {
"description": "Describes if the user is an admin user or not. This field can only be set on a business or enterprise license.",
"type": "object",
"properties": {
"global": {
"description": "If set to true the user will be able to administrate the system.",
"type": "boolean"
}
}
},
"roles": {
"description": "Contains the roles of the user per app (assuming they are not a builder user). This field can only be set on a business or enterprise license.",
"type": "object",
"additionalProperties": {
"type": "string",
"description": "A map of app ID (production app ID, minus the _dev component) to a role ID, e.g. ADMIN."
}
},
"_id": {
"description": "The ID of the user.",
"type": "string"
@ -1610,6 +1666,34 @@
"description": "If set to true forces the user to reset their password on first login.",
"type": "boolean"
},
"builder": {
"description": "Describes if the user is a builder user or not. This field can only be set on a business or enterprise license.",
"type": "object",
"properties": {
"global": {
"description": "If set to true the user will be able to build any app in the system.",
"type": "boolean"
}
}
},
"admin": {
"description": "Describes if the user is an admin user or not. This field can only be set on a business or enterprise license.",
"type": "object",
"properties": {
"global": {
"description": "If set to true the user will be able to administrate the system.",
"type": "boolean"
}
}
},
"roles": {
"description": "Contains the roles of the user per app (assuming they are not a builder user). This field can only be set on a business or enterprise license.",
"type": "object",
"additionalProperties": {
"type": "string",
"description": "A map of app ID (production app ID, minus the _dev component) to a role ID, e.g. ADMIN."
}
},
"_id": {
"description": "The ID of the user.",
"type": "string"
@ -1753,29 +1837,26 @@
"rolesAssign": {
"type": "object",
"properties": {
"builder": {
"appBuilder": {
"type": "object",
"properties": {
"global": {
"type": "boolean"
"appId": {
"description": "The app that the users should have app builder privileges granted for.",
"type": "string"
}
},
"description": "Add/remove global builder permissions from the list of users.",
"description": "Allow setting users to builders per app.",
"required": [
"global"
"appId"
]
},
"builder": {
"type": "boolean",
"description": "Add/remove global builder permissions from the list of users."
},
"admin": {
"type": "object",
"properties": {
"global": {
"type": "boolean"
}
},
"description": "Add/remove global admin permissions from the list of users.",
"required": [
"global"
]
"type": "boolean",
"description": "Add/remove global admin permissions from the list of users."
},
"role": {
"type": "object",
@ -1810,29 +1891,26 @@
"rolesUnAssign": {
"type": "object",
"properties": {
"builder": {
"appBuilder": {
"type": "object",
"properties": {
"global": {
"type": "boolean"
"appId": {
"description": "The app that the users should have app builder privileges granted for.",
"type": "string"
}
},
"description": "Add/remove global builder permissions from the list of users.",
"description": "Allow setting users to builders per app.",
"required": [
"global"
"appId"
]
},
"builder": {
"type": "boolean",
"description": "Add/remove global builder permissions from the list of users."
},
"admin": {
"type": "object",
"properties": {
"global": {
"type": "boolean"
}
},
"description": "Add/remove global admin permissions from the list of users.",
"required": [
"global"
]
"type": "boolean",
"description": "Add/remove global admin permissions from the list of users."
},
"role": {
"type": "object",
@ -1865,6 +1943,9 @@
]
},
"rolesOutput": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"userIds": {
@ -1879,6 +1960,11 @@
"userIds"
]
}
},
"required": [
"data"
]
}
}
},
"security": [
@ -2235,6 +2321,7 @@
"post": {
"operationId": "roleAssign",
"summary": "Assign a role to a list of users",
"description": "This is a business/enterprise only endpoint",
"tags": [
"roles"
],
@ -2266,6 +2353,7 @@
"post": {
"operationId": "roleUnAssign",
"summary": "Un-assign a role from a list of users",
"description": "This is a business/enterprise only endpoint",
"tags": [
"roles"
],

View File

@ -1296,6 +1296,32 @@ components:
description: If set to true forces the user to reset their password on first
login.
type: boolean
builder:
description: Describes if the user is a builder user or not. This field can only
be set on a business or enterprise license.
type: object
properties:
global:
description: If set to true the user will be able to build any app in the
system.
type: boolean
admin:
description: Describes if the user is an admin user or not. This field can only
be set on a business or enterprise license.
type: object
properties:
global:
description: If set to true the user will be able to administrate the system.
type: boolean
roles:
description: Contains the roles of the user per app (assuming they are not a
builder user). This field can only be set on a business or
enterprise license.
type: object
additionalProperties:
type: string
description: A map of app ID (production app ID, minus the _dev component) to a
role ID, e.g. ADMIN.
required:
- email
- roles
@ -1328,6 +1354,32 @@ components:
description: If set to true forces the user to reset their password on first
login.
type: boolean
builder:
description: Describes if the user is a builder user or not. This field can only
be set on a business or enterprise license.
type: object
properties:
global:
description: If set to true the user will be able to build any app in the
system.
type: boolean
admin:
description: Describes if the user is an admin user or not. This field can only
be set on a business or enterprise license.
type: object
properties:
global:
description: If set to true the user will be able to administrate the system.
type: boolean
roles:
description: Contains the roles of the user per app (assuming they are not a
builder user). This field can only be set on a business or
enterprise license.
type: object
additionalProperties:
type: string
description: A map of app ID (production app ID, minus the _dev component) to a
role ID, e.g. ADMIN.
_id:
description: The ID of the user.
type: string
@ -1368,6 +1420,32 @@ components:
description: If set to true forces the user to reset their password on first
login.
type: boolean
builder:
description: Describes if the user is a builder user or not. This field can only
be set on a business or enterprise license.
type: object
properties:
global:
description: If set to true the user will be able to build any app in the
system.
type: boolean
admin:
description: Describes if the user is an admin user or not. This field can only
be set on a business or enterprise license.
type: object
properties:
global:
description: If set to true the user will be able to administrate the system.
type: boolean
roles:
description: Contains the roles of the user per app (assuming they are not a
builder user). This field can only be set on a business or
enterprise license.
type: object
additionalProperties:
type: string
description: A map of app ID (production app ID, minus the _dev component) to a
role ID, e.g. ADMIN.
_id:
description: The ID of the user.
type: string
@ -1481,22 +1559,22 @@ components:
rolesAssign:
type: object
properties:
builder:
appBuilder:
type: object
properties:
global:
appId:
description: The app that the users should have app builder privileges granted
for.
type: string
description: Allow setting users to builders per app.
required:
- appId
builder:
type: boolean
description: Add/remove global builder permissions from the list of users.
required:
- global
admin:
type: object
properties:
global:
type: boolean
description: Add/remove global admin permissions from the list of users.
required:
- global
role:
type: object
properties:
@ -1520,22 +1598,22 @@ components:
rolesUnAssign:
type: object
properties:
builder:
appBuilder:
type: object
properties:
global:
appId:
description: The app that the users should have app builder privileges granted
for.
type: string
description: Allow setting users to builders per app.
required:
- appId
builder:
type: boolean
description: Add/remove global builder permissions from the list of users.
required:
- global
admin:
type: object
properties:
global:
type: boolean
description: Add/remove global admin permissions from the list of users.
required:
- global
role:
type: object
properties:
@ -1557,6 +1635,9 @@ components:
required:
- userIds
rolesOutput:
type: object
properties:
data:
type: object
properties:
userIds:
@ -1566,6 +1647,8 @@ components:
type: string
required:
- userIds
required:
- data
security:
- ApiKeyAuth: []
paths:
@ -1780,6 +1863,7 @@ paths:
post:
operationId: roleAssign
summary: Assign a role to a list of users
description: This is a business/enterprise only endpoint
tags:
- roles
requestBody:
@ -1799,6 +1883,7 @@ paths:
post:
operationId: roleUnAssign
summary: Un-assign a role from a list of users
description: This is a business/enterprise only endpoint
tags:
- roles
requestBody:

View File

@ -3,35 +3,26 @@ import Resource from "./utils/Resource"
const roleSchema = object(
{
appBuilder: object({
appBuilder: object(
{
appId: {
description:
"The app that the users should have app builder privileges granted for.",
type: "string",
},
}),
builder: object(
{
global: {
},
{ description: "Allow setting users to builders per app." }
),
builder: {
type: "boolean",
},
},
{
description:
"Add/remove global builder permissions from the list of users.",
}
),
admin: object(
{
global: {
},
admin: {
type: "boolean",
},
},
{
description:
"Add/remove global admin permissions from the list of users.",
}
),
},
role: object(
{
roleId: {
@ -61,6 +52,7 @@ export default new Resource().setSchemas({
rolesAssign: roleSchema,
rolesUnAssign: roleSchema,
rolesOutput: object({
data: object({
userIds: {
description: "The updated users' IDs",
type: "array",
@ -69,4 +61,5 @@ export default new Resource().setSchemas({
},
},
}),
}),
})

View File

@ -16,6 +16,10 @@ export type CreateRowParams = components["schemas"]["row"]
export type User = components["schemas"]["userOutput"]["data"]
export type CreateUserParams = components["schemas"]["user"]
export type RoleAssignRequest = components["schemas"]["rolesAssign"]
export type RoleUnAssignRequest = components["schemas"]["rolesUnAssign"]
export type RoleAssignmentResponse = components["schemas"]["rolesOutput"]
export type SearchInputParams =
| components["schemas"]["nameSearch"]
| components["schemas"]["rowSearch"]

View File

@ -1,28 +1,29 @@
import {
UserCtx,
RoleAssignmentResponse,
RoleAssignmentRequest,
} from "@budibase/types"
import { UserCtx } from "@budibase/types"
import { Next } from "koa"
import { sdk } from "@budibase/pro"
import {
RoleAssignmentResponse,
RoleUnAssignRequest,
RoleAssignRequest,
} from "./mapping/types"
async function assign(
ctx: UserCtx<RoleAssignmentRequest, RoleAssignmentResponse>,
ctx: UserCtx<RoleAssignRequest, RoleAssignmentResponse>,
next: Next
) {
const { userIds, ...assignmentProps } = ctx.request.body
await sdk.publicApi.roles.assign(userIds, assignmentProps)
ctx.body = { userIds }
ctx.body = { data: { userIds } }
await next()
}
async function unAssign(
ctx: UserCtx<RoleAssignmentRequest, RoleAssignmentResponse>,
ctx: UserCtx<RoleUnAssignRequest, RoleAssignmentResponse>,
next: Next
) {
const { userIds, ...unAssignmentProps } = ctx.request.body
await sdk.publicApi.roles.unAssign(userIds, unAssignmentProps)
ctx.body = { userIds }
ctx.body = { data: { userIds } }
await next()
}

View File

@ -9,6 +9,7 @@ const write = []
* post:
* operationId: roleAssign
* summary: Assign a role to a list of users
* description: This is a business/enterprise only endpoint
* tags:
* - roles
* requestBody:
@ -33,6 +34,7 @@ write.push(new Endpoint("post", "/roles/assign", controller.assign))
* post:
* operationId: roleUnAssign
* summary: Un-assign a role from a list of users
* description: This is a business/enterprise only endpoint
* tags:
* - roles
* requestBody:

View File

@ -35,9 +35,11 @@ export interface paths {
post: operations["querySearch"];
};
"/roles/assign": {
/** This is a business/enterprise only endpoint */
post: operations["roleAssign"];
};
"/roles/unassign": {
/** This is a business/enterprise only endpoint */
post: operations["roleUnAssign"];
};
"/tables/{tableId}/rows": {
@ -586,8 +588,18 @@ export interface components {
lastName?: string;
/** @description If set to true forces the user to reset their password on first login. */
forceResetPassword?: boolean;
} & {
roles: unknown;
/** @description Describes if the user is a builder user or not. This field can only be set on a business or enterprise license. */
builder?: {
/** @description If set to true the user will be able to build any app in the system. */
global?: boolean;
};
/** @description Describes if the user is an admin user or not. This field can only be set on a business or enterprise license. */
admin?: {
/** @description If set to true the user will be able to administrate the system. */
global?: boolean;
};
/** @description Contains the roles of the user per app (assuming they are not a builder user). This field can only be set on a business or enterprise license. */
roles: { [key: string]: string };
};
userOutput: {
data: {
@ -606,14 +618,24 @@ export interface components {
lastName?: string;
/** @description If set to true forces the user to reset their password on first login. */
forceResetPassword?: boolean;
/** @description Describes if the user is a builder user or not. This field can only be set on a business or enterprise license. */
builder?: {
/** @description If set to true the user will be able to build any app in the system. */
global?: boolean;
};
/** @description Describes if the user is an admin user or not. This field can only be set on a business or enterprise license. */
admin?: {
/** @description If set to true the user will be able to administrate the system. */
global?: boolean;
};
/** @description Contains the roles of the user per app (assuming they are not a builder user). This field can only be set on a business or enterprise license. */
roles: { [key: string]: string };
/** @description The ID of the user. */
_id: string;
} & {
roles: unknown;
};
};
userSearch: {
data: ({
data: {
/** @description The email address of the user, this must be unique. */
email: string;
/** @description The password of the user if using password based login - this will never be returned. This can be left out of subsequent requests (updates) and will be enriched back into the user structure. */
@ -629,11 +651,21 @@ export interface components {
lastName?: string;
/** @description If set to true forces the user to reset their password on first login. */
forceResetPassword?: boolean;
/** @description Describes if the user is a builder user or not. This field can only be set on a business or enterprise license. */
builder?: {
/** @description If set to true the user will be able to build any app in the system. */
global?: boolean;
};
/** @description Describes if the user is an admin user or not. This field can only be set on a business or enterprise license. */
admin?: {
/** @description If set to true the user will be able to administrate the system. */
global?: boolean;
};
/** @description Contains the roles of the user per app (assuming they are not a builder user). This field can only be set on a business or enterprise license. */
roles: { [key: string]: string };
/** @description The ID of the user. */
_id: string;
} & {
roles: unknown;
})[];
}[];
};
rowSearch: {
query: {
@ -692,14 +724,15 @@ export interface components {
name: string;
};
rolesAssign: {
/** @description Allow setting users to builders per app. */
appBuilder?: {
/** @description The app that the users should have app builder privileges granted for. */
appId: string;
};
/** @description Add/remove global builder permissions from the list of users. */
builder?: {
global: boolean;
};
builder?: boolean;
/** @description Add/remove global admin permissions from the list of users. */
admin?: {
global: boolean;
};
admin?: boolean;
/** @description Add/remove a per-app role, such as BASIC, ADMIN etc. */
role?: {
/** @description The role ID, such as BASIC, ADMIN or a custom role ID. */
@ -711,14 +744,15 @@ export interface components {
userIds: string[];
};
rolesUnAssign: {
/** @description Allow setting users to builders per app. */
appBuilder?: {
/** @description The app that the users should have app builder privileges granted for. */
appId: string;
};
/** @description Add/remove global builder permissions from the list of users. */
builder?: {
global: boolean;
};
builder?: boolean;
/** @description Add/remove global admin permissions from the list of users. */
admin?: {
global: boolean;
};
admin?: boolean;
/** @description Add/remove a per-app role, such as BASIC, ADMIN etc. */
role?: {
/** @description The role ID, such as BASIC, ADMIN or a custom role ID. */
@ -730,10 +764,12 @@ export interface components {
userIds: string[];
};
rolesOutput: {
data: {
/** @description The updated users' IDs */
userIds: string[];
};
};
};
parameters: {
/** @description The ID of the table which this request is targeting. */
tableId: string;
@ -928,6 +964,7 @@ export interface operations {
};
};
};
/** This is a business/enterprise only endpoint */
roleAssign: {
responses: {
/** Returns a list of updated user IDs */
@ -943,6 +980,7 @@ export interface operations {
};
};
};
/** This is a business/enterprise only endpoint */
roleUnAssign: {
responses: {
/** Returns a list of updated user IDs */

View File

@ -1,3 +1,2 @@
export * from "./account"
export * from "./web"
export * from "./public"

View File

View File

@ -1 +0,0 @@
export * from "./roles"

View File

@ -1,16 +0,0 @@
export interface RoleAssignmentRequest {
role?: {
appId: string
roleId: string
}
appBuilder?: {
appId: string
}
builder?: boolean
admin?: boolean
userIds: string[]
}
export interface RoleAssignmentResponse {
userIds: string[]
}