Fixing an issue where you could accidentally end up on org/admin page due to the reactivity statements firing all the time.

This commit is contained in:
mike12345567 2021-07-27 17:56:39 +01:00
parent 5324f506b6
commit 35f1b50511
7 changed files with 29 additions and 6 deletions

View File

@ -2,6 +2,7 @@ const { newid } = require("../hashing")
const Replication = require("./Replication")
const { getDB } = require("./index")
const { DEFAULT_TENANT_ID } = require("../constants")
const env = require("../environment")
const UNICODE_MAX = "\ufff0"
const SEPARATOR = "_"
@ -82,6 +83,9 @@ exports.getGlobalDB = tenantId => {
if (tenantId && tenantId !== DEFAULT_TENANT_ID) {
dbName = `${tenantId}${SEPARATOR}${dbName}`
}
if (env.MULTI_TENANCY && tenantId == null) {
throw "Cannot create global DB without tenantId"
}
return getDB(dbName)
}
@ -210,7 +214,7 @@ exports.getDeployedAppID = appId => {
* @return {Promise<object[]>} returns the app information document stored in each app database.
*/
exports.getAllApps = async (CouchDB, { tenantId, dev, all } = {}) => {
if (!tenantId) {
if (!env.MULTI_TENANCY && !tenantId) {
tenantId = DEFAULT_TENANT_ID
}
let allDbs = await CouchDB.allDbs()

View File

@ -16,6 +16,7 @@ module.exports = {
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
MINIO_URL: process.env.MINIO_URL,
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
MULTI_TENANCY: process.env.MULTI_TENANCY,
isTest,
_set(key, value) {
process.env[key] = value

View File

@ -10,6 +10,7 @@ const { createUserEmailView } = require("./db/views")
const { getDB } = require("./db")
const { getGlobalDB } = require("./db/utils")
const { DEFAULT_TENANT_ID, Headers } = require("./constants")
const env = require("./environment")
const APP_PREFIX = DocumentTypes.APP + SEPARATOR
@ -104,7 +105,7 @@ exports.isClient = ctx => {
exports.lookupTenantId = async userId => {
const db = getDB(StaticDatabases.PLATFORM_INFO.name)
let tenantId = DEFAULT_TENANT_ID
let tenantId = env.MULTI_TENANCY ? DEFAULT_TENANT_ID : null
try {
const doc = await db.get(userId)
if (doc && doc.tenantId) {

View File

@ -16,9 +16,10 @@
// Force creation of an admin user if one doesn't exist
$: {
if (loaded && multiTenancyEnabled && !tenantSet) {
const apiReady = $admin.loaded && $auth.loaded
if (loaded && apiReady && multiTenancyEnabled && !tenantSet) {
$redirect("./auth/org")
} else if (loaded && !hasAdminUser) {
} else if (loaded && apiReady && !hasAdminUser) {
$redirect("./admin")
}
}

View File

@ -27,6 +27,8 @@
auth.checkQueryString()
if (!multiTenancyEnabled) {
$goto("../")
} else {
admin.unload()
}
})
</script>

View File

@ -3,7 +3,9 @@ import api from "builderStore/api"
import { auth } from "stores/portal"
export function createAdminStore() {
const admin = writable({})
const admin = writable({
loaded: false,
})
async function init() {
try {
@ -20,13 +22,14 @@ export function createAdminStore() {
0
)
await multiTenancyEnabled()
admin.update(store => {
store.loaded = true
store.checklist = json
store.onboardingProgress =
(stepsComplete / onboardingSteps.length) * 100
return store
})
await multiTenancyEnabled()
} catch (err) {
admin.update(store => {
store.checklist = null
@ -51,9 +54,17 @@ export function createAdminStore() {
return enabled
}
function unload() {
admin.update(store => {
store.loaded = false
return store
})
}
return {
subscribe: admin.subscribe,
init,
unload,
}
}

View File

@ -6,6 +6,7 @@ export function createAuthStore() {
user: null,
tenantId: "default",
tenantSet: false,
loaded: false,
})
const store = derived(auth, $store => {
let initials = null
@ -30,6 +31,7 @@ export function createAuthStore() {
user: $store.user,
tenantId: $store.tenantId,
tenantSet: $store.tenantSet,
loaded: $store.loaded,
initials,
isAdmin,
isBuilder,
@ -38,6 +40,7 @@ export function createAuthStore() {
function setUser(user) {
auth.update(store => {
store.loaded = true
store.user = user
if (user) {
store.tenantId = user.tenantId || "default"