PR comments.
This commit is contained in:
parent
7e79c827a7
commit
4d2aa2a67b
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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<DBDumpOpts> {
|
||||
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({
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,5 +4,5 @@ export interface Role extends Document {
|
|||
permissionId: string
|
||||
inherits?: string
|
||||
permissions: { [key: string]: string[] }
|
||||
version?: number
|
||||
version?: string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue