Merge pull request #11656 from Budibase/BUDI-7393/clean_code
Clean code
This commit is contained in:
commit
37e1443bf8
|
@ -312,37 +312,6 @@ export async function getAllRoles(appId?: string): Promise<RoleDoc[]> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This retrieves the required role for a resource
|
|
||||||
* @param permLevel The level of request
|
|
||||||
* @param resourceId The resource being requested
|
|
||||||
* @param subResourceId The sub resource being requested
|
|
||||||
* @return {Promise<{permissions}|Object>} returns the permissions required to access.
|
|
||||||
*/
|
|
||||||
export async function getRequiredResourceRole(
|
|
||||||
permLevel: string,
|
|
||||||
{ resourceId, subResourceId }: { resourceId?: string; subResourceId?: string }
|
|
||||||
) {
|
|
||||||
const roles = await getAllRoles()
|
|
||||||
let main = [],
|
|
||||||
sub = []
|
|
||||||
for (let role of roles) {
|
|
||||||
// no permissions, ignore it
|
|
||||||
if (!role.permissions) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
const mainRes = resourceId ? role.permissions[resourceId] : undefined
|
|
||||||
const subRes = subResourceId ? role.permissions[subResourceId] : undefined
|
|
||||||
if (mainRes && mainRes.indexOf(permLevel) !== -1) {
|
|
||||||
main.push(role._id)
|
|
||||||
} else if (subRes && subRes.indexOf(permLevel) !== -1) {
|
|
||||||
sub.push(role._id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// for now just return the IDs
|
|
||||||
return main.concat(sub)
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AccessController {
|
export class AccessController {
|
||||||
userHierarchies: { [key: string]: string[] }
|
userHierarchies: { [key: string]: string[] }
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
Loading…
Reference in New Issue