first time setup E2E

This commit is contained in:
Martin McKeaveney 2021-05-05 21:56:43 +01:00
parent 4bc1a7dc3c
commit 1aedba80bd
6 changed files with 51 additions and 19 deletions

View File

@ -0,0 +1,35 @@
<script>
import { onMount } from "svelte"
import { goto } from "@roxi/routify"
import {
SideNavigation as Navigation,
SideNavigationItem as Item,
} from "@budibase/bbui"
import { auth } from "stores/backend"
import LoginForm from "components/login/LoginForm.svelte"
import BuilderSettingsButton from "components/start/BuilderSettingsButton.svelte"
import LogoutButton from "components/start/LogoutButton.svelte"
import Logo from "/assets/budibase-logo.svg"
import api from "builderStore/api"
let modal
let checklist
async function fetchConfigChecklist() {
const response = await api.get("/api/admin/configs/checklist")
return await response.json()
}
onMount(async () => {
const response = await fetchConfigChecklist()
if (!response.adminUser) {
$goto("./admin")
}
checklist = response
})
</script>
{#if checklist}
<slot />
{/if}

View File

@ -8,26 +8,21 @@
Input,
Body,
} from "@budibase/bbui"
import { goto } from "@roxi/routify"
import { onMount } from "svelte"
import api from "builderStore/api"
let adminUser = {}
async function save(doc) {
async function save() {
try {
// Save the admin user
const response = await api.post(`/api/admin/users`, {
email: adminUser.email,
password: adminUser.password,
roles: {},
admin: {
global: true,
},
})
const response = await api.post(`/api/admin/users/init`, adminUser)
const json = await response.json()
if (response.status !== 200) throw new Error(json.message)
notifications.success(`Admin user created.`)
$goto("../portal")
} catch (err) {
notifications.error(`Failed to create admin user.`)
}

View File

@ -10,6 +10,7 @@
SideNavigation as Navigation,
SideNavigationItem as Item,
} from "@budibase/bbui"
import api from "builderStore/api"
let orgName
let orgLogo
@ -22,12 +23,8 @@
orgLogo = "https://via.placeholder.com/150"
// set onBoardingProgress
onBoardingProgress = 20
user = { name: "John Doe" }
if (onBoardingProgress < 21) {
$goto("../admin")
}
user = { name: "John Doe" }
}
onMount(getInfo)

View File

@ -60,14 +60,18 @@ exports.save = async ctx => {
}
}
exports.firstUser = async ctx => {
exports.adminUser = async ctx => {
const { email, password } = ctx.request.body
ctx.request.body = {
email: FIRST_USER_EMAIL,
password: FIRST_USER_PASSWORD,
email: email,
password: password,
roles: {},
builder: {
global: true,
},
admin: {
global: true,
},
}
await exports.save(ctx)
}

View File

@ -5,7 +5,8 @@ const { routes } = require("./routes")
const { buildAuthMiddleware } = require("@budibase/auth").auth
const NO_AUTH_ENDPOINTS = [
"/api/admin/users/first",
"/api/admin/users/init",
"/api/admin/configs/checklist",
"/api/admin/auth",
"/api/admin/auth/google",
"/api/admin/auth/google/callback",

View File

@ -27,7 +27,7 @@ function buildUserSaveValidation() {
router
.post("/api/admin/users", buildUserSaveValidation(), controller.save)
.get("/api/admin/users", controller.fetch)
.post("/api/admin/users/first", controller.firstUser)
.post("/api/admin/users/init", controller.adminUser)
.delete("/api/admin/users/:id", controller.destroy)
.get("/api/admin/users/:id", controller.find)