From b9b4f88e4a256032d21eed6e92239398b4263c1d Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 29 Oct 2024 10:23:32 +0000 Subject: [PATCH 01/10] Fix default values when using multi-option column and supplying empty array. --- packages/server/src/api/routes/tests/row.spec.ts | 13 +++++++++++++ packages/server/src/utilities/rowProcessor/index.ts | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 66e931d0ab..42c3560b36 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -763,12 +763,25 @@ describe.each([ expect(row.food).toEqual(["apple", "orange"]) }) + it("creates a new row with a default value when given an empty list", async () => { + const row = await config.api.row.save(table._id!, { food: [] }) + expect(row.food).toEqual(["apple", "orange"]) + }) + it("does not use default value if value specified", async () => { const row = await config.api.row.save(table._id!, { food: ["orange"], }) expect(row.food).toEqual(["orange"]) }) + + it("resets back to its default value when empty", async () => { + let row = await config.api.row.save(table._id!, { + food: ["orange"], + }) + row = await config.api.row.save(table._id!, { ...row, food: [] }) + expect(row.food).toEqual(["apple", "orange"]) + }) }) describe("user column", () => { diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index 0ffa7600aa..d5cbbd2b64 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -20,6 +20,7 @@ import { User, ViewV2, FeatureFlag, + Document, } from "@budibase/types" import { cloneDeep } from "lodash/fp" import { @@ -134,7 +135,12 @@ async function processDefaultValues(table: Table, row: Row) { } for (const [key, schema] of Object.entries(table.schema)) { - if ("default" in schema && schema.default != null && row[key] == null) { + const isEmpty = + row[key] == null || + row[key] === "" || + (Array.isArray(row[key]) && row[key].length === 0) + + if ("default" in schema && schema.default != null && isEmpty) { let processed: string | string[] if (Array.isArray(schema.default)) { processed = schema.default.map(val => processStringSync(val, ctx)) From 67fea783bb46820dae8ab97bc9c3687d6fe72bc0 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 29 Oct 2024 10:29:41 +0000 Subject: [PATCH 02/10] Support boolean and bigint fields having default values. --- .../server/src/api/routes/tests/row.spec.ts | 56 +++++++++++++++++++ packages/shared-core/src/table.ts | 4 +- .../types/src/documents/app/table/schema.ts | 14 +++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 2980803fbc..1cb6afe58b 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -835,6 +835,62 @@ describe.each([ }) }) + describe("boolean column", () => { + beforeAll(async () => { + table = await config.api.table.save( + saveTableRequest({ + schema: { + active: { + name: "active", + type: FieldType.BOOLEAN, + default: "true", + }, + }, + }) + ) + }) + + it("creates a new row with a default value successfully", async () => { + const row = await config.api.row.save(table._id!, {}) + expect(row.active).toEqual(true) + }) + + it("does not use default value if value specified", async () => { + const row = await config.api.row.save(table._id!, { + active: false, + }) + expect(row.active).toEqual(false) + }) + }) + + describe("bigint column", () => { + beforeAll(async () => { + table = await config.api.table.save( + saveTableRequest({ + schema: { + bigNumber: { + name: "bigNumber", + type: FieldType.BIGINT, + default: "1234567890", + }, + }, + }) + ) + }) + + it("creates a new row with a default value successfully", async () => { + const row = await config.api.row.save(table._id!, {}) + expect(row.bigNumber).toEqual("1234567890") + }) + + it("does not use default value if value specified", async () => { + const row = await config.api.row.save(table._id!, { + bigNumber: "9876543210", + }) + expect(row.bigNumber).toEqual("9876543210") + }) + }) + describe("bindings", () => { describe("string column", () => { beforeAll(async () => { diff --git a/packages/shared-core/src/table.ts b/packages/shared-core/src/table.ts index 73e3ad6cb7..5402439d9c 100644 --- a/packages/shared-core/src/table.ts +++ b/packages/shared-core/src/table.ts @@ -57,12 +57,12 @@ const allowDefaultColumnByType: Record = { [FieldType.STRING]: true, [FieldType.OPTIONS]: true, [FieldType.ARRAY]: true, + [FieldType.BIGINT]: true, + [FieldType.BOOLEAN]: true, [FieldType.AUTO]: false, [FieldType.INTERNAL]: false, [FieldType.BARCODEQR]: false, - [FieldType.BIGINT]: false, - [FieldType.BOOLEAN]: false, [FieldType.FORMULA]: false, [FieldType.AI]: false, [FieldType.ATTACHMENTS]: false, diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 45d0aa78d2..9e4555e1a2 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -198,6 +198,16 @@ interface BaseFieldSchema extends UIFieldMetadata { subtype?: never } +interface BooleanFieldMetadata extends BaseFieldSchema { + type: FieldType.BOOLEAN + default?: string +} + +interface BigIntFieldMetadata extends BaseFieldSchema { + type: FieldType.BIGINT + default?: string +} + interface OtherFieldMetadata extends BaseFieldSchema { type: Exclude< FieldType, @@ -214,6 +224,8 @@ interface OtherFieldMetadata extends BaseFieldSchema { | FieldType.STRING | FieldType.ARRAY | FieldType.OPTIONS + | FieldType.BOOLEAN + | FieldType.BIGINT > } @@ -233,6 +245,8 @@ export type FieldSchema = | BBReferenceSingleFieldMetadata | ArrayFieldMetadata | OptionsFieldMetadata + | BooleanFieldMetadata + | BigIntFieldMetadata export interface TableSchema { [key: string]: FieldSchema From 0c8590be9c43a4ecdda68bad35746378b9c1529b Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 29 Oct 2024 10:32:49 +0000 Subject: [PATCH 03/10] Fix lint. --- packages/server/src/utilities/rowProcessor/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index d5cbbd2b64..ed74394a85 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -20,7 +20,6 @@ import { User, ViewV2, FeatureFlag, - Document, } from "@budibase/types" import { cloneDeep } from "lodash/fp" import { From b58fd7dc6b0e92976c330901b7b21b07b19163d1 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 29 Oct 2024 10:34:14 +0000 Subject: [PATCH 04/10] Fix OSS build. --- .../types/src/documents/app/table/schema.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/types/src/documents/app/table/schema.ts b/packages/types/src/documents/app/table/schema.ts index 9e4555e1a2..7e79902a49 100644 --- a/packages/types/src/documents/app/table/schema.ts +++ b/packages/types/src/documents/app/table/schema.ts @@ -186,6 +186,16 @@ export interface ArrayFieldMetadata extends BaseFieldSchema { default?: string[] } +export interface BooleanFieldMetadata extends BaseFieldSchema { + type: FieldType.BOOLEAN + default?: string +} + +export interface BigIntFieldMetadata extends BaseFieldSchema { + type: FieldType.BIGINT + default?: string +} + interface BaseFieldSchema extends UIFieldMetadata { type: FieldType name: string @@ -198,16 +208,6 @@ interface BaseFieldSchema extends UIFieldMetadata { subtype?: never } -interface BooleanFieldMetadata extends BaseFieldSchema { - type: FieldType.BOOLEAN - default?: string -} - -interface BigIntFieldMetadata extends BaseFieldSchema { - type: FieldType.BIGINT - default?: string -} - interface OtherFieldMetadata extends BaseFieldSchema { type: Exclude< FieldType, From 4da185a8432a5949814222f1dfd0949336b2d219 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 29 Oct 2024 11:00:45 +0000 Subject: [PATCH 05/10] Fixes an issue with public role access, some old roles have a slightly different role ID format which needs to be accounted for in the comparison. Tests will come after, want to get the fix out. --- packages/backend-core/src/security/roles.ts | 31 +++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/backend-core/src/security/roles.ts b/packages/backend-core/src/security/roles.ts index c14178cacb..42a55c16c7 100644 --- a/packages/backend-core/src/security/roles.ts +++ b/packages/backend-core/src/security/roles.ts @@ -219,7 +219,10 @@ export function getBuiltinRole(roleId: string): Role | undefined { export function builtinRoleToNumber(id: string) { const builtins = getBuiltinRoles() const MAX = Object.values(builtins).length + 1 - if (id === BUILTIN_IDS.ADMIN || id === BUILTIN_IDS.BUILDER) { + if ( + compareRoleIds(id, BUILTIN_IDS.ADMIN) || + compareRoleIds(id, BUILTIN_IDS.BUILDER) + ) { return MAX } let role = builtins[id], @@ -256,7 +259,9 @@ export async function roleToNumber(id: string) { // find the built-in roles, get their number, sort it, then get the last one const highestBuiltin: number | undefined = role.inherits .map(roleId => { - const foundRole = hierarchy.find(role => role._id === roleId) + const foundRole = hierarchy.find(role => + compareRoleIds(role._id!, roleId) + ) if (foundRole) { return findNumber(foundRole) + 1 } @@ -380,7 +385,7 @@ async function getAllUserRoles( ): Promise { const allRoles = await getAllRoles() // admins have access to all roles - if (userRoleId === BUILTIN_IDS.ADMIN) { + if (compareRoleIds(userRoleId, BUILTIN_IDS.ADMIN)) { return allRoles } @@ -491,17 +496,21 @@ export async function getAllRoles(appId?: string): Promise { // need to combine builtin with any DB record of them (for sake of permissions) for (let builtinRoleId of externalBuiltinRoles) { const builtinRole = builtinRoles[builtinRoleId] - const dbBuiltin = roles.filter( - dbRole => - getExternalRoleID(dbRole._id!, dbRole.version) === builtinRoleId + const dbBuiltin = roles.filter(dbRole => + compareRoleIds(dbRole._id!, builtinRoleId) )[0] if (dbBuiltin == null) { roles.push(builtinRole || builtinRoles.BASIC) } else { // remove role and all back after combining with the builtin roles = roles.filter(role => role._id !== dbBuiltin._id) - dbBuiltin._id = getExternalRoleID(dbBuiltin._id!, dbBuiltin.version) - roles.push(Object.assign(builtinRole, dbBuiltin)) + dbBuiltin._id = getExternalRoleID(builtinRole._id!, dbBuiltin.version) + roles.push({ + ...builtinRole, + ...dbBuiltin, + name: builtinRole.name, + _id: getExternalRoleID(builtinRole._id!, builtinRole.version), + }) } } // check permissions @@ -544,9 +553,9 @@ export class AccessController { if ( tryingRoleId == null || tryingRoleId === "" || - tryingRoleId === userRoleId || - tryingRoleId === BUILTIN_IDS.BUILDER || - userRoleId === BUILTIN_IDS.BUILDER + compareRoleIds(tryingRoleId, BUILTIN_IDS.BUILDER) || + compareRoleIds(userRoleId!, tryingRoleId) || + compareRoleIds(userRoleId!, BUILTIN_IDS.BUILDER) ) { return true } From 32ad21de4f37704440d03f3e8b812872cd39d0c9 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 29 Oct 2024 11:38:00 +0000 Subject: [PATCH 06/10] Fix forms always requesting table schema and cache view definitions --- .../src/components/app/forms/Form.svelte | 17 ++++---- .../src/components/app/forms/InnerForm.svelte | 6 +-- .../src/components/app/forms/validation.js | 8 ++-- packages/client/src/utils/schema.js | 39 ++++++++++++++----- packages/frontend-core/src/api/viewsV2.js | 1 + 5 files changed, 45 insertions(+), 26 deletions(-) diff --git a/packages/client/src/components/app/forms/Form.svelte b/packages/client/src/components/app/forms/Form.svelte index fe02dc665d..88333f7565 100644 --- a/packages/client/src/components/app/forms/Form.svelte +++ b/packages/client/src/components/app/forms/Form.svelte @@ -3,6 +3,7 @@ import InnerForm from "./InnerForm.svelte" import { Helpers } from "@budibase/bbui" import { writable } from "svelte/store" + import { fetchDatasourceDefinition } from "utils/schema" export let dataSource export let theme @@ -32,9 +33,9 @@ return parsedFormStep } - let loaded = false + let definition let schema - let table + let loaded = false let currentStep = getContext("current-step") || writable(getInitialFormStep()) $: fetchSchema(dataSource) @@ -84,12 +85,10 @@ // Fetches the form schema from this form's dataSource const fetchSchema = async dataSource => { - if (dataSource?.tableId && !dataSource?.type?.startsWith("query")) { - try { - table = await API.fetchTableDefinition(dataSource.tableId) - } catch (error) { - table = null - } + try { + definition = await fetchDatasourceDefinition(dataSource) + } catch (error) { + definition = null } const res = await fetchDatasourceSchema(dataSource) schema = res || {} @@ -121,7 +120,7 @@ {readonly} {actionType} {schema} - {table} + {definition} {initialValues} {disableSchemaValidation} {editAutoColumns} diff --git a/packages/client/src/components/app/forms/InnerForm.svelte b/packages/client/src/components/app/forms/InnerForm.svelte index bb2f51fc95..91a444aa6a 100644 --- a/packages/client/src/components/app/forms/InnerForm.svelte +++ b/packages/client/src/components/app/forms/InnerForm.svelte @@ -10,7 +10,7 @@ export let initialValues export let size export let schema - export let table + export let definition export let disableSchemaValidation = false export let editAutoColumns = false @@ -164,7 +164,7 @@ schemaConstraints, validationRules, field, - table + definition ) // Sanitise the default value to ensure it doesn't contain invalid data @@ -338,7 +338,7 @@ schemaConstraints, validationRules, field, - table + definition ) // Update validator diff --git a/packages/client/src/components/app/forms/validation.js b/packages/client/src/components/app/forms/validation.js index 46a5330cf3..ad3e5ae689 100644 --- a/packages/client/src/components/app/forms/validation.js +++ b/packages/client/src/components/app/forms/validation.js @@ -5,17 +5,17 @@ import { Helpers } from "@budibase/bbui" /** * Creates a validation function from a combination of schema-level constraints * and custom validation rules - * @param schemaConstraints any schema level constraints from the table + * @param schemaConstraints any schema level constraints from the datasource * @param customRules any custom validation rules * @param field the field name we are evaluating - * @param table the definition of the table we are evaluating + * @param definition the definition of the datasource we are evaluating * @returns {function} a validator function which accepts test values */ export const createValidatorFromConstraints = ( schemaConstraints, customRules, field, - table + definition ) => { let rules = [] @@ -23,7 +23,7 @@ export const createValidatorFromConstraints = ( if (schemaConstraints) { // Required constraint if ( - field === table?.primaryDisplay || + field === definition?.primaryDisplay || schemaConstraints.presence?.allowEmpty === false || schemaConstraints.presence === true ) { diff --git a/packages/client/src/utils/schema.js b/packages/client/src/utils/schema.js index e2399e8738..ec1cef53ce 100644 --- a/packages/client/src/utils/schema.js +++ b/packages/client/src/utils/schema.js @@ -10,16 +10,13 @@ import ViewV2Fetch from "@budibase/frontend-core/src/fetch/ViewV2Fetch.js" import QueryArrayFetch from "@budibase/frontend-core/src/fetch/QueryArrayFetch" /** - * Fetches the schema of any kind of datasource. + * Constructs a fetch instance for a given datasource. * All datasource fetch classes implement their own functionality to get the * schema of a datasource of their respective types. - * @param datasource the datasource to fetch the schema for - * @param options options for enriching the schema + * @param datasource the datasource + * @returns */ -export const fetchDatasourceSchema = async ( - datasource, - options = { enrichRelationships: false, formSchema: false } -) => { +const getDatasourceFetchInstance = datasource => { const handler = { table: TableFetch, view: ViewFetch, @@ -34,10 +31,23 @@ export const fetchDatasourceSchema = async ( if (!handler) { return null } - const instance = new handler({ API }) + return new handler({ API }) +} - // Get the datasource definition and then schema - const definition = await instance.getDefinition(datasource) +/** + * Fetches the schema of any kind of datasource. + * @param datasource the datasource to fetch the schema for + * @param options options for enriching the schema + */ +export const fetchDatasourceSchema = async ( + datasource, + options = { enrichRelationships: false, formSchema: false } +) => { + const instance = getDatasourceFetchInstance(datasource) + const definition = await instance?.getDefinition(datasource) + if (!definition) { + return null + } // Get the normal schema as long as we aren't wanting a form schema let schema @@ -75,6 +85,15 @@ export const fetchDatasourceSchema = async ( return instance.enrichSchema(schema) } +/** + * Fetches the definition of any kind of datasource. + * @param datasource the datasource to fetch the schema for + */ +export const fetchDatasourceDefinition = async datasource => { + const instance = getDatasourceFetchInstance(datasource) + return await instance?.getDefinition(datasource) +} + /** * Fetches the schema of relationship fields for a SQL table schema * @param schema the schema to enrich diff --git a/packages/frontend-core/src/api/viewsV2.js b/packages/frontend-core/src/api/viewsV2.js index a2072c2e1d..d1cb07c6b0 100644 --- a/packages/frontend-core/src/api/viewsV2.js +++ b/packages/frontend-core/src/api/viewsV2.js @@ -6,6 +6,7 @@ export const buildViewV2Endpoints = API => ({ fetchDefinition: async viewId => { return await API.get({ url: `/api/v2/views/${encodeURIComponent(viewId)}`, + cache: true, }) }, /** From 7cce68f126b4405a7f5276443d4f54e0f00558b3 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 29 Oct 2024 11:44:03 +0000 Subject: [PATCH 07/10] Provide fetchDatasourceDefinition via SDK --- packages/client/src/components/app/forms/Form.svelte | 4 ++-- packages/client/src/sdk.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/client/src/components/app/forms/Form.svelte b/packages/client/src/components/app/forms/Form.svelte index 88333f7565..2071e85fcc 100644 --- a/packages/client/src/components/app/forms/Form.svelte +++ b/packages/client/src/components/app/forms/Form.svelte @@ -3,7 +3,6 @@ import InnerForm from "./InnerForm.svelte" import { Helpers } from "@budibase/bbui" import { writable } from "svelte/store" - import { fetchDatasourceDefinition } from "utils/schema" export let dataSource export let theme @@ -23,7 +22,8 @@ const context = getContext("context") const component = getContext("component") - const { API, fetchDatasourceSchema } = getContext("sdk") + const { API, fetchDatasourceSchema, detchDatasourceDefinition } = + getContext("sdk") const getInitialFormStep = () => { const parsedFormStep = parseInt(initialFormStep) diff --git a/packages/client/src/sdk.js b/packages/client/src/sdk.js index 50d3f857d5..bd51924bf4 100644 --- a/packages/client/src/sdk.js +++ b/packages/client/src/sdk.js @@ -26,7 +26,10 @@ import Provider from "components/context/Provider.svelte" import Block from "components/Block.svelte" import BlockComponent from "components/BlockComponent.svelte" import { ActionTypes } from "./constants" -import { fetchDatasourceSchema } from "./utils/schema.js" +import { + fetchDatasourceSchema, + fetchDatasourceDefinition, +} from "./utils/schema.js" import { getAPIKey } from "./utils/api.js" import { enrichButtonActions } from "./utils/buttonActions.js" import { processStringSync, makePropSafe } from "@budibase/string-templates" @@ -66,6 +69,7 @@ export default { linkable, getAction, fetchDatasourceSchema, + fetchDatasourceDefinition, fetchData, QueryUtils, ContextScopes: Constants.ContextScopes, From fc3fcb5cbdc6c55bc64b744b42c28476925b528b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 29 Oct 2024 11:48:16 +0000 Subject: [PATCH 08/10] Lint --- packages/client/src/components/app/forms/Form.svelte | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/client/src/components/app/forms/Form.svelte b/packages/client/src/components/app/forms/Form.svelte index 2071e85fcc..f470297d78 100644 --- a/packages/client/src/components/app/forms/Form.svelte +++ b/packages/client/src/components/app/forms/Form.svelte @@ -22,8 +22,7 @@ const context = getContext("context") const component = getContext("component") - const { API, fetchDatasourceSchema, detchDatasourceDefinition } = - getContext("sdk") + const { fetchDatasourceSchema, fetchDatasourceDefinition } = getContext("sdk") const getInitialFormStep = () => { const parsedFormStep = parseInt(initialFormStep) From 5cad630b255fb99732e10a76e1b94fa88eee459a Mon Sep 17 00:00:00 2001 From: Budibase Staging Release Bot <> Date: Tue, 29 Oct 2024 11:52:20 +0000 Subject: [PATCH 09/10] Bump version to 2.33.5 --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index 530c51d20b..505f313793 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "2.33.4", + "version": "2.33.5", "npmClient": "yarn", "packages": [ "packages/*", From f94d8ba870acb3a906d0a3fbb1356de4d0673d80 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 29 Oct 2024 12:18:36 +0000 Subject: [PATCH 10/10] Fixing merge artifact --- packages/backend-core/src/security/roles.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/backend-core/src/security/roles.ts b/packages/backend-core/src/security/roles.ts index b7060ebdd7..4076be93a0 100644 --- a/packages/backend-core/src/security/roles.ts +++ b/packages/backend-core/src/security/roles.ts @@ -238,8 +238,8 @@ export function builtinRoleToNumber(id: string) { const builtins = getBuiltinRoles() const MAX = Object.values(builtins).length + 1 if ( - compareRoleIds(id, BUILTIN_IDS.ADMIN) || - compareRoleIds(id, BUILTIN_IDS.BUILDER) + roleIDsAreEqual(id, BUILTIN_IDS.ADMIN) || + roleIDsAreEqual(id, BUILTIN_IDS.BUILDER) ) { return MAX } @@ -278,7 +278,7 @@ export async function roleToNumber(id: string) { const highestBuiltin: number | undefined = role.inherits .map(roleId => { const foundRole = hierarchy.find(role => - compareRoleIds(role._id!, roleId) + roleIDsAreEqual(role._id!, roleId) ) if (foundRole) { return findNumber(foundRole) + 1 @@ -403,7 +403,7 @@ async function getAllUserRoles( ): Promise { const allRoles = await getAllRoles() // admins have access to all roles - if (compareRoleIds(userRoleId, BUILTIN_IDS.ADMIN)) { + if (roleIDsAreEqual(userRoleId, BUILTIN_IDS.ADMIN)) { return allRoles } @@ -515,7 +515,7 @@ export async function getAllRoles(appId?: string): Promise { for (let builtinRoleId of externalBuiltinRoles) { const builtinRole = builtinRoles[builtinRoleId] const dbBuiltin = roles.filter(dbRole => - compareRoleIds(dbRole._id!, builtinRoleId) + roleIDsAreEqual(dbRole._id!, builtinRoleId) )[0] if (dbBuiltin == null) { roles.push(builtinRole || builtinRoles.BASIC) @@ -574,9 +574,9 @@ export class AccessController { if ( tryingRoleId == null || tryingRoleId === "" || - compareRoleIds(tryingRoleId, BUILTIN_IDS.BUILDER) || - compareRoleIds(userRoleId!, tryingRoleId) || - compareRoleIds(userRoleId!, BUILTIN_IDS.BUILDER) + roleIDsAreEqual(tryingRoleId, BUILTIN_IDS.BUILDER) || + roleIDsAreEqual(userRoleId!, tryingRoleId) || + roleIDsAreEqual(userRoleId!, BUILTIN_IDS.BUILDER) ) { return true }