Further PR comments.
This commit is contained in:
parent
4d2aa2a67b
commit
fc537a0aab
|
@ -89,6 +89,13 @@ export function generateRoleID(name: string) {
|
||||||
return `${prefix}${name}`
|
return `${prefix}${name}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to be more verbose.
|
||||||
|
*/
|
||||||
|
export function prefixRoleID(name: string) {
|
||||||
|
return generateRoleID(name)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a new dev info document ID - this is scoped to a user.
|
* Generates a new dev info document ID - this is scoped to a user.
|
||||||
* @returns {string} The new dev info ID which info for dev (like api key) can be stored under.
|
* @returns {string} The new dev info ID which info for dev (like api key) can be stored under.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { BuiltinPermissionID, PermissionLevel } from "./permissions"
|
import { BuiltinPermissionID, PermissionLevel } from "./permissions"
|
||||||
import { generateRoleID, getRoleParams, DocumentType, SEPARATOR } from "../db"
|
import { prefixRoleID, getRoleParams, DocumentType, SEPARATOR } from "../db"
|
||||||
import { getAppDB } from "../context"
|
import { getAppDB } from "../context"
|
||||||
import { doWithDB } from "../db"
|
import { doWithDB } from "../db"
|
||||||
import { Screen, Role as RoleDoc } from "@budibase/types"
|
import { Screen, Role as RoleDoc } from "@budibase/types"
|
||||||
|
@ -169,7 +169,7 @@ export async function getRole(
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// make sure has the prefix (if it has it then it won't be added)
|
// make sure has the prefix (if it has it then it won't be added)
|
||||||
roleId = generateRoleID(roleId)
|
roleId = prefixRoleID(roleId)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const db = getAppDB()
|
const db = getAppDB()
|
||||||
|
@ -402,7 +402,7 @@ export function getDBRoleID(roleName: string) {
|
||||||
if (roleName?.startsWith(DocumentType.ROLE)) {
|
if (roleName?.startsWith(DocumentType.ROLE)) {
|
||||||
return roleName
|
return roleName
|
||||||
}
|
}
|
||||||
return generateRoleID(roleName)
|
return prefixRoleID(roleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -109,8 +109,6 @@
|
||||||
return "Select a unique role name."
|
return "Select a unique role name."
|
||||||
} else if (invalidRoleName) {
|
} else if (invalidRoleName) {
|
||||||
return "Please enter a role name consisting of only alphanumeric symbols and underscores"
|
return "Please enter a role name consisting of only alphanumeric symbols and underscores"
|
||||||
} else {
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ async function updateRolesOnUserTable(
|
||||||
roleVersion === roles.RoleIDVersion.NAME
|
roleVersion === roles.RoleIDVersion.NAME
|
||||||
? roles.getExternalRoleID(roleId, roleVersion)
|
? roles.getExternalRoleID(roleId, roleVersion)
|
||||||
: roleId
|
: roleId
|
||||||
const indexOf = constraints.inclusion.indexOf(updatedRoleId)
|
const indexOfRoleId = constraints.inclusion.indexOf(updatedRoleId)
|
||||||
if (remove && indexOf !== -1) {
|
if (remove && indexOfRoleId !== -1) {
|
||||||
constraints.inclusion.splice(indexOf, 1)
|
constraints.inclusion.splice(indexOfRoleId, 1)
|
||||||
} else if (!remove && indexOf === -1) {
|
} else if (!remove && indexOfRoleId === -1) {
|
||||||
constraints.inclusion.push(updatedRoleId)
|
constraints.inclusion.push(updatedRoleId)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue