Linting and Optimisation

This commit is contained in:
Peter Clement 2021-07-09 15:05:39 +01:00
parent 4ae29f6b54
commit 90e6db2be1
6 changed files with 34 additions and 35 deletions

View File

@ -15,18 +15,21 @@
Oidc: OidcLogo, Oidc: OidcLogo,
Oracle: OracleLogo, Oracle: OracleLogo,
Auth0: Auth0Logo, Auth0: Auth0Logo,
AD: MicrosoftLogo AD: MicrosoftLogo,
} }
$: show = $admin.checklist?.oidc $: show = $admin.checklist?.oidc
</script> </script>
{#if show} {#if show}
<ActionButton <ActionButton on:click={() => window.open("/api/admin/auth/oidc", "_blank")}>
on:click={() => window.open("/api/admin/auth/oidc", "_blank")}
>
<div class="inner"> <div class="inner">
<img src={preDefinedIcons[oidcIcon] ? preDefinedIcons[oidcIcon] : `/global/oidc_logos/${oidcIcon}` || OidcLogo} alt="oidc icon" /> <img
<p>{`Sign in with ${oidcName || 'OIDC'}`}</p> src={preDefinedIcons[oidcIcon]
? preDefinedIcons[oidcIcon]
: `/global/oidc_logos/${oidcIcon}` || OidcLogo}
alt="oidc icon"
/>
<p>{`Sign in with ${oidcName || "OIDC"}`}</p>
</div> </div>
</ActionButton> </ActionButton>
{/if} {/if}
@ -48,4 +51,3 @@
margin: 0; margin: 0;
} }
</style> </style>

View File

@ -62,7 +62,10 @@
<Heading>Sign in to {company}</Heading> <Heading>Sign in to {company}</Heading>
</Layout> </Layout>
<GoogleButton /> <GoogleButton />
<OIDCButton oidcIcon={$organisation.oidcIcon} oidcName={$organisation.oidcName}/> <OIDCButton
oidcIcon={$organisation.oidcIcon}
oidcName={$organisation.oidcName}
/>
<Divider noGrid /> <Divider noGrid />
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<Body size="S" textAlign="center">Sign in with email</Body> <Body size="S" textAlign="center">Sign in with email</Body>

View File

@ -19,6 +19,13 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { onMount } from "svelte" import { onMount } from "svelte"
import api from "builderStore/api" import api from "builderStore/api"
import { writable } from "svelte/store"
import { organisation } from "stores/portal"
const values = writable({
oidcIcon: $organisation.oidcIcon,
oidcName: $organisation.oidcName,
})
const ConfigTypes = { const ConfigTypes = {
Google: "google", Google: "google",
@ -39,12 +46,12 @@
} }
const OIDCConfigFields = { const OIDCConfigFields = {
Oidc: ["configUrl", "clientID", "clientSecret"], Oidc: ["configUrl", "clientId", "clientSecret"],
} }
const OIDCConfigLabels = { const OIDCConfigLabels = {
Oidc: { Oidc: {
configUrl: "Config URL", configUrl: "Config URL",
clientID: "Client ID", clientId: "Client ID",
clientSecret: "Client Secret", clientSecret: "Client Secret",
}, },
} }
@ -81,8 +88,9 @@
const onFileSelected = e => { const onFileSelected = e => {
let fileName = e.target.files[0].name let fileName = e.target.files[0].name
image = e.target.files[0] image = e.target.files[0]
providers.oidc.config["iconName"] = fileName $values.oidcIcon = fileName
iconDropdownOptions.unshift({ label: fileName, value: fileName }) iconDropdownOptions.unshift({ label: fileName, value: fileName })
image && uploadLogo(image)
} }
const providers = { google, oidc } const providers = { google, oidc }
@ -90,6 +98,7 @@
async function save(docs) { async function save(docs) {
// only if the user has provided an image, upload it. // only if the user has provided an image, upload it.
image && uploadLogo(image) image && uploadLogo(image)
await organisation.save($values)
let calls = [] let calls = []
docs.forEach(element => { docs.forEach(element => {
calls.push(api.post(`/api/admin/configs`, element)) calls.push(api.post(`/api/admin/configs`, element))
@ -116,6 +125,7 @@
} }
onMount(async () => { onMount(async () => {
await organisation.init()
// fetch the configs for oauth // fetch the configs for oauth
const googleResponse = await api.get( const googleResponse = await api.get(
`/api/admin/configs/${ConfigTypes.Google}` `/api/admin/configs/${ConfigTypes.Google}`
@ -220,13 +230,13 @@
</Body> </Body>
<div class="form-row"> <div class="form-row">
<Label size="L">Name</Label> <Label size="L">Name</Label>
<Input bind:value={providers.oidc.config["name"]} /> <Input bind:value={$values.oidcName} />
</div> </div>
<div class="form-row"> <div class="form-row">
<Label size="L">Icon</Label> <Label size="L">Icon</Label>
<Select <Select
label="" label=""
bind:value={providers.oidc.config["iconName"]} bind:value={$values.oidcIcon}
options={iconDropdownOptions} options={iconDropdownOptions}
on:change={e => e.detail === "Upload" && fileinput.click()} on:change={e => e.detail === "Upload" && fileinput.click()}
/> />

View File

@ -6,6 +6,8 @@ const DEFAULT_CONFIG = {
logoUrl: undefined, logoUrl: undefined,
docsUrl: undefined, docsUrl: undefined,
company: "Budibase", company: "Budibase",
oidcIcon: undefined,
oidcName: undefined,
} }
export function createOrganisationStore() { export function createOrganisationStore() {

View File

@ -106,29 +106,11 @@ exports.publicSettings = async function (ctx) {
type: Configs.SETTINGS, type: Configs.SETTINGS,
}) })
// Pull out the OIDC icon and name because the other properties shouldn't if (!publicConfig) {
// be made public ctx.body = {}
const oidcConfig = await getScopedFullConfig(db, { } else {
type: Configs.OIDC,
})
if (publicConfig && !oidcConfig) {
ctx.body = publicConfig ctx.body = publicConfig
} }
else if(!publicConfig && oidcConfig) {
// Pull out the OIDC icon and name because the other properties shouldn't
// be made public
let config = {}
config.oidcIcon = oidcConfig.config.iconName
config.oidcName = oidcConfig.config.name
oidcConfig.config = config
ctx.body = oidcConfig
}
else if (publicConfig && oidcConfig) {
ctx.body = publicConfig
publicConfig.config.oidcIcon = oidcConfig.config.iconName
publicConfig.config.oidcName = oidcConfig.config.name
}
} catch (err) { } catch (err) {
ctx.throw(err.status, err) ctx.throw(err.status, err)
} }

View File

@ -66,7 +66,7 @@ function buildConfigSaveValidation() {
{ is: Configs.SETTINGS, then: settingValidation() }, { is: Configs.SETTINGS, then: settingValidation() },
{ is: Configs.ACCOUNT, then: Joi.object().unknown(true) }, { is: Configs.ACCOUNT, then: Joi.object().unknown(true) },
{ is: Configs.GOOGLE, then: googleValidation() }, { is: Configs.GOOGLE, then: googleValidation() },
{ is: Configs.OIDC, then: Joi.object().unknown(true) } { is: Configs.OIDC, then: oidcValidation() }
], ],
}), }),
}).required(), }).required(),