Implementing feature #1700 and making it possible to remove logo.

This commit is contained in:
mike12345567 2021-06-21 18:01:25 +01:00
parent ed5dd08c66
commit 61d810edfe
8 changed files with 56 additions and 12 deletions

View File

@ -9,6 +9,7 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { organisation, auth } from "stores/portal" import { organisation, auth } from "stores/portal"
import Logo from "assets/bb-emblem.svg" import Logo from "assets/bb-emblem.svg"
import { onMount } from "svelte"
let email = "" let email = ""
@ -20,6 +21,10 @@
notifications.error("Unable to send reset password link") notifications.error("Unable to send reset password link")
} }
} }
onMount(async () => {
await organisation.init()
})
</script> </script>
<div class="login"> <div class="login">

View File

@ -10,13 +10,16 @@
notifications, notifications,
} from "@budibase/bbui" } from "@budibase/bbui"
import { goto, params } from "@roxi/routify" import { goto, params } from "@roxi/routify"
import { auth } from "stores/portal" import { auth, organisation } from "stores/portal"
import GoogleButton from "./_components/GoogleButton.svelte" import GoogleButton from "./_components/GoogleButton.svelte"
import Logo from "assets/bb-emblem.svg" import Logo from "assets/bb-emblem.svg"
import { onMount } from "svelte"
let username = "" let username = ""
let password = "" let password = ""
$: company = $organisation.company || "Budibase"
async function login() { async function login() {
try { try {
await auth.login({ await auth.login({
@ -43,6 +46,10 @@
function handleKeydown(evt) { function handleKeydown(evt) {
if (evt.key === "Enter") login() if (evt.key === "Enter") login()
} }
onMount(async () => {
await organisation.init()
})
</script> </script>
<svelte:window on:keydown={handleKeydown} /> <svelte:window on:keydown={handleKeydown} />
@ -50,8 +57,8 @@
<div class="main"> <div class="main">
<Layout> <Layout>
<Layout noPadding justifyItems="center"> <Layout noPadding justifyItems="center">
<img alt="logo" src={Logo} /> <img alt="logo" src={$organisation.logoUrl || Logo} />
<Heading>Sign in to Budibase</Heading> <Heading>Sign in to {company}</Heading>
</Layout> </Layout>
<GoogleButton /> <GoogleButton />
<Divider noGrid /> <Divider noGrid />
@ -66,7 +73,7 @@
/> />
</Layout> </Layout>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<Button cta on:click={login}>Sign in to Budibase</Button> <Button cta on:click={login}>Sign in to {company}</Button>
<ActionButton quiet on:click={() => $goto("./forgot")}> <ActionButton quiet on:click={() => $goto("./forgot")}>
Forgot password? Forgot password?
</ActionButton> </ActionButton>

View File

@ -2,8 +2,9 @@
import { Body, Button, Heading, Layout, notifications } from "@budibase/bbui" import { Body, Button, Heading, Layout, notifications } from "@budibase/bbui"
import { goto, params } from "@roxi/routify" import { goto, params } from "@roxi/routify"
import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte" import PasswordRepeatInput from "components/common/users/PasswordRepeatInput.svelte"
import { auth } from "stores/portal" import { auth, organisation } from "stores/portal"
import Logo from "assets/bb-emblem.svg" import Logo from "assets/bb-emblem.svg"
import { onMount } from "svelte"
const resetCode = $params["?code"] const resetCode = $params["?code"]
let password, error let password, error
@ -28,13 +29,17 @@
notifications.error("Unable to reset password") notifications.error("Unable to reset password")
} }
} }
onMount(async () => {
await organisation.init()
})
</script> </script>
<div class="login"> <div class="login">
<div class="main"> <div class="main">
<Layout> <Layout>
<Layout noPadding justifyItems="center"> <Layout noPadding justifyItems="center">
<img src={Logo} alt="Organisation logo" /> <img src={$organisation.logoUrl || Logo} alt="Organisation logo" />
</Layout> </Layout>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<Heading textAlign="center">Reset your password</Heading> <Heading textAlign="center">Reset your password</Heading>

View File

@ -57,11 +57,17 @@
await organisation.init() await organisation.init()
} }
// Update settings const config = {
const res = await organisation.save({
company: $values.company ?? "", company: $values.company ?? "",
platformUrl: $values.platformUrl ?? "", platformUrl: $values.platformUrl ?? "",
}) }
// remove logo if required
if (!$values.logo) {
config.logoUrl = ""
}
// Update settings
const res = await organisation.save(config)
if (res.status === 200) { if (res.status === 200) {
notifications.success("Settings saved successfully") notifications.success("Settings saved successfully")
} else { } else {
@ -98,7 +104,11 @@
<Dropzone <Dropzone
value={[$values.logo]} value={[$values.logo]}
on:change={e => { on:change={e => {
$values.logo = e.detail?.[0] if (!e.detail || e.detail.length === 0) {
$values.logo = null
} else {
$values.logo = e.detail[0]
}
}} }}
/> />
</div> </div>

View File

@ -13,7 +13,7 @@ export function createOrganisationStore() {
const { subscribe, set } = store const { subscribe, set } = store
async function init() { async function init() {
const res = await api.get(`/api/admin/configs/settings`) const res = await api.get(`/api/admin/configs/public`)
const json = await res.json() const json = await res.json()
if (json.status === 400) { if (json.status === 400) {

View File

@ -98,6 +98,18 @@ exports.find = async function (ctx) {
} }
} }
exports.publicSettings = async function (ctx) {
const db = new CouchDB(GLOBAL_DB)
try {
// Find the config with the most granular scope based on context
ctx.body = await getScopedFullConfig(db, {
type: Configs.SETTINGS,
})
} catch (err) {
ctx.throw(err.status, err)
}
}
exports.upload = async function (ctx) { exports.upload = async function (ctx) {
if (ctx.request.files == null || ctx.request.files.file.length > 1) { if (ctx.request.files == null || ctx.request.files.file.length > 1) {
ctx.throw(400, "One file must be uploaded.") ctx.throw(400, "One file must be uploaded.")

View File

@ -37,6 +37,10 @@ const PUBLIC_ENDPOINTS = [
route: "/api/apps", route: "/api/apps",
method: "GET", method: "GET",
}, },
{
route: "/api/admin/configs/public",
method: "GET",
}
] ]
const router = new Router() const router = new Router()

View File

@ -26,7 +26,7 @@ function settingValidation() {
// prettier-ignore // prettier-ignore
return Joi.object({ return Joi.object({
platformUrl: Joi.string().optional(), platformUrl: Joi.string().optional(),
logoUrl: Joi.string().optional(), logoUrl: Joi.string().optional().allow("", null),
docsUrl: Joi.string().optional(), docsUrl: Joi.string().optional(),
company: Joi.string().required(), company: Joi.string().required(),
}).unknown(true) }).unknown(true)
@ -91,6 +91,7 @@ router
buildConfigGetValidation(), buildConfigGetValidation(),
controller.fetch controller.fetch
) )
.get("/api/admin/configs/public", controller.publicSettings)
.get("/api/admin/configs/:type", buildConfigGetValidation(), controller.find) .get("/api/admin/configs/:type", buildConfigGetValidation(), controller.find)
.post( .post(
"/api/admin/configs/upload/:type/:name", "/api/admin/configs/upload/:type/:name",