Dedupe and clean up some role logic and constants, and display roles properly in user list

This commit is contained in:
Andrew Kingston 2023-11-23 14:12:10 +00:00
parent b72b93e5b2
commit fd5dd8dd72
5 changed files with 33 additions and 35 deletions

View File

@ -804,8 +804,8 @@
<FancySelect
bind:value={creationRoleType}
options={sdk.users.isAdmin($auth.user)
? Constants.BudibaseRoleOptionsNew
: Constants.BudibaseRoleOptionsNew.filter(
? Constants.BudibaseRoleOptions
: Constants.BudibaseRoleOptions.filter(
option => option.value !== Constants.BudibaseRoles.Admin
)}
label="Role"

View File

@ -98,17 +98,7 @@
return y._id === userId
})
})
$: globalRole = getGlobalRole(user)
const getGlobalRole = user => {
if (sdk.users.isAdmin(user)) {
return Constants.BudibaseRoles.Admin
} else if (sdk.users.isCreator(user)) {
return Constants.BudibaseRoles.Creator
} else {
return Constants.BudibaseRoles.AppUser
}
}
$: globalRole = users.getUserRole(user)
const getAvailableApps = (appList, privileged, roles) => {
let availableApps = appList.slice()
@ -310,6 +300,7 @@
<div class="field">
<Label size="L">Role</Label>
<Select
placeholder={null}
disabled={!sdk.users.isAdmin($auth.user)}
value={globalRole}
options={Constants.BudibaseRoleOptions}

View File

@ -10,11 +10,11 @@
admin: "Full access",
}
$: role = Constants.BudibaseRoleOptionsOld.find(
$: role = Constants.BudibaseRoleOptions.find(
x => x.value === users.getUserRole(row)
)
$: value = role?.label || "Not available"
$: tooltip = TooltipMap[role?.value] || ""
$: tooltip = role.subtitle || ""
</script>
<div on:click|stopPropagation title={tooltip}>

View File

@ -3,6 +3,7 @@ import { API } from "api"
import { update } from "lodash"
import { licensing } from "."
import { sdk } from "@budibase/shared-core"
import { Constants } from "@budibase/frontend-core"
export function createUsersStore() {
const { subscribe, set } = writable({})
@ -120,12 +121,18 @@ export function createUsersStore() {
return await API.removeAppBuilder({ userId, appId })
}
const getUserRole = user =>
sdk.users.isAdmin(user)
? "admin"
: sdk.users.isBuilder(user)
? "developer"
: "appUser"
const getUserRole = user => {
if (sdk.users.isAdmin(user)) {
return Constants.BudibaseRoles.Admin
} else if (sdk.users.isBuilder(user)) {
return Constants.BudibaseRoles.Developer
} else if (sdk.users.isCreator(user)) {
return Constants.BudibaseRoles.Creator
} else {
return Constants.BudibaseRoles.AppUser
}
}
const refreshUsage =
fn =>
async (...args) => {

View File

@ -25,26 +25,26 @@ export const BudibaseRoles = {
}
export const BudibaseRoleOptionsOld = [
{ label: "Developer", value: BudibaseRoles.Developer },
{ label: "Member", value: BudibaseRoles.AppUser },
{ label: "Admin", value: BudibaseRoles.Admin },
{
label: "Developer",
value: BudibaseRoles.Developer,
},
]
export const BudibaseRoleOptions = [
{ label: "App user", value: BudibaseRoles.AppUser },
{ label: "Creator", value: BudibaseRoles.Creator },
{ label: "Account admin", value: BudibaseRoles.Admin },
]
export const BudibaseRoleOptionsNew = [
{
label: "Admin",
value: "admin",
label: "Account admin",
value: BudibaseRoles.Admin,
subtitle: "Has full access to all apps and settings in your account",
},
{
label: "Member",
value: "appUser",
subtitle: "Can only view apps they have access to",
label: "Creator",
value: BudibaseRoles.Creator,
subtitle: "Can create and edit apps they have access to",
},
{
label: "App user",
value: BudibaseRoles.AppUser,
subtitle: "Can only use published apps they have access to",
},
]