Removing isAdmin and isBuilder flags from the auth store, using SDK only.

This commit is contained in:
mike12345567 2023-08-01 11:30:04 +01:00
parent dce38908c9
commit a8ff2da768
18 changed files with 45 additions and 31 deletions

View File

@ -107,7 +107,7 @@
> >
Update password Update password
</MenuItem> </MenuItem>
{#if $auth.isBuilder} {#if sdk.users.hasBuilderPermissions($auth.user)}
<MenuItem <MenuItem
icon="UserDeveloper" icon="UserDeveloper"
on:click={() => $goto("../portal")} on:click={() => $goto("../portal")}

View File

@ -3,6 +3,7 @@
import { goto } from "@roxi/routify" import { goto } from "@roxi/routify"
import { auth, admin, licensing } from "stores/portal" import { auth, admin, licensing } from "stores/portal"
import { isEnabled, TENANT_FEATURE_FLAGS } from "helpers/featureFlags" import { isEnabled, TENANT_FEATURE_FLAGS } from "helpers/featureFlags"
import { sdk } from "@budibase/shared-core"
</script> </script>
{#if isEnabled(TENANT_FEATURE_FLAGS.LICENSING) && !$licensing.isEnterprisePlan} {#if isEnabled(TENANT_FEATURE_FLAGS.LICENSING) && !$licensing.isEnterprisePlan}
@ -17,7 +18,7 @@
> >
Upgrade Upgrade
</Button> </Button>
{:else if !$admin.cloud && $auth.isAdmin} {:else if !$admin.cloud && sdk.users.isAdmin($auth.user)}
<Button <Button
cta cta
size="S" size="S"

View File

@ -15,7 +15,7 @@
let activeTab = "Apps" let activeTab = "Apps"
$: $url(), updateActiveTab($menu) $: $url(), updateActiveTab($menu)
$: fullscreen = $apps.length == null $: isOnboarding = !$apps.length && sdk.users.isGlobalBuilder($auth.user)
const updateActiveTab = menu => { const updateActiveTab = menu => {
for (let entry of menu) { for (let entry of menu) {
@ -50,7 +50,7 @@
</script> </script>
{#if $auth.user && loaded} {#if $auth.user && loaded}
{#if fullscreen} {#if isOnboarding}
<slot /> <slot />
{:else} {:else}
<HelpMenu /> <HelpMenu />

View File

@ -19,6 +19,7 @@
import DeleteLicenseKeyModal from "../../../../components/portal/licensing/DeleteLicenseKeyModal.svelte" import DeleteLicenseKeyModal from "../../../../components/portal/licensing/DeleteLicenseKeyModal.svelte"
import { API } from "api" import { API } from "api"
import { onMount } from "svelte" import { onMount } from "svelte"
import { sdk } from "@budibase/shared-core"
$: license = $auth.user.license $: license = $auth.user.license
$: upgradeUrl = `${$admin.accountPortalUrl}/portal/upgrade` $: upgradeUrl = `${$admin.accountPortalUrl}/portal/upgrade`
@ -176,7 +177,7 @@
}) })
</script> </script>
{#if $auth.isAdmin} {#if sdk.users.isAdmin($auth.user)}
<DeleteLicenseKeyModal <DeleteLicenseKeyModal
bind:this={deleteLicenseKeyModal} bind:this={deleteLicenseKeyModal}
onConfirm={deleteLicenseKey} onConfirm={deleteLicenseKey}

View File

@ -14,6 +14,7 @@
import { Constants } from "@budibase/frontend-core" import { Constants } from "@budibase/frontend-core"
import { DashCard, Usage } from "components/usage" import { DashCard, Usage } from "components/usage"
import { PlanModel } from "constants" import { PlanModel } from "constants"
import { sdk } from "@budibase/shared-core"
let staticUsage = [] let staticUsage = []
let monthlyUsage = [] let monthlyUsage = []
@ -51,7 +52,8 @@
$: accountPortalAccess = $auth?.user?.accountPortalAccess $: accountPortalAccess = $auth?.user?.accountPortalAccess
$: quotaReset = quotaUsage?.quotaReset $: quotaReset = quotaUsage?.quotaReset
$: canManagePlan = $: canManagePlan =
($admin.cloud && accountPortalAccess) || (!$admin.cloud && $auth.isAdmin) ($admin.cloud && accountPortalAccess) ||
(!$admin.cloud && sdk.users.isAdmin($auth.user))
$: showButton = !usesInvoicing && accountPortalAccess $: showButton = !usesInvoicing && accountPortalAccess

View File

@ -18,6 +18,7 @@
import { API } from "api" import { API } from "api"
import { onMount } from "svelte" import { onMount } from "svelte"
import { goto } from "@roxi/routify" import { goto } from "@roxi/routify"
import { sdk } from "@budibase/shared-core"
const imageExtensions = [ const imageExtensions = [
".png", ".png",
@ -206,7 +207,7 @@
}) })
</script> </script>
{#if $auth.isAdmin && mounted} {#if sdk.users.isAdmin($auth.user) && mounted}
<Layout noPadding> <Layout noPadding>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<div class="title"> <div class="title">
@ -400,7 +401,7 @@
on:click={() => { on:click={() => {
if (isCloud && $auth?.user?.accountPortalAccess) { if (isCloud && $auth?.user?.accountPortalAccess) {
window.open($admin.accountPortalUrl + "/portal/upgrade", "_blank") window.open($admin.accountPortalUrl + "/portal/upgrade", "_blank")
} else if ($auth.isAdmin) { } else if (sdk.users.isAdmin($auth.user)) {
$goto("/builder/portal/account/upgrade") $goto("/builder/portal/account/upgrade")
} }
}} }}

View File

@ -13,6 +13,7 @@
import { redirect } from "@roxi/routify" import { redirect } from "@roxi/routify"
import { API } from "api" import { API } from "api"
import { onMount } from "svelte" import { onMount } from "svelte"
import { sdk } from "@budibase/shared-core"
let diagnosticInfo = "" let diagnosticInfo = ""
@ -46,7 +47,7 @@
}) })
</script> </script>
{#if $auth.isAdmin && diagnosticInfo} {#if sdk.users.isAdmin($auth.user) && diagnosticInfo}
<Layout noPadding> <Layout noPadding>
<Layout gap="XS"> <Layout gap="XS">
<Heading size="M">Diagnostics</Heading> <Heading size="M">Diagnostics</Heading>

View File

@ -13,10 +13,11 @@
import { auth, organisation, admin } from "stores/portal" import { auth, organisation, admin } from "stores/portal"
import { writable } from "svelte/store" import { writable } from "svelte/store"
import { redirect } from "@roxi/routify" import { redirect } from "@roxi/routify"
import { sdk } from "@budibase/shared-core"
// Only admins allowed here // Only admins allowed here
$: { $: {
if (!$auth.isAdmin) { if (!sdk.users.isAdmin($auth.user)) {
$redirect("../../portal") $redirect("../../portal")
} }
} }
@ -50,7 +51,7 @@
} }
</script> </script>
{#if $auth.isAdmin} {#if sdk.users.isAdmin($auth.user)}
<Layout noPadding> <Layout noPadding>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<Heading size="M">Organisation</Heading> <Heading size="M">Organisation</Heading>

View File

@ -14,6 +14,7 @@
import { API } from "api" import { API } from "api"
import { auth, admin } from "stores/portal" import { auth, admin } from "stores/portal"
import { redirect } from "@roxi/routify" import { redirect } from "@roxi/routify"
import { sdk } from "@budibase/shared-core"
let version let version
let loaded = false let loaded = false
@ -25,7 +26,7 @@
// Only admins allowed here // Only admins allowed here
$: { $: {
if (!$auth.isAdmin || $admin.cloud) { if (!sdk.users.isAdmin($auth.user) || $admin.cloud) {
$redirect("../../portal") $redirect("../../portal")
} }
} }
@ -89,7 +90,7 @@
}) })
</script> </script>
{#if $auth.isAdmin} {#if sdk.users.isAdmin($auth.user)}
<Layout noPadding> <Layout noPadding>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<Heading size="M">Version</Heading> <Heading size="M">Version</Heading>

View File

@ -20,6 +20,7 @@
import CreateEditGroupModal from "./_components/CreateEditGroupModal.svelte" import CreateEditGroupModal from "./_components/CreateEditGroupModal.svelte"
import GroupIcon from "./_components/GroupIcon.svelte" import GroupIcon from "./_components/GroupIcon.svelte"
import GroupUsers from "./_components/GroupUsers.svelte" import GroupUsers from "./_components/GroupUsers.svelte"
import { sdk } from "@budibase/shared-core"
export let groupId export let groupId
@ -46,7 +47,7 @@
let editModal, deleteModal let editModal, deleteModal
$: scimEnabled = $features.isScimEnabled $: scimEnabled = $features.isScimEnabled
$: readonly = !$auth.isAdmin || scimEnabled $: readonly = !sdk.users.isAdmin($auth.user) || scimEnabled
$: group = $groups.find(x => x._id === groupId) $: group = $groups.find(x => x._id === groupId)
$: groupApps = $apps $: groupApps = $apps
.filter(app => .filter(app =>

View File

@ -3,6 +3,7 @@
import UserGroupPicker from "components/settings/UserGroupPicker.svelte" import UserGroupPicker from "components/settings/UserGroupPicker.svelte"
import { createPaginationStore } from "helpers/pagination" import { createPaginationStore } from "helpers/pagination"
import { auth, groups, users } from "stores/portal" import { auth, groups, users } from "stores/portal"
import { sdk } from "@budibase/shared-core"
export let groupId export let groupId
export let onUsersUpdated export let onUsersUpdated
@ -13,7 +14,7 @@
let prevSearch = undefined let prevSearch = undefined
let pageInfo = createPaginationStore() let pageInfo = createPaginationStore()
$: readonly = !$auth.isAdmin $: readonly = !sdk.users.isAdmin($auth.user)
$: page = $pageInfo.page $: page = $pageInfo.page
$: searchUsers(page, searchTerm) $: searchUsers(page, searchTerm)
$: group = $groups.find(x => x._id === groupId) $: group = $groups.find(x => x._id === groupId)

View File

@ -9,6 +9,7 @@
import { setContext } from "svelte" import { setContext } from "svelte"
import ScimBanner from "../../_components/SCIMBanner.svelte" import ScimBanner from "../../_components/SCIMBanner.svelte"
import RemoveUserTableRenderer from "../_components/RemoveUserTableRenderer.svelte" import RemoveUserTableRenderer from "../_components/RemoveUserTableRenderer.svelte"
import { sdk } from "@budibase/shared-core"
export let groupId export let groupId
@ -49,7 +50,7 @@
] ]
$: scimEnabled = $features.isScimEnabled $: scimEnabled = $features.isScimEnabled
$: readonly = !$auth.isAdmin || scimEnabled $: readonly = !sdk.users.isAdmin($auth.user) || scimEnabled
const removeUser = async id => { const removeUser = async id => {
await groups.actions.removeUser(groupId, id) await groups.actions.removeUser(groupId, id)

View File

@ -2,6 +2,7 @@
import { ActionButton } from "@budibase/bbui" import { ActionButton } from "@budibase/bbui"
import { getContext } from "svelte" import { getContext } from "svelte"
import { auth } from "stores/portal" import { auth } from "stores/portal"
import { sdk } from "@budibase/shared-core"
export let value export let value
@ -13,6 +14,10 @@
} }
</script> </script>
<ActionButton disabled={!$auth.isAdmin} size="S" on:click={onClick}> <ActionButton
disabled={!sdk.users.isAdmin($auth.user)}
size="S"
on:click={onClick}
>
Remove Remove
</ActionButton> </ActionButton>

View File

@ -22,6 +22,7 @@
import GroupNameTableRenderer from "./_components/GroupNameTableRenderer.svelte" import GroupNameTableRenderer from "./_components/GroupNameTableRenderer.svelte"
import { goto } from "@roxi/routify" import { goto } from "@roxi/routify"
import ScimBanner from "../_components/SCIMBanner.svelte" import ScimBanner from "../_components/SCIMBanner.svelte"
import { sdk } from "@budibase/shared-core"
const DefaultGroup = { const DefaultGroup = {
name: "", name: "",
@ -40,7 +41,7 @@
{ column: "roles", component: GroupAppsTableRenderer }, { column: "roles", component: GroupAppsTableRenderer },
] ]
$: readonly = !$auth.isAdmin $: readonly = !sdk.users.isAdmin($auth.user)
$: schema = { $: schema = {
name: { displayName: "Group", width: "2fr", minWidth: "200px" }, name: { displayName: "Group", width: "2fr", minWidth: "200px" },
users: { sortable: false, width: "1fr" }, users: { sortable: false, width: "1fr" },

View File

@ -88,7 +88,7 @@
$: scimEnabled = $features.isScimEnabled $: scimEnabled = $features.isScimEnabled
$: isSSO = !!user?.provider $: isSSO = !!user?.provider
$: readonly = !$auth.isAdmin || scimEnabled $: readonly = !sdk.users.isAdmin($auth.user) || scimEnabled
$: privileged = sdk.users.isAdminOrBuilder(user) $: privileged = sdk.users.isAdminOrBuilder(user)
$: nameLabel = getNameLabel(user) $: nameLabel = getNameLabel(user)
$: filteredGroups = getFilteredGroups($groups, searchTerm) $: filteredGroups = getFilteredGroups($groups, searchTerm)
@ -286,7 +286,7 @@
<div class="field"> <div class="field">
<Label size="L">Role</Label> <Label size="L">Role</Label>
<Select <Select
disabled={!$auth.isAdmin} disabled={!sdk.users.isAdmin($auth.user)}
value={globalRole} value={globalRole}
options={Constants.BudibaseRoleOptions} options={Constants.BudibaseRoleOptions}
on:change={updateUserRole} on:change={updateUserRole}

View File

@ -2,6 +2,7 @@
import { ActionButton } from "@budibase/bbui" import { ActionButton } from "@budibase/bbui"
import { getContext } from "svelte" import { getContext } from "svelte"
import { auth } from "stores/portal" import { auth } from "stores/portal"
import { sdk } from "@budibase/shared-core"
export let value export let value
@ -13,6 +14,10 @@
} }
</script> </script>
<ActionButton disabled={!$auth.isAdmin} size="S" on:click={onClick}> <ActionButton
disabled={!sdk.users.isAdmin($auth.user)}
size="S"
on:click={onClick}
>
Remove Remove
</ActionButton> </ActionButton>

View File

@ -39,6 +39,7 @@
import { API } from "api" import { API } from "api"
import { OnboardingType } from "../../../../../constants" import { OnboardingType } from "../../../../../constants"
import ScimBanner from "../_components/SCIMBanner.svelte" import ScimBanner from "../_components/SCIMBanner.svelte"
import { sdk } from "@budibase/shared-core"
const fetch = fetchData({ const fetch = fetchData({
API, API,
@ -66,7 +67,7 @@
let userData = [] let userData = []
$: isOwner = $auth.accountPortalAccess && $admin.cloud $: isOwner = $auth.accountPortalAccess && $admin.cloud
$: readonly = !$auth.isAdmin || $features.isScimEnabled $: readonly = !sdk.users.isAdmin($auth.user) || $features.isScimEnabled
$: debouncedUpdateFetch(searchEmail) $: debouncedUpdateFetch(searchEmail)
$: schema = { $: schema = {

View File

@ -14,13 +14,6 @@ export function createAuthStore() {
postLogout: false, postLogout: false,
}) })
const store = derived(auth, $store => { const store = derived(auth, $store => {
let isAdmin = false
let isBuilder = false
if ($store.user) {
const user = $store.user
isAdmin = sdk.users.isAdmin(user)
isBuilder = sdk.users.isBuilder(user)
}
return { return {
user: $store.user, user: $store.user,
accountPortalAccess: $store.accountPortalAccess, accountPortalAccess: $store.accountPortalAccess,
@ -28,8 +21,6 @@ export function createAuthStore() {
tenantSet: $store.tenantSet, tenantSet: $store.tenantSet,
loaded: $store.loaded, loaded: $store.loaded,
postLogout: $store.postLogout, postLogout: $store.postLogout,
isAdmin,
isBuilder,
isSSO: !!$store.user?.provider, isSSO: !!$store.user?.provider,
} }
}) })