diff --git a/packages/backend-core/src/security/permissions.ts b/packages/backend-core/src/security/permissions.ts index 929ae92909..263f042a9d 100644 --- a/packages/backend-core/src/security/permissions.ts +++ b/packages/backend-core/src/security/permissions.ts @@ -2,6 +2,8 @@ import { PermissionLevel, PermissionType, BuiltinPermissionID, + Permission, + BuiltinPermissions, } from "@budibase/types" import flatten from "lodash/flatten" import cloneDeep from "lodash/fp/cloneDeep" @@ -12,7 +14,7 @@ export type RoleHierarchy = { permissionId: string }[] -export class Permission { +export class PermissionImpl implements Permission { type: PermissionType level: PermissionLevel @@ -61,68 +63,62 @@ export function getAllowedLevels(userPermLevel: PermissionLevel): string[] { } } -export const BUILTIN_PERMISSIONS: { - [key in keyof typeof BuiltinPermissionID]: { - _id: (typeof BuiltinPermissionID)[key] - name: string - permissions: Permission[] - } -} = { +export const BUILTIN_PERMISSIONS: BuiltinPermissions = { PUBLIC: { _id: BuiltinPermissionID.PUBLIC, name: "Public", permissions: [ - new Permission(PermissionType.WEBHOOK, PermissionLevel.EXECUTE), + new PermissionImpl(PermissionType.WEBHOOK, PermissionLevel.EXECUTE), ], }, READ_ONLY: { _id: BuiltinPermissionID.READ_ONLY, name: "Read only", permissions: [ - new Permission(PermissionType.QUERY, PermissionLevel.READ), - new Permission(PermissionType.TABLE, PermissionLevel.READ), - new Permission(PermissionType.APP, PermissionLevel.READ), + new PermissionImpl(PermissionType.QUERY, PermissionLevel.READ), + new PermissionImpl(PermissionType.TABLE, PermissionLevel.READ), + new PermissionImpl(PermissionType.APP, PermissionLevel.READ), ], }, WRITE: { _id: BuiltinPermissionID.WRITE, name: "Read/Write", permissions: [ - new Permission(PermissionType.QUERY, PermissionLevel.WRITE), - new Permission(PermissionType.TABLE, PermissionLevel.WRITE), - new Permission(PermissionType.AUTOMATION, PermissionLevel.EXECUTE), - new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ), - new Permission(PermissionType.APP, PermissionLevel.READ), + new PermissionImpl(PermissionType.QUERY, PermissionLevel.WRITE), + new PermissionImpl(PermissionType.TABLE, PermissionLevel.WRITE), + new PermissionImpl(PermissionType.AUTOMATION, PermissionLevel.EXECUTE), + new PermissionImpl(PermissionType.LEGACY_VIEW, PermissionLevel.READ), + new PermissionImpl(PermissionType.APP, PermissionLevel.READ), ], }, POWER: { _id: BuiltinPermissionID.POWER, name: "Power", permissions: [ - new Permission(PermissionType.TABLE, PermissionLevel.WRITE), - new Permission(PermissionType.USER, PermissionLevel.READ), - new Permission(PermissionType.AUTOMATION, PermissionLevel.EXECUTE), - new Permission(PermissionType.WEBHOOK, PermissionLevel.READ), - new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ), - new Permission(PermissionType.APP, PermissionLevel.READ), + new PermissionImpl(PermissionType.TABLE, PermissionLevel.WRITE), + new PermissionImpl(PermissionType.USER, PermissionLevel.READ), + new PermissionImpl(PermissionType.AUTOMATION, PermissionLevel.EXECUTE), + new PermissionImpl(PermissionType.WEBHOOK, PermissionLevel.READ), + new PermissionImpl(PermissionType.LEGACY_VIEW, PermissionLevel.READ), + new PermissionImpl(PermissionType.APP, PermissionLevel.READ), ], }, ADMIN: { _id: BuiltinPermissionID.ADMIN, name: "Admin", permissions: [ - new Permission(PermissionType.TABLE, PermissionLevel.ADMIN), - new Permission(PermissionType.USER, PermissionLevel.ADMIN), - new Permission(PermissionType.AUTOMATION, PermissionLevel.ADMIN), - new Permission(PermissionType.WEBHOOK, PermissionLevel.READ), - new Permission(PermissionType.QUERY, PermissionLevel.ADMIN), - new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ), - new Permission(PermissionType.APP, PermissionLevel.READ), + new PermissionImpl(PermissionType.TABLE, PermissionLevel.ADMIN), + new PermissionImpl(PermissionType.USER, PermissionLevel.ADMIN), + new PermissionImpl(PermissionType.AUTOMATION, PermissionLevel.ADMIN), + new PermissionImpl(PermissionType.WEBHOOK, PermissionLevel.READ), + new PermissionImpl(PermissionType.QUERY, PermissionLevel.ADMIN), + new PermissionImpl(PermissionType.LEGACY_VIEW, PermissionLevel.READ), + new PermissionImpl(PermissionType.APP, PermissionLevel.READ), ], }, } -export function getBuiltinPermissions() { +export function getBuiltinPermissions(): BuiltinPermissions { return cloneDeep(BUILTIN_PERMISSIONS) } diff --git a/packages/backend-core/src/security/tests/permissions.spec.ts b/packages/backend-core/src/security/tests/permissions.spec.ts index f98833c7cd..d268a56a1f 100644 --- a/packages/backend-core/src/security/tests/permissions.spec.ts +++ b/packages/backend-core/src/security/tests/permissions.spec.ts @@ -133,7 +133,7 @@ describe("getBuiltinPermissionByID", () => { _id: BuiltinPermissionID.PUBLIC, name: "Public", permissions: [ - new permissions.Permission( + new permissions.PermissionImpl( permissions.PermissionType.WEBHOOK, permissions.PermissionLevel.EXECUTE ), diff --git a/packages/builder/src/components/design/settings/controls/DataSourceSelect/DataSourceSelect.svelte b/packages/builder/src/components/design/settings/controls/DataSourceSelect/DataSourceSelect.svelte index 410af53648..9eef8c1c06 100644 --- a/packages/builder/src/components/design/settings/controls/DataSourceSelect/DataSourceSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/DataSourceSelect/DataSourceSelect.svelte @@ -52,9 +52,16 @@ let modal $: text = value?.label ?? "Choose an option" - $: tables = $tablesStore.list.map(table => - format.table(table, $datasources.list) - ) + $: tables = $tablesStore.list + .map(table => format.table(table, $datasources.list)) + .sort((a, b) => { + // sort tables alphabetically, grouped by datasource + const dsComparison = a.datasourceName.localeCompare(b.datasourceName) + if (dsComparison !== 0) { + return dsComparison + } + return a.label.localeCompare(b.label) + }) $: viewsV1 = $viewsStore.list.map(view => ({ ...view, label: view.name, diff --git a/packages/builder/src/pages/builder/app/[application]/automation/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/automation/_layout.svelte index acc1b8e2d9..c5c28d1e1e 100644 --- a/packages/builder/src/pages/builder/app/[application]/automation/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/automation/_layout.svelte @@ -1,5 +1,5 @@