Dedupe and clean up some role logic and constants, and display roles properly in user list
This commit is contained in:
parent
b72b93e5b2
commit
fd5dd8dd72
|
@ -804,8 +804,8 @@
|
||||||
<FancySelect
|
<FancySelect
|
||||||
bind:value={creationRoleType}
|
bind:value={creationRoleType}
|
||||||
options={sdk.users.isAdmin($auth.user)
|
options={sdk.users.isAdmin($auth.user)
|
||||||
? Constants.BudibaseRoleOptionsNew
|
? Constants.BudibaseRoleOptions
|
||||||
: Constants.BudibaseRoleOptionsNew.filter(
|
: Constants.BudibaseRoleOptions.filter(
|
||||||
option => option.value !== Constants.BudibaseRoles.Admin
|
option => option.value !== Constants.BudibaseRoles.Admin
|
||||||
)}
|
)}
|
||||||
label="Role"
|
label="Role"
|
||||||
|
|
|
@ -98,17 +98,7 @@
|
||||||
return y._id === userId
|
return y._id === userId
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
$: globalRole = getGlobalRole(user)
|
$: globalRole = users.getUserRole(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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const getAvailableApps = (appList, privileged, roles) => {
|
const getAvailableApps = (appList, privileged, roles) => {
|
||||||
let availableApps = appList.slice()
|
let availableApps = appList.slice()
|
||||||
|
@ -310,6 +300,7 @@
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<Label size="L">Role</Label>
|
<Label size="L">Role</Label>
|
||||||
<Select
|
<Select
|
||||||
|
placeholder={null}
|
||||||
disabled={!sdk.users.isAdmin($auth.user)}
|
disabled={!sdk.users.isAdmin($auth.user)}
|
||||||
value={globalRole}
|
value={globalRole}
|
||||||
options={Constants.BudibaseRoleOptions}
|
options={Constants.BudibaseRoleOptions}
|
||||||
|
|
|
@ -10,11 +10,11 @@
|
||||||
admin: "Full access",
|
admin: "Full access",
|
||||||
}
|
}
|
||||||
|
|
||||||
$: role = Constants.BudibaseRoleOptionsOld.find(
|
$: role = Constants.BudibaseRoleOptions.find(
|
||||||
x => x.value === users.getUserRole(row)
|
x => x.value === users.getUserRole(row)
|
||||||
)
|
)
|
||||||
$: value = role?.label || "Not available"
|
$: value = role?.label || "Not available"
|
||||||
$: tooltip = TooltipMap[role?.value] || ""
|
$: tooltip = role.subtitle || ""
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div on:click|stopPropagation title={tooltip}>
|
<div on:click|stopPropagation title={tooltip}>
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { API } from "api"
|
||||||
import { update } from "lodash"
|
import { update } from "lodash"
|
||||||
import { licensing } from "."
|
import { licensing } from "."
|
||||||
import { sdk } from "@budibase/shared-core"
|
import { sdk } from "@budibase/shared-core"
|
||||||
|
import { Constants } from "@budibase/frontend-core"
|
||||||
|
|
||||||
export function createUsersStore() {
|
export function createUsersStore() {
|
||||||
const { subscribe, set } = writable({})
|
const { subscribe, set } = writable({})
|
||||||
|
@ -120,12 +121,18 @@ export function createUsersStore() {
|
||||||
return await API.removeAppBuilder({ userId, appId })
|
return await API.removeAppBuilder({ userId, appId })
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUserRole = user =>
|
const getUserRole = user => {
|
||||||
sdk.users.isAdmin(user)
|
if (sdk.users.isAdmin(user)) {
|
||||||
? "admin"
|
return Constants.BudibaseRoles.Admin
|
||||||
: sdk.users.isBuilder(user)
|
} else if (sdk.users.isBuilder(user)) {
|
||||||
? "developer"
|
return Constants.BudibaseRoles.Developer
|
||||||
: "appUser"
|
} else if (sdk.users.isCreator(user)) {
|
||||||
|
return Constants.BudibaseRoles.Creator
|
||||||
|
} else {
|
||||||
|
return Constants.BudibaseRoles.AppUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const refreshUsage =
|
const refreshUsage =
|
||||||
fn =>
|
fn =>
|
||||||
async (...args) => {
|
async (...args) => {
|
||||||
|
|
|
@ -25,26 +25,26 @@ export const BudibaseRoles = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BudibaseRoleOptionsOld = [
|
export const BudibaseRoleOptionsOld = [
|
||||||
{ label: "Developer", value: BudibaseRoles.Developer },
|
{
|
||||||
{ label: "Member", value: BudibaseRoles.AppUser },
|
label: "Developer",
|
||||||
{ label: "Admin", value: BudibaseRoles.Admin },
|
value: BudibaseRoles.Developer,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
export const BudibaseRoleOptions = [
|
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",
|
label: "Account admin",
|
||||||
value: "admin",
|
value: BudibaseRoles.Admin,
|
||||||
subtitle: "Has full access to all apps and settings in your account",
|
subtitle: "Has full access to all apps and settings in your account",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Member",
|
label: "Creator",
|
||||||
value: "appUser",
|
value: BudibaseRoles.Creator,
|
||||||
subtitle: "Can only view apps they have access to",
|
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",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue