Add licensing and env logic to determine which account links to show

This commit is contained in:
Andrew Kingston 2023-01-09 12:25:22 +00:00
parent 99ba588478
commit 4e7daa66ed
3 changed files with 43 additions and 77 deletions

View File

@ -18,7 +18,7 @@
import ThemeModal from "components/settings/ThemeModal.svelte" import ThemeModal from "components/settings/ThemeModal.svelte"
import APIKeyModal from "components/settings/APIKeyModal.svelte" import APIKeyModal from "components/settings/APIKeyModal.svelte"
import Logo from "assets/bb-emblem.svg" import Logo from "assets/bb-emblem.svg"
// import { isEnabled, TENANT_FEATURE_FLAGS } from "helpers/featureFlags" import { isEnabled, TENANT_FEATURE_FLAGS } from "helpers/featureFlags"
let loaded = false let loaded = false
let themeModal let themeModal
@ -43,6 +43,7 @@
} }
const buildMenu = admin => { const buildMenu = admin => {
// Standard user and developer pages
let menu = [ let menu = [
{ {
title: "Apps", title: "Apps",
@ -54,6 +55,7 @@
}, },
] ]
// Admin only pages
if (admin) { if (admin) {
menu = [ menu = [
{ {
@ -72,76 +74,20 @@
title: "Settings", title: "Settings",
href: "/builder/portal/settings", href: "/builder/portal/settings",
}, },
{
title: "Account",
href: "/builder/portal/account",
},
] ]
// if (!$adminStore.cloud) {
// menu = menu.concat([
// {
// title: "Update",
// href: "/builder/portal/settings/update",
// },
// ])
// }
} }
// add link to account portal if the user has access // Check if allowed access to account section
// let accountSectionAdded = false if (
isEnabled(TENANT_FEATURE_FLAGS.LICENSING) &&
($auth?.user?.accountPortalAccess || (!$adminStore.cloud && admin))
) {
menu.push({
title: "Account",
href: "/builder/portal/account",
})
}
// link out to account-portal if account holder in cloud or always in self-host
// if ($auth?.user?.accountPortalAccess || (!$adminStore.cloud && admin)) {
// accountSectionAdded = true
// menu = menu.concat([
// {
// title: "Account",
// href: $adminStore.accountPortalUrl,
// heading: "Account",
// },
// ])
// }
//
// if (isEnabled(TENANT_FEATURE_FLAGS.LICENSING)) {
// // always show usage in self-host or cloud if licensing enabled
// menu = menu.concat([
// {
// title: "Usage",
// href: "/builder/portal/settings/usage",
// heading: accountSectionAdded ? "" : "Account",
// },
// ])
//
// // show the relevant hosting upgrade page
// if ($adminStore.cloud && $auth?.user?.accountPortalAccess) {
// menu = menu.concat([
// {
// title: "Upgrade",
// href: $adminStore.accountPortalUrl + "/portal/upgrade",
// },
// ])
// } else if (!$adminStore.cloud && admin) {
// menu = menu.concat({
// title: "Upgrade",
// href: "/builder/portal/settings/upgrade",
// })
// }
//
// // show the billing page to licensed account holders in cloud
// if (
// $auth?.user?.accountPortalAccess &&
// $auth.user.account.stripeCustomerId
// ) {
// menu = menu.concat([
// {
// title: "Billing",
// href: $adminStore.accountPortalUrl + "/portal/billing",
// },
// ])
// }
// }
menu = menu.filter(item => !!item)
return menu return menu
} }

View File

@ -2,22 +2,39 @@
import { url, isActive } from "@roxi/routify" import { url, isActive } from "@roxi/routify"
import { Page } from "@budibase/bbui" import { Page } from "@budibase/bbui"
import { Content, SideNav, SideNavItem } from "components/portal/page" import { Content, SideNav, SideNavItem } from "components/portal/page"
import { admin, auth } from "stores/portal"
</script> </script>
<Page narrow> <Page narrow>
<Content> <Content>
<div slot="side-nav"> <div slot="side-nav">
<SideNav> <SideNav>
<!-- Always show usage in self-host or cloud if licensing enabled-->
<SideNavItem <SideNavItem
text="Usage" text="Usage"
url={$url("./usage")} url={$url("./usage")}
active={$isActive("./usage")} active={$isActive("./usage")}
/> />
<SideNavItem <!-- Show the relevant hosting upgrade page-->
text="Upgrade" {#if $admin.cloud && $auth?.user?.accountPortalAccess}
url={$url("./upgrade")} <SideNavItem
active={$isActive("./upgrade")} text="Upgrade"
/> url={$admin.accountPortalUrl + "/portal/upgrade"}
/>
{:else if !$admin.cloud && admin}
<SideNavItem
text="Upgrade"
url={$url("./upgrade")}
active={$isActive("./upgrade")}
/>
{/if}
<!-- Show the billing page to licensed account holders in cloud -->
{#if $auth?.user?.accountPortalAccess && $auth.user.account.stripeCustomerId}
<SideNavItem
text="Billing"
url={$admin.accountPortalUrl + "/portal/billing"}
/>
{/if}
</SideNav> </SideNav>
</div> </div>
<slot /> <slot />

View File

@ -2,6 +2,7 @@
import { url, isActive } from "@roxi/routify" import { url, isActive } from "@roxi/routify"
import { Page } from "@budibase/bbui" import { Page } from "@budibase/bbui"
import { Content, SideNav, SideNavItem } from "components/portal/page" import { Content, SideNav, SideNavItem } from "components/portal/page"
import { admin } from "stores/portal"
$: wide = $isActive("./email/:template") $: wide = $isActive("./email/:template")
</script> </script>
@ -25,11 +26,13 @@
url={$url("./organisation")} url={$url("./organisation")}
active={$isActive("./organisation")} active={$isActive("./organisation")}
/> />
<SideNavItem {#if !$admin.cloud}
text="Version" <SideNavItem
url={$url("./version")} text="Version"
active={$isActive("./version")} url={$url("./version")}
/> active={$isActive("./version")}
/>
{/if}
</SideNav> </SideNav>
</div> </div>
<slot /> <slot />