1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00

Move all session population to budibase (bug fix)

This commit is contained in:
Rory Powell 2021-09-20 11:26:19 +01:00
parent 6a48cff5d5
commit 1d873d9e11
8 changed files with 83 additions and 4 deletions

View file

@ -1,5 +1,7 @@
const redis = require("../redis/authRedis")
const { getTenantId, lookupTenantId, getGlobalDB } = require("../tenancy")
const env = require("../environment")
const accounts = require("../cloud/accounts")
const EXPIRY_SECONDS = 3600
@ -9,6 +11,15 @@ const EXPIRY_SECONDS = 3600
const populateFromDB = async (userId, tenantId) => {
const user = await getGlobalDB(tenantId).get(userId)
user.budibaseAccess = true
if (!env.SELF_HOSTED) {
const account = await accounts.getAccount(user.email)
if (account) {
user.account = account
user.accountPortalAccess = true
}
}
return user
}

View file

@ -0,0 +1,22 @@
const API = require("./api")
const env = require("../environment")
const api = new API(env.ACCOUNT_PORTAL_URL)
// TODO: Authorization
exports.getAccount = async email => {
const payload = {
email,
}
const response = await api.post(`/api/accounts/search`, {
body: payload,
})
const json = await response.json()
if (response.status !== 200) {
throw Error(`Error getting account by email ${email}`, json)
}
return json[0]
}

View file

@ -0,0 +1,44 @@
const fetch = require("node-fetch")
class API {
constructor(host) {
this.host = host
}
apiCall =
method =>
async (url = "", options = {}) => {
if (!options.headers) {
options.headers = {}
}
if (!options.headers["Content-Type"]) {
options.headers = {
"Content-Type": "application/json",
Accept: "application/json",
...options.headers,
}
}
let json = options.headers["Content-Type"] === "application/json"
const requestOptions = {
method: method,
body: json ? JSON.stringify(options.body) : options.body,
headers: options.headers,
// TODO: See if this is necessary
credentials: "include",
}
const resp = await fetch(`${this.host}${url}`, requestOptions)
return resp
}
post = this.apiCall("POST")
get = this.apiCall("GET")
patch = this.apiCall("PATCH")
del = this.apiCall("DELETE")
put = this.apiCall("PUT")
}
module.exports = API

View file

@ -19,6 +19,8 @@ module.exports = {
MINIO_URL: process.env.MINIO_URL,
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
MULTI_TENANCY: process.env.MULTI_TENANCY,
ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED),
isTest,
_set(key, value) {
process.env[key] = value

View file

@ -26,7 +26,7 @@ module.exports = {
COUCH_DB_URL: process.env.COUCH_DB_URL,
MINIO_URL: process.env.MINIO_URL,
WORKER_URL: process.env.WORKER_URL,
SELF_HOSTED: process.env.SELF_HOSTED,
SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED),
AWS_REGION: process.env.AWS_REGION,
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,

View file

@ -21,7 +21,7 @@ async function init() {
COUCH_DB_PASSWORD: "budibase",
// empty string is false
MULTI_TENANCY: "",
ACCOUNT_PORTAL_URL: "http://localhost:3001",
ACCOUNT_PORTAL_URL: "http://localhost:10001",
}
let envFile = ""
Object.keys(envFileJson).forEach(key => {

View file

@ -3,7 +3,7 @@ const env = require("../../../environment")
exports.fetch = async ctx => {
ctx.body = {
multiTenancy: !!env.MULTI_TENANCY,
cloud: !(env.SELF_HOSTED === "1"),
cloud: !env.SELF_HOSTED,
accountPortalUrl: env.ACCOUNT_PORTAL_URL,
}
}

View file

@ -18,7 +18,7 @@ if (!LOADED && isDev() && !isTest()) {
module.exports = {
NODE_ENV: process.env.NODE_ENV,
SELF_HOSTED: process.env.SELF_HOSTED,
SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED),
PORT: process.env.PORT,
CLUSTER_PORT: process.env.CLUSTER_PORT,
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,