diff --git a/packages/backend-core/src/security/roles.ts b/packages/backend-core/src/security/roles.ts index 0c05e54c77..b43017afb0 100644 --- a/packages/backend-core/src/security/roles.ts +++ b/packages/backend-core/src/security/roles.ts @@ -25,11 +25,11 @@ const EXTERNAL_BUILTIN_ROLE_IDS = [ BUILTIN_IDS.PUBLIC, ] -export const RoleVersion = { +export const RoleIDVersion = { // original version, with a UUID based ID - VERSION_1: undefined, + UUID: undefined, // new version - with name based ID - VERSION_2: 2, + NAME: "name", } export class Role implements RoleDoc { @@ -38,7 +38,7 @@ export class Role implements RoleDoc { name: string permissionId: string inherits?: string - version?: number + version?: string permissions = {} constructor(id: string, name: string, permissionId: string) { @@ -46,7 +46,7 @@ export class Role implements RoleDoc { this.name = name this.permissionId = permissionId // version for managing the ID - removing the role_ when responding - this.version = RoleVersion.VERSION_2 + this.version = RoleIDVersion.NAME } addInheritance(inherits: string) { @@ -408,11 +408,11 @@ export function getDBRoleID(roleName: string) { /** * Remove the "role_" from builtin role IDs that have been written to the DB (for permissions). */ -export function getExternalRoleID(roleId: string, version?: number) { +export function getExternalRoleID(roleId: string, version?: string) { // for built-in roles we want to remove the DB role ID element (role_) if ( (roleId.startsWith(DocumentType.ROLE) && isBuiltin(roleId)) || - version === RoleVersion.VERSION_2 + version === RoleIDVersion.NAME ) { return roleId.split(`${DocumentType.ROLE}${SEPARATOR}`)[1] } diff --git a/packages/server/src/api/controllers/role.ts b/packages/server/src/api/controllers/role.ts index ff8dd3609c..f772405846 100644 --- a/packages/server/src/api/controllers/role.ts +++ b/packages/server/src/api/controllers/role.ts @@ -15,7 +15,7 @@ async function updateRolesOnUserTable( db: Database, roleId: string, updateOption: string, - roleVersion?: number + roleVersion: string | undefined ) { const table = await db.get(InternalTables.USER_METADATA) const schema = table.schema @@ -26,7 +26,7 @@ async function updateRolesOnUserTable( updated = true const constraints = schema[prop].constraints const updatedRoleId = - roleVersion === roles.RoleVersion.VERSION_2 + roleVersion === roles.RoleIDVersion.NAME ? roles.getExternalRoleID(roleId, roleVersion) : roleId const indexOf = constraints.inclusion.indexOf(updatedRoleId) @@ -66,7 +66,7 @@ export async function save(ctx: UserCtx) { isCreate = true } // version 2 roles need updated to add back role_ - else if (version === roles.RoleVersion.VERSION_2) { + else if (version === roles.RoleIDVersion.NAME) { _id = generateRoleID(name) } diff --git a/packages/server/src/sdk/app/backups/exports.ts b/packages/server/src/sdk/app/backups/exports.ts index 3be8c64159..306918cf80 100644 --- a/packages/server/src/sdk/app/backups/exports.ts +++ b/packages/server/src/sdk/app/backups/exports.ts @@ -22,12 +22,12 @@ import tar from "tar" const MemoryStream = require("memorystream") -interface DBDumpOpts { +export interface DBDumpOpts { filter?: any exportPath?: string } -interface ExportOpts extends DBDumpOpts { +export interface ExportOpts extends DBDumpOpts { tar?: boolean excludeRows?: boolean excludeLogs?: boolean @@ -57,7 +57,10 @@ function tarFilesToTmp(tmpDir: string, files: string[]) { * a filter function or the name of the export. * @return {*} either a readable stream or a string */ -export async function exportDB(dbName: string, opts: DBDumpOpts = {}) { +export async function exportDB( + dbName: string, + opts: DBDumpOpts = {} +): Promise { const exportOpts = { filter: opts?.filter, batch_size: 1000, @@ -178,6 +181,7 @@ export async function exportApp(appId: string, config?: ExportOpts) { * Streams a backup of the database state for an app * @param {string} appId The ID of the app which is to be backed up. * @param {boolean} excludeRows Flag to state whether the export should include data. + * @param {string} encryptPassword password for encrypting the export. * @returns {*} a readable stream of the backup which is written in real time */ export async function streamExportApp({ diff --git a/packages/server/src/tests/utilities/structures.ts b/packages/server/src/tests/utilities/structures.ts index fc8a2b3e98..24eb1522a7 100644 --- a/packages/server/src/tests/utilities/structures.ts +++ b/packages/server/src/tests/utilities/structures.ts @@ -266,7 +266,7 @@ export function basicRole() { name: `NewRole_${utils.newid()}`, inherits: roles.BUILTIN_ROLE_IDS.BASIC, permissionId: permissions.BuiltinPermissionID.READ_ONLY, - version: 2, + version: "name", } } diff --git a/packages/types/src/documents/app/role.ts b/packages/types/src/documents/app/role.ts index 2167041b90..d126a67b16 100644 --- a/packages/types/src/documents/app/role.ts +++ b/packages/types/src/documents/app/role.ts @@ -4,5 +4,5 @@ export interface Role extends Document { permissionId: string inherits?: string permissions: { [key: string]: string[] } - version?: number + version?: string }