Merge pull request #5583 from Budibase/feature/bb-logo

BB logo on free plan
This commit is contained in:
Rory Powell 2022-09-15 13:29:37 +01:00 committed by GitHub
commit 89337c9ceb
11 changed files with 109 additions and 10 deletions

View File

@ -1,15 +1,20 @@
<a <script>
import { Link } from "@budibase/bbui"
</script>
<Link
href="https://www.budibase.com/?utm_source=budibase-apps-public-screens&utm_medium=badge&utm_campaign=made-in-budibase" href="https://www.budibase.com/?utm_source=budibase-apps-public-screens&utm_medium=badge&utm_campaign=made-in-budibase"
target="_blank"
> >
<div> <div>
<img src="https://i.imgur.com/Xhdt1YP.png" alt="Budibase" /> <img src="https://i.imgur.com/Xhdt1YP.png" alt="Budibase" />
<p>Made In Budibase</p> <p>Made In Budibase</p>
</div> </div>
</a> </Link>
<style> <style>
div { div {
position: absolute; position: fixed;
right: 20px; right: 20px;
bottom: 20px; bottom: 20px;
padding: 10px; padding: 10px;
@ -27,12 +32,7 @@
p { p {
text-decoration: none; text-decoration: none;
color: var(--spectrum-heading-m-text-color); color: var(--spectrum-global-color-gray-900);
}
a:visited {
text-decoration: none;
color: var(--spectrum-heading-m-text-color);
} }
img { img {

View File

@ -5,9 +5,18 @@
import { FieldTypes } from "constants" import { FieldTypes } from "constants"
import active from "svelte-spa-router/active" import active from "svelte-spa-router/active"
import { RoleUtils } from "@budibase/frontend-core" import { RoleUtils } from "@budibase/frontend-core"
import MadeInBudibase from "../MadeInBudibase.svelte"
import licensing from "../../licensing"
const sdk = getContext("sdk") const sdk = getContext("sdk")
const { routeStore, styleable, linkable, builderStore, currentRole } = sdk const {
routeStore,
styleable,
linkable,
builderStore,
currentRole,
environmentStore,
} = sdk
const component = getContext("component") const component = getContext("component")
const context = getContext("context") const context = getContext("context")
@ -225,6 +234,11 @@
</div> </div>
</div> </div>
{/if} {/if}
{#if !$builderStore.inBuilder && licensing.logoEnabled() && $environmentStore.cloud}
<MadeInBudibase />
{/if}
<div class="main-wrapper"> <div class="main-wrapper">
<div class="main size--{pageWidthClass}"> <div class="main size--{pageWidthClass}">
<slot /> <slot />

View File

@ -0,0 +1,6 @@
export const PlanType = {
FREE: "free",
TEAM: "team",
BUSINESS: "business",
ENTERPRISE: "enterprise",
}

View File

@ -0,0 +1,5 @@
import { isFreePlan } from "./utils.js"
export const logoEnabled = () => {
return isFreePlan()
}

View File

@ -0,0 +1,7 @@
import * as features from "./features"
const licensing = {
...features,
}
export default licensing

View File

@ -0,0 +1,20 @@
import { authStore } from "../stores/auth.js"
import { get } from "svelte/store"
import { PlanType } from "./constants"
const getLicense = () => {
const user = get(authStore)
if (user) {
return user.license
}
}
export const isFreePlan = () => {
const license = getLicense()
if (license) {
return license.plan.type === PlanType.FREE
} else {
// safety net - no license means free plan
return true
}
}

View File

@ -9,6 +9,7 @@ import {
rowSelectionStore, rowSelectionStore,
componentStore, componentStore,
currentRole, currentRole,
environmentStore,
} from "stores" } from "stores"
import { styleable } from "utils/styleable" import { styleable } from "utils/styleable"
import { linkable } from "utils/linkable" import { linkable } from "utils/linkable"
@ -27,6 +28,7 @@ export default {
builderStore, builderStore,
uploadStore, uploadStore,
componentStore, componentStore,
environmentStore,
currentRole, currentRole,
styleable, styleable,
linkable, linkable,

View File

@ -0,0 +1,31 @@
import { API } from "api"
import { writable } from "svelte/store"
const initialState = {
cloud: false,
}
const createEnvironmentStore = () => {
const store = writable(initialState)
const actions = {
fetchEnvironment: async () => {
try {
const environment = await API.getEnvironment()
store.set({
...initialState,
...environment,
})
} catch (error) {
store.set(initialState)
}
},
}
return {
subscribe: store.subscribe,
actions,
}
}
export const environmentStore = createEnvironmentStore()

View File

@ -17,6 +17,7 @@ export { devToolsStore } from "./devTools"
export { componentStore } from "./components" export { componentStore } from "./components"
export { uploadStore } from "./uploads.js" export { uploadStore } from "./uploads.js"
export { rowSelectionStore } from "./rowSelection.js" export { rowSelectionStore } from "./rowSelection.js"
export { environmentStore } from "./environment"
// Context stores are layered and duplicated, so it is not a singleton // Context stores are layered and duplicated, so it is not a singleton
export { createContextStore } from "./context" export { createContextStore } from "./context"

View File

@ -1,7 +1,9 @@
import { routeStore } from "./routes" import { routeStore } from "./routes"
import { appStore } from "./app" import { appStore } from "./app"
import { environmentStore } from "./environment"
export async function initialise() { export async function initialise() {
await routeStore.actions.fetchRoutes() await routeStore.actions.fetchRoutes()
await appStore.actions.fetchAppDefinition() await appStore.actions.fetchAppDefinition()
await environmentStore.actions.fetchEnvironment()
} }

View File

@ -4,6 +4,15 @@ const { getFullUser } = require("../../utilities/users")
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles") const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
const { getAppDB, getAppId } = require("@budibase/backend-core/context") const { getAppDB, getAppId } = require("@budibase/backend-core/context")
/**
* Add the attributes that are session based to the current user.
*/
const addSessionAttributesToUser = ctx => {
if (ctx.user) {
ctx.body.license = ctx.user.license
}
}
exports.fetchSelf = async ctx => { exports.fetchSelf = async ctx => {
let userId = ctx.user.userId || ctx.user._id let userId = ctx.user.userId || ctx.user._id
/* istanbul ignore next */ /* istanbul ignore next */
@ -55,4 +64,6 @@ exports.fetchSelf = async ctx => {
} else { } else {
ctx.body = user ctx.body = user
} }
addSessionAttributesToUser(ctx)
} }