diff --git a/packages/auth/src/db/utils.js b/packages/auth/src/db/utils.js index 105e038907..4bc0427976 100644 --- a/packages/auth/src/db/utils.js +++ b/packages/auth/src/db/utils.js @@ -132,29 +132,32 @@ const determineScopedConfig = async function (db, { type, user, group }) { } ) ) - const configs = response.rows.map(row => { + + function determineScore(row) { const config = row.doc // Config is specific to a user and a group if (config._id.includes(generateConfigID({ type, user, group }))) { - config.score = 4 + return 4 } else if (config._id.includes(generateConfigID({ type, user }))) { // Config is specific to a user only - config.score = 3 + return 3 } else if (config._id.includes(generateConfigID({ type, group }))) { // Config is specific to a group only - config.score = 2 + return 2 } else if (config._id.includes(generateConfigID({ type }))) { // Config is specific to a type only - config.score = 1 + return 1 } - return config - }) + return 0 + } // Find the config with the most granular scope based on context - const scopedConfig = configs.sort((a, b) => b.score - a.score)[0] + const scopedConfig = response.rows.sort( + (a, b) => determineScore(a) - determineScore(b) + )[0] - return scopedConfig + return scopedConfig.doc } exports.generateConfigID = generateConfigID diff --git a/packages/builder/src/builderStore/index.js b/packages/builder/src/builderStore/index.js index 6fecda84c0..bd849c834f 100644 --- a/packages/builder/src/builderStore/index.js +++ b/packages/builder/src/builderStore/index.js @@ -2,6 +2,7 @@ import { getFrontendStore } from "./store/frontend" import { getAutomationStore } from "./store/automation" import { getHostingStore } from "./store/hosting" import { getThemeStore } from "./store/theme" +import { getAdminStore } from "./store/admin" import { derived, writable } from "svelte/store" import analytics from "analytics" import { FrontendTypes, LAYOUT_NAMES } from "../constants" @@ -11,6 +12,7 @@ export const store = getFrontendStore() export const automationStore = getAutomationStore() export const themeStore = getThemeStore() export const hostingStore = getHostingStore() +export const adminPanelStore = getAdminStore() export const currentAsset = derived(store, $store => { const type = $store.currentFrontEndType diff --git a/packages/builder/src/builderStore/store/admin.js b/packages/builder/src/builderStore/store/admin.js new file mode 100644 index 0000000000..dcf7fef485 --- /dev/null +++ b/packages/builder/src/builderStore/store/admin.js @@ -0,0 +1,11 @@ +import { writable } from "svelte/store" + +const INITIAL_ADMIN_STATE = { + oauth: [], +} + +export const getAdminStore = () => { + const store = writable({ ...INITIAL_ADMIN_STATE }) + store.actions = {} + return store +} diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index c01de46334..de657a63ac 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -16,11 +16,14 @@ {#if $auth.user}
- +