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": { "forceResetPassword": {
"description": "If set to true forces the user to reset their password on first login.", "description": "If set to true forces the user to reset their password on first login.",
"type": "boolean" "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": [ "required": [
@ -1559,6 +1587,34 @@
"description": "If set to true forces the user to reset their password on first login.", "description": "If set to true forces the user to reset their password on first login.",
"type": "boolean" "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": { "_id": {
"description": "The ID of the user.", "description": "The ID of the user.",
"type": "string" "type": "string"
@ -1610,6 +1666,34 @@
"description": "If set to true forces the user to reset their password on first login.", "description": "If set to true forces the user to reset their password on first login.",
"type": "boolean" "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": { "_id": {
"description": "The ID of the user.", "description": "The ID of the user.",
"type": "string" "type": "string"
@ -1753,29 +1837,26 @@
"rolesAssign": { "rolesAssign": {
"type": "object", "type": "object",
"properties": { "properties": {
"builder": { "appBuilder": {
"type": "object", "type": "object",
"properties": { "properties": {
"global": { "appId": {
"type": "boolean" "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": [ "required": [
"global" "appId"
] ]
}, },
"builder": {
"type": "boolean",
"description": "Add/remove global builder permissions from the list of users."
},
"admin": { "admin": {
"type": "object", "type": "boolean",
"properties": { "description": "Add/remove global admin permissions from the list of users."
"global": {
"type": "boolean"
}
},
"description": "Add/remove global admin permissions from the list of users.",
"required": [
"global"
]
}, },
"role": { "role": {
"type": "object", "type": "object",
@ -1810,29 +1891,26 @@
"rolesUnAssign": { "rolesUnAssign": {
"type": "object", "type": "object",
"properties": { "properties": {
"builder": { "appBuilder": {
"type": "object", "type": "object",
"properties": { "properties": {
"global": { "appId": {
"type": "boolean" "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": [ "required": [
"global" "appId"
] ]
}, },
"builder": {
"type": "boolean",
"description": "Add/remove global builder permissions from the list of users."
},
"admin": { "admin": {
"type": "object", "type": "boolean",
"properties": { "description": "Add/remove global admin permissions from the list of users."
"global": {
"type": "boolean"
}
},
"description": "Add/remove global admin permissions from the list of users.",
"required": [
"global"
]
}, },
"role": { "role": {
"type": "object", "type": "object",
@ -1867,16 +1945,24 @@
"rolesOutput": { "rolesOutput": {
"type": "object", "type": "object",
"properties": { "properties": {
"userIds": { "data": {
"description": "The updated users' IDs", "type": "object",
"type": "array", "properties": {
"items": { "userIds": {
"type": "string" "description": "The updated users' IDs",
} "type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"userIds"
]
} }
}, },
"required": [ "required": [
"userIds" "data"
] ]
} }
} }
@ -2235,6 +2321,7 @@
"post": { "post": {
"operationId": "roleAssign", "operationId": "roleAssign",
"summary": "Assign a role to a list of users", "summary": "Assign a role to a list of users",
"description": "This is a business/enterprise only endpoint",
"tags": [ "tags": [
"roles" "roles"
], ],
@ -2266,6 +2353,7 @@
"post": { "post": {
"operationId": "roleUnAssign", "operationId": "roleUnAssign",
"summary": "Un-assign a role from a list of users", "summary": "Un-assign a role from a list of users",
"description": "This is a business/enterprise only endpoint",
"tags": [ "tags": [
"roles" "roles"
], ],

View File

@ -1296,6 +1296,32 @@ components:
description: If set to true forces the user to reset their password on first description: If set to true forces the user to reset their password on first
login. login.
type: boolean 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: required:
- email - email
- roles - roles
@ -1328,6 +1354,32 @@ components:
description: If set to true forces the user to reset their password on first description: If set to true forces the user to reset their password on first
login. login.
type: boolean 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: _id:
description: The ID of the user. description: The ID of the user.
type: string type: string
@ -1368,6 +1420,32 @@ components:
description: If set to true forces the user to reset their password on first description: If set to true forces the user to reset their password on first
login. login.
type: boolean 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: _id:
description: The ID of the user. description: The ID of the user.
type: string type: string
@ -1481,22 +1559,22 @@ components:
rolesAssign: rolesAssign:
type: object type: object
properties: properties:
appBuilder:
type: object
properties:
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: builder:
type: object type: boolean
properties:
global:
type: boolean
description: Add/remove global builder permissions from the list of users. description: Add/remove global builder permissions from the list of users.
required:
- global
admin: admin:
type: object type: boolean
properties:
global:
type: boolean
description: Add/remove global admin permissions from the list of users. description: Add/remove global admin permissions from the list of users.
required:
- global
role: role:
type: object type: object
properties: properties:
@ -1520,22 +1598,22 @@ components:
rolesUnAssign: rolesUnAssign:
type: object type: object
properties: properties:
appBuilder:
type: object
properties:
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: builder:
type: object type: boolean
properties:
global:
type: boolean
description: Add/remove global builder permissions from the list of users. description: Add/remove global builder permissions from the list of users.
required:
- global
admin: admin:
type: object type: boolean
properties:
global:
type: boolean
description: Add/remove global admin permissions from the list of users. description: Add/remove global admin permissions from the list of users.
required:
- global
role: role:
type: object type: object
properties: properties:
@ -1559,13 +1637,18 @@ components:
rolesOutput: rolesOutput:
type: object type: object
properties: properties:
userIds: data:
description: The updated users' IDs type: object
type: array properties:
items: userIds:
type: string description: The updated users' IDs
type: array
items:
type: string
required:
- userIds
required: required:
- userIds - data
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
paths: paths:
@ -1780,6 +1863,7 @@ paths:
post: post:
operationId: roleAssign operationId: roleAssign
summary: Assign a role to a list of users summary: Assign a role to a list of users
description: This is a business/enterprise only endpoint
tags: tags:
- roles - roles
requestBody: requestBody:
@ -1799,6 +1883,7 @@ paths:
post: post:
operationId: roleUnAssign operationId: roleUnAssign
summary: Un-assign a role from a list of users summary: Un-assign a role from a list of users
description: This is a business/enterprise only endpoint
tags: tags:
- roles - roles
requestBody: requestBody:

View File

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

View File

@ -16,6 +16,10 @@ export type CreateRowParams = components["schemas"]["row"]
export type User = components["schemas"]["userOutput"]["data"] export type User = components["schemas"]["userOutput"]["data"]
export type CreateUserParams = components["schemas"]["user"] 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 = export type SearchInputParams =
| components["schemas"]["nameSearch"] | components["schemas"]["nameSearch"]
| components["schemas"]["rowSearch"] | components["schemas"]["rowSearch"]

View File

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

View File

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

View File

@ -35,9 +35,11 @@ export interface paths {
post: operations["querySearch"]; post: operations["querySearch"];
}; };
"/roles/assign": { "/roles/assign": {
/** This is a business/enterprise only endpoint */
post: operations["roleAssign"]; post: operations["roleAssign"];
}; };
"/roles/unassign": { "/roles/unassign": {
/** This is a business/enterprise only endpoint */
post: operations["roleUnAssign"]; post: operations["roleUnAssign"];
}; };
"/tables/{tableId}/rows": { "/tables/{tableId}/rows": {
@ -586,8 +588,18 @@ export interface components {
lastName?: string; lastName?: string;
/** @description If set to true forces the user to reset their password on first login. */ /** @description If set to true forces the user to reset their password on first login. */
forceResetPassword?: boolean; 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. */
roles: unknown; 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: { userOutput: {
data: { data: {
@ -606,14 +618,24 @@ export interface components {
lastName?: string; lastName?: string;
/** @description If set to true forces the user to reset their password on first login. */ /** @description If set to true forces the user to reset their password on first login. */
forceResetPassword?: boolean; 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. */ /** @description The ID of the user. */
_id: string; _id: string;
} & {
roles: unknown;
}; };
}; };
userSearch: { userSearch: {
data: ({ data: {
/** @description The email address of the user, this must be unique. */ /** @description The email address of the user, this must be unique. */
email: string; 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. */ /** @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; lastName?: string;
/** @description If set to true forces the user to reset their password on first login. */ /** @description If set to true forces the user to reset their password on first login. */
forceResetPassword?: boolean; 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. */ /** @description The ID of the user. */
_id: string; _id: string;
} & { }[];
roles: unknown;
})[];
}; };
rowSearch: { rowSearch: {
query: { query: {
@ -692,14 +724,15 @@ export interface components {
name: string; name: string;
}; };
rolesAssign: { 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. */ /** @description Add/remove global builder permissions from the list of users. */
builder?: { builder?: boolean;
global: boolean;
};
/** @description Add/remove global admin permissions from the list of users. */ /** @description Add/remove global admin permissions from the list of users. */
admin?: { admin?: boolean;
global: boolean;
};
/** @description Add/remove a per-app role, such as BASIC, ADMIN etc. */ /** @description Add/remove a per-app role, such as BASIC, ADMIN etc. */
role?: { role?: {
/** @description The role ID, such as BASIC, ADMIN or a custom role ID. */ /** @description The role ID, such as BASIC, ADMIN or a custom role ID. */
@ -711,14 +744,15 @@ export interface components {
userIds: string[]; userIds: string[];
}; };
rolesUnAssign: { 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. */ /** @description Add/remove global builder permissions from the list of users. */
builder?: { builder?: boolean;
global: boolean;
};
/** @description Add/remove global admin permissions from the list of users. */ /** @description Add/remove global admin permissions from the list of users. */
admin?: { admin?: boolean;
global: boolean;
};
/** @description Add/remove a per-app role, such as BASIC, ADMIN etc. */ /** @description Add/remove a per-app role, such as BASIC, ADMIN etc. */
role?: { role?: {
/** @description The role ID, such as BASIC, ADMIN or a custom role ID. */ /** @description The role ID, such as BASIC, ADMIN or a custom role ID. */
@ -730,8 +764,10 @@ export interface components {
userIds: string[]; userIds: string[];
}; };
rolesOutput: { rolesOutput: {
/** @description The updated users' IDs */ data: {
userIds: string[]; /** @description The updated users' IDs */
userIds: string[];
};
}; };
}; };
parameters: { parameters: {
@ -928,6 +964,7 @@ export interface operations {
}; };
}; };
}; };
/** This is a business/enterprise only endpoint */
roleAssign: { roleAssign: {
responses: { responses: {
/** Returns a list of updated user IDs */ /** Returns a list of updated user IDs */
@ -943,6 +980,7 @@ export interface operations {
}; };
}; };
}; };
/** This is a business/enterprise only endpoint */
roleUnAssign: { roleUnAssign: {
responses: { responses: {
/** Returns a list of updated user IDs */ /** Returns a list of updated user IDs */

View File

@ -1,3 +1,2 @@
export * from "./account" export * from "./account"
export * from "./web" 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[]
}