Browse Source

Linting and Optimisation

gh-pages
Peter Clement 5 years ago
parent
commit
90e6db2be1
  1. 16
      packages/builder/src/pages/builder/auth/_components/OIDCButton.svelte
  2. 5
      packages/builder/src/pages/builder/auth/login.svelte
  3. 20
      packages/builder/src/pages/builder/portal/manage/auth/index.svelte
  4. 2
      packages/builder/src/stores/portal/organisation.js
  5. 24
      packages/worker/src/api/controllers/admin/configs.js
  6. 2
      packages/worker/src/api/routes/admin/configs.js

16
packages/builder/src/pages/builder/auth/_components/OIDCButton.svelte

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

5
packages/builder/src/pages/builder/auth/login.svelte

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

20
packages/builder/src/pages/builder/portal/manage/auth/index.svelte

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

2
packages/builder/src/stores/portal/organisation.js

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

24
packages/worker/src/api/controllers/admin/configs.js

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

2
packages/worker/src/api/routes/admin/configs.js

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

Loading…
Cancel
Save