Fix email link from internal bb onboarding. Prevent account holder from being deleted

This commit is contained in:
Rory Powell 2021-10-04 11:30:59 +01:00
parent be7d343868
commit d63186ff8f
11 changed files with 53 additions and 19 deletions

View File

@ -1,23 +1,15 @@
<script> <script>
import { Input, Icon, notifications } from "@budibase/bbui" import { Input, Icon, notifications } from "@budibase/bbui"
import { store, hostingStore } from "builderStore"
export let value export let value
export let production = false
$: appId = $store.appId
$: appUrl = $hostingStore.appUrl
function fullWebhookURL(uri) { function fullWebhookURL(uri) {
if (!uri) { if (!uri) {
return "" return ""
} }
if (production) {
return `${appUrl}/${uri}`
} else {
return `${window.location.origin}/${uri}` return `${window.location.origin}/${uri}`
} }
}
function copyToClipboard() { function copyToClipboard() {
const dummy = document.createElement("textarea") const dummy = document.createElement("textarea")

View File

@ -26,8 +26,8 @@
confirmText="Self-host Budibase" confirmText="Self-host Budibase"
> >
<span <span
>Self-host budibase for free, and get SSO, unlimited apps, and more - and >Self-host budibase for free to get unlimited apps and more - and it only
it only takes a few minutes!</span takes a few minutes!</span
> >
</ModalContent> </ModalContent>
</Modal> </Modal>

View File

@ -52,11 +52,11 @@
async function deleteUser() { async function deleteUser() {
const res = await users.delete(userId) const res = await users.delete(userId)
if (res.message) { if (res.status === 200) {
notifications.success(`User ${$userFetch?.data?.email} deleted.`) notifications.success(`User ${$userFetch?.data?.email} deleted.`)
$goto("./") $goto("./")
} else { } else {
notifications.error("Failed to delete user.") notifications.error(res?.message ? res.message : "Failed to delete user.")
} }
} }

View File

@ -55,7 +55,11 @@ export function createUsersStore() {
async function del(id) { async function del(id) {
const response = await api.delete(`/api/global/users/${id}`) const response = await api.delete(`/api/global/users/${id}`)
update(users => users.filter(user => user._id !== id)) update(users => users.filter(user => user._id !== id))
return await response.json() const json = await response.json()
return {
...json,
status: response.status,
}
} }
async function save(data) { async function save(data) {

View File

@ -27,7 +27,9 @@
"multi:enable": "node scripts/multiTenancy.js enable", "multi:enable": "node scripts/multiTenancy.js enable",
"multi:disable": "node scripts/multiTenancy.js disable", "multi:disable": "node scripts/multiTenancy.js disable",
"selfhost:enable": "node scripts/selfhost.js enable", "selfhost:enable": "node scripts/selfhost.js enable",
"selfhost:disable": "node scripts/selfhost.js disable" "selfhost:disable": "node scripts/selfhost.js disable",
"localdomain:enable": "node scripts/localdomain.js enable",
"localdomain:disable": "node scripts/localdomain.js disable"
}, },
"jest": { "jest": {
"preset": "ts-jest", "preset": "ts-jest",

View File

@ -0,0 +1,22 @@
#!/usr/bin/env node
const updateDotEnv = require("update-dotenv")
const arg = process.argv.slice(2)[0]
/**
* For testing multi tenancy sub domains locally.
*
* Relies on an entry in /etc/hosts e.g:
*
* 127.0.0.1 local.com
*
* and an entry for each tenant you wish to test locally e.g:
*
* 127.0.0.1 t1.local.com
* 127.0.0.1 t2.local.com
*/
updateDotEnv({
ACCOUNT_PORTAL_URL:
arg === "enable" ? "http://local.com:10001" : "http://localhost:10001",
COOKIE_DOMAIN: arg === "enable" ? ".local.com" : "",
}).then(() => console.log("Updated worker!"))

View File

@ -23,6 +23,7 @@ async function init() {
MULTI_TENANCY: "", MULTI_TENANCY: "",
DISABLE_ACCOUNT_PORTAL: "", DISABLE_ACCOUNT_PORTAL: "",
ACCOUNT_PORTAL_URL: "http://localhost:10001", ACCOUNT_PORTAL_URL: "http://localhost:10001",
PLATFORM_URL: "http://localhost:10000",
} }
let envFile = "" let envFile = ""
Object.keys(envFileJson).forEach(key => { Object.keys(envFileJson).forEach(key => {

View File

@ -19,4 +19,6 @@ updateDotEnv({
ACCOUNT_PORTAL_URL: ACCOUNT_PORTAL_URL:
arg === "enable" ? "http://local.com:10001" : "http://localhost:10001", arg === "enable" ? "http://local.com:10001" : "http://localhost:10001",
COOKIE_DOMAIN: arg === "enable" ? ".local.com" : "", COOKIE_DOMAIN: arg === "enable" ? ".local.com" : "",
PLATFORM_URL:
arg === "enable" ? "http://local.com:10000" : "http://localhost:10000",
}).then(() => console.log("Updated worker!")) }).then(() => console.log("Updated worker!"))

View File

@ -205,6 +205,18 @@ exports.adminUser = async ctx => {
exports.destroy = async ctx => { exports.destroy = async ctx => {
const db = getGlobalDB() const db = getGlobalDB()
const dbUser = await db.get(ctx.params.id) const dbUser = await db.get(ctx.params.id)
// root account holder can't be deleted from inside budibase
const email = dbUser.email
const account = await accounts.getAccount(email)
if (account) {
if (email === ctx.user.email) {
ctx.throw(400, 'Please visit "Account" to delete this user')
} else {
ctx.throw(400, "Account holder cannot be deleted")
}
}
await removeUserFromInfoDB(dbUser) await removeUserFromInfoDB(dbUser)
await db.remove(dbUser._id, dbUser._rev) await db.remove(dbUser._id, dbUser._rev)
await userCache.invalidateUser(dbUser._id) await userCache.invalidateUser(dbUser._id)

View File

@ -40,6 +40,7 @@ module.exports = {
SMTP_HOST: process.env.SMTP_HOST, SMTP_HOST: process.env.SMTP_HOST,
SMTP_PORT: process.env.SMTP_PORT, SMTP_PORT: process.env.SMTP_PORT,
SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS, SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS,
PLATFORM_URL: process.env.PLATFORM_URL,
_set(key, value) { _set(key, value) {
process.env[key] = value process.env[key] = value
module.exports[key] = value module.exports[key] = value

View File

@ -8,8 +8,6 @@ const {
const { checkSlashesInUrl } = require("./index") const { checkSlashesInUrl } = require("./index")
const env = require("../environment") const env = require("../environment")
const { getGlobalDB, addTenantToUrl } = require("@budibase/auth/tenancy") const { getGlobalDB, addTenantToUrl } = require("@budibase/auth/tenancy")
const LOCAL_URL = `http://localhost:${env.CLUSTER_PORT || 10000}`
const BASE_COMPANY = "Budibase" const BASE_COMPANY = "Budibase"
exports.getSettingsTemplateContext = async (purpose, code = null) => { exports.getSettingsTemplateContext = async (purpose, code = null) => {
@ -17,7 +15,7 @@ exports.getSettingsTemplateContext = async (purpose, code = null) => {
// TODO: use more granular settings in the future if required // TODO: use more granular settings in the future if required
let settings = (await getScopedConfig(db, { type: Configs.SETTINGS })) || {} let settings = (await getScopedConfig(db, { type: Configs.SETTINGS })) || {}
if (!settings || !settings.platformUrl) { if (!settings || !settings.platformUrl) {
settings.platformUrl = LOCAL_URL settings.platformUrl = env.PLATFORM_URL
} }
const URL = settings.platformUrl const URL = settings.platformUrl
const context = { const context = {