split out id parsing into pro repo
This commit is contained in:
parent
3f721400e6
commit
b5ffd995f4
|
@ -50,3 +50,8 @@ exports.getProdAppID = appId => {
|
||||||
const rest = split.join(APP_DEV_PREFIX)
|
const rest = split.join(APP_DEV_PREFIX)
|
||||||
return `${APP_PREFIX}${rest}`
|
return `${APP_PREFIX}${rest}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.extractAppId = id => {
|
||||||
|
const split = id?.split("_") || []
|
||||||
|
return split.length ? split[split.length - 1] : null
|
||||||
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ function isBuiltin(role) {
|
||||||
/**
|
/**
|
||||||
* Works through the inheritance ranks to see how far up the builtin stack this ID is.
|
* Works through the inheritance ranks to see how far up the builtin stack this ID is.
|
||||||
*/
|
*/
|
||||||
function builtinRoleToNumber(id) {
|
exports.builtinRoleToNumber = id => {
|
||||||
const builtins = exports.getBuiltinRoles()
|
const builtins = exports.getBuiltinRoles()
|
||||||
const MAX = Object.values(BUILTIN_IDS).length + 1
|
const MAX = Object.values(BUILTIN_IDS).length + 1
|
||||||
if (id === BUILTIN_IDS.ADMIN || id === BUILTIN_IDS.BUILDER) {
|
if (id === BUILTIN_IDS.ADMIN || id === BUILTIN_IDS.BUILDER) {
|
||||||
|
@ -104,7 +104,8 @@ exports.lowerBuiltinRoleID = (roleId1, roleId2) => {
|
||||||
if (!roleId2) {
|
if (!roleId2) {
|
||||||
return roleId1
|
return roleId1
|
||||||
}
|
}
|
||||||
return builtinRoleToNumber(roleId1) > builtinRoleToNumber(roleId2)
|
return exports.builtinRoleToNumber(roleId1) >
|
||||||
|
exports.builtinRoleToNumber(roleId2)
|
||||||
? roleId2
|
? roleId2
|
||||||
: roleId1
|
: roleId1
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,13 @@
|
||||||
async function removeUser(id) {
|
async function removeUser(id) {
|
||||||
let newUsers = group.users.filter(user => user._id !== id)
|
let newUsers = group.users.filter(user => user._id !== id)
|
||||||
group.users = newUsers
|
group.users = newUsers
|
||||||
|
let user = await users.get(id)
|
||||||
|
|
||||||
|
await users.save({
|
||||||
|
...user,
|
||||||
|
userGroups: [],
|
||||||
|
})
|
||||||
|
|
||||||
await groups.actions.save(group)
|
await groups.actions.save(group)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,15 +46,15 @@
|
||||||
.filter(x => {
|
.filter(x => {
|
||||||
if ($userFetch.data?.roles) {
|
if ($userFetch.data?.roles) {
|
||||||
return Object.keys($userFetch.data.roles).find(y => {
|
return Object.keys($userFetch.data.roles).find(y => {
|
||||||
return x.appId === y
|
return x.appId === apps.extractAppId(y)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(app => {
|
.map(app => {
|
||||||
let roles = Object.fromEntries(
|
let roles = Object.fromEntries(
|
||||||
Object.entries($userFetch.data.roles).filter(
|
Object.entries($userFetch.data.roles).filter(([key]) => {
|
||||||
([key]) => key === app.appId
|
return apps.extractAppId(key) === app.appId
|
||||||
)
|
})
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
name: app.name,
|
name: app.name,
|
||||||
|
@ -90,6 +90,7 @@
|
||||||
Object.keys(roles).forEach(role => {
|
Object.keys(roles).forEach(role => {
|
||||||
let roleNumber = RoleUtils.getRolePriority(roles[role])
|
let roleNumber = RoleUtils.getRolePriority(roles[role])
|
||||||
if (roleNumber > highestRoleNumber) {
|
if (roleNumber > highestRoleNumber) {
|
||||||
|
highestRoleNumber = roleNumber
|
||||||
highestRole = roles[role]
|
highestRole = roles[role]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,8 +12,9 @@ const {
|
||||||
} = require("@budibase/backend-core/tenancy")
|
} = require("@budibase/backend-core/tenancy")
|
||||||
const env = require("../environment")
|
const env = require("../environment")
|
||||||
const { getAppId } = require("@budibase/backend-core/context")
|
const { getAppId } = require("@budibase/backend-core/context")
|
||||||
|
const { groups } = require("@budibase/pro")
|
||||||
|
|
||||||
exports.updateAppRole = (user, { appId } = {}) => {
|
exports.updateAppRole = async (user, { appId } = {}) => {
|
||||||
appId = appId || getAppId()
|
appId = appId || getAppId()
|
||||||
if (!user || !user.roles) {
|
if (!user || !user.roles) {
|
||||||
return user
|
return user
|
||||||
|
@ -32,6 +33,9 @@ exports.updateAppRole = (user, { appId } = {}) => {
|
||||||
user.roleId = BUILTIN_ROLE_IDS.ADMIN
|
user.roleId = BUILTIN_ROLE_IDS.ADMIN
|
||||||
} else if (!user.roleId) {
|
} else if (!user.roleId) {
|
||||||
user.roleId = BUILTIN_ROLE_IDS.PUBLIC
|
user.roleId = BUILTIN_ROLE_IDS.PUBLIC
|
||||||
|
} else if (user?.userGroups?.length) {
|
||||||
|
let roleId = await groups.getGroupRoleId(user, appId)
|
||||||
|
user.roleId = roleId
|
||||||
}
|
}
|
||||||
delete user.roles
|
delete user.roles
|
||||||
return user
|
return user
|
||||||
|
|
Loading…
Reference in New Issue