Skip to content

Commit

Permalink
Merge branch 'master' into ts/notification-store
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr authored Jan 9, 2025
2 parents 2b90d97 + dd89562 commit 6f629a3
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 101 deletions.
31 changes: 0 additions & 31 deletions packages/builder/src/stores/portal/oidc.js

This file was deleted.

21 changes: 21 additions & 0 deletions packages/builder/src/stores/portal/oidc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { get } from "svelte/store"
import { API } from "@/api"
import { auth } from "@/stores/portal"
import { BudiStore } from "../BudiStore"
import { PublicOIDCConfig } from "@budibase/types"

class OIDCStore extends BudiStore<PublicOIDCConfig> {
constructor() {
super({})
}

async init() {
const tenantId = get(auth).tenantId
const configs = await API.getOIDCConfigs(tenantId)
// Just use the first config for now.
// We will be support multiple logins buttons later on.
this.set(configs[0] || {})
}
}

export const oidc = new OIDCStore()
66 changes: 0 additions & 66 deletions packages/builder/src/stores/portal/organisation.js

This file was deleted.

71 changes: 71 additions & 0 deletions packages/builder/src/stores/portal/organisation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { get } from "svelte/store"
import { API } from "@/api"
import { auth } from "@/stores/portal"
import {
ConfigType,
PublicSettingsInnerConfig,
SettingsBrandingConfig,
SettingsInnerConfig,
} from "@budibase/types"
import { BudiStore } from "../BudiStore"

interface LocalOrganisationState {
loaded: boolean
}

type SavedOrganisationState = SettingsInnerConfig & SettingsBrandingConfig
type OrganisationState = SavedOrganisationState &
PublicSettingsInnerConfig &
LocalOrganisationState

const DEFAULT_STATE: OrganisationState = {
platformUrl: "",
emailBrandingEnabled: true,
testimonialsEnabled: true,
platformTitle: "Budibase",
company: "Budibase",
google: false,
googleDatasourceConfigured: false,
oidc: false,
oidcCallbackUrl: "",
googleCallbackUrl: "",
loaded: false,
}

class OrganisationStore extends BudiStore<OrganisationState> {
constructor() {
super(DEFAULT_STATE)
}

async init() {
const tenantId = get(auth).tenantId
const settingsConfigDoc = await API.getTenantConfig(tenantId)
this.set({ ...DEFAULT_STATE, ...settingsConfigDoc.config, loaded: true })
}

async save(changes: Partial<SavedOrganisationState>) {
// Strip non persisted fields
const {
oidc,
google,
googleDatasourceConfigured,
oidcCallbackUrl,
googleCallbackUrl,
loaded,
...config
} = get(this.store)

// Save new config
const newConfig: SavedOrganisationState = {
...config,
...changes,
}
await API.saveConfig({
type: ConfigType.SETTINGS,
config: newConfig,
})
await this.init()
}
}

export const organisation = new OrganisationStore()
4 changes: 2 additions & 2 deletions packages/frontend-core/src/api/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { BaseAPIClient } from "./types"
export interface ConfigEndpoints {
getConfig: (type: ConfigType) => Promise<FindConfigResponse>
getTenantConfig: (tentantId: string) => Promise<GetPublicSettingsResponse>
getOIDCConfig: (tenantId: string) => Promise<GetPublicOIDCConfigResponse>
getOIDCConfigs: (tenantId: string) => Promise<GetPublicOIDCConfigResponse>
getOIDCLogos: () => Promise<Config<OIDCLogosConfig>>
saveConfig: (config: SaveConfigRequest) => Promise<SaveConfigResponse>
deleteConfig: (id: string, rev: string) => Promise<DeleteConfigResponse>
Expand Down Expand Up @@ -73,7 +73,7 @@ export const buildConfigEndpoints = (API: BaseAPIClient): ConfigEndpoints => ({
* Gets the OIDC config for a certain tenant.
* @param tenantId the tenant ID to get the config for
*/
getOIDCConfig: async tenantId => {
getOIDCConfigs: async tenantId => {
return await API.get({
url: `/api/global/configs/public/oidc?tenantId=${tenantId}`,
})
Expand Down
3 changes: 1 addition & 2 deletions packages/types/src/documents/global/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ export interface SMTPConfig extends Config<SMTPInnerConfig> {}
export interface SettingsBrandingConfig {
faviconUrl?: string
faviconUrlEtag?: string

emailBrandingEnabled?: boolean
testimonialsEnabled?: boolean
platformTitle?: string
loginHeading?: string
loginButton?: string

metaDescription?: string
metaImageUrl?: string
metaTitle?: string
Expand All @@ -42,6 +40,7 @@ export interface SettingsInnerConfig {
platformUrl?: string
company?: string
logoUrl?: string // Populated on read
docsUrl?: string
logoUrlEtag?: string
uniqueTenantId?: string
analyticsEnabled?: boolean
Expand Down

0 comments on commit 6f629a3

Please sign in to comment.