Merge branch 'dev-experience' of https://github.com/Budibase/budibase into feature/global-user-management

This commit is contained in:
Martin McKeaveney 2021-04-07 17:17:00 +01:00
commit 2d7823f314
20 changed files with 122 additions and 80 deletions

1
.gitignore vendored
View File

@ -63,6 +63,7 @@ typings/
# dotenv environment variables file
.env
!hosting/.env
hosting/generated-envoy.dev.yaml
# parcel-bundler cache (https://parceljs.org/)
.cache

View File

@ -27,7 +27,7 @@ services:
restart: always
image: envoyproxy/envoy:v1.16-latest
volumes:
- ./envoy.dev.yaml:/etc/envoy/envoy.yaml
- ./generated-envoy.dev.yaml:/etc/envoy/envoy.yaml
ports:
- "${MAIN_PORT}:10000"
depends_on:

View File

@ -106,7 +106,7 @@ static_resources:
- endpoint:
address:
socket_address:
address: 172.17.0.1
address: {{ address }}
port_value: 4001
- name: builder-dev
@ -120,6 +120,6 @@ static_resources:
- endpoint:
address:
socket_address:
address: 172.17.0.1
address: {{ address }}
port_value: 3000

View File

@ -23,7 +23,9 @@
"publishdev": "lerna run publishdev",
"publishnpm": "yarn build && lerna publish --force-publish",
"restore": "npm run clean && npm run bootstrap && npm run build",
"nuke": "rimraf ~/.budibase && npm run restore && lerna run --parallel dev:stack:nuke",
"nuke": "npm run nuke:packages && npm run nuke:docker",
"nuke:packages": "npm run restore",
"nuke:docker": "lerna run --parallel dev:stack:nuke",
"clean": "lerna clean",
"kill-port": "kill-port 4001",
"dev": "yarn run kill-port && lerna link && lerna run --parallel dev:builder --concurrency 1",

View File

@ -48,11 +48,11 @@ export default function positionDropdown(element, { anchor, align }) {
element.style.left = `${calcLeftPosition(dimensions).toFixed(0)}px`
const resizeObserver = new ResizeObserver(entries => {
for (let entry of entries) {
entries.forEach(() => {
dimensions = getDimensions()
element.style[positionSide] = `${dimensions[positionSide]}px`
element.style.left = `${calcLeftPosition(dimensions).toFixed(0)}px`
}
})
})
resizeObserver.observe(anchor)

View File

@ -11,8 +11,6 @@ const createNotificationStore = () => {
})
}
let timers = []
const notifications = derived(_notifications, ($_notifications, set) => {
set($_notifications)
if ($_notifications.length > 0) {

View File

@ -109,7 +109,8 @@ context("Create a View", () => {
.find(".ag-cell")
.then($values => {
const values = Array.from($values).map(value => value.textContent)
expect(values.sort()).to.deep.eq([
expect(values.sort()).to.deep.eq(
[
"Students",
"23.333333333333332",
"1650",
@ -117,7 +118,8 @@ context("Create a View", () => {
"25",
"20",
"70",
].sort())
].sort()
)
})
})

View File

@ -57,9 +57,9 @@ Cypress.Commands.add("createApp", name => {
Cypress.Commands.add("deleteApp", name => {
cy.visit(`localhost:${Cypress.env("PORT")}/builder`)
cy.get("body").then($body => {
cy.get(".apps").then($apps => {
cy.wait(1000)
if ($body.find(`[data-cy="app-${name}"]`).length) {
if ($apps.find(`[data-cy="app-${name}"]`).length) {
cy.get(`[data-cy="app-${name}"] a`).click()
cy.get("[data-cy=settings-icon]").click()
cy.get(".modal-content").within(() => {

View File

@ -20,6 +20,9 @@ export const get = apiCall("GET")
export const patch = apiCall("PATCH")
export const del = apiCall("DELETE")
export const put = apiCall("PUT")
export const getBuilderCookie = async () => {
await post("/api/builder/login", {})
}
export default {
post: apiCall("POST"),
@ -27,4 +30,5 @@ export default {
patch: apiCall("PATCH"),
delete: apiCall("DELETE"),
put: apiCall("PUT"),
getBuilderCookie,
}

View File

@ -6,6 +6,7 @@ import { derived, writable } from "svelte/store"
import analytics from "analytics"
import { FrontendTypes, LAYOUT_NAMES } from "../constants"
import { findComponent } from "./storeUtils"
import { getBuilderCookie } from "./api"
export const store = getFrontendStore()
export const automationStore = getAutomationStore()
@ -57,6 +58,8 @@ export const selectedAccessRole = writable("BASIC")
export const initialise = async () => {
try {
// TODO this needs to be replaced by a real login
await getBuilderCookie()
await analytics.activate()
analytics.captureEvent("Builder Started")
} catch (err) {

View File

@ -26,7 +26,7 @@
notifier.success(`View ${name} created`)
onClosed()
analytics.captureEvent("View Created", { name })
$goto(`../../../view/${name}`)
$goto(`../../view/${name}`)
}
</script>

View File

@ -45,7 +45,11 @@
}
</script>
<div class="root">
{#await promise}
<!-- This should probably be some kind of loading state? -->
<div class="loading" />
{:then _}
<div class="root">
<div class="top-nav">
<div class="topleftnav">
<button class="home-logo">
@ -92,18 +96,20 @@
Request feature
</Button>
</div>
{#await promise}
<!-- This should probably be some kind of loading state? -->
<div />
{:then _}
<slot />
{:catch error}
</div>
{:catch error}
<p>Something went wrong: {error.message}</p>
{/await}
</div>
{/await}
<style>
.loading {
min-height: 100%;
height: 100%;
width: 100%;
background: var(--background);
}
.root {
min-height: 100%;
height: 100%;

View File

@ -18,6 +18,7 @@
let previousType
let previousAsset
let previousComponentId
let hydrationComplete = false
// Hydrate state from URL params
$: hydrateStateFromURL($params, $leftover)
@ -30,6 +31,12 @@
)
const hydrateStateFromURL = (params, leftover) => {
if (hydrationComplete) {
return
} else {
hydrationComplete = true
}
// Do nothing if no asset type, as that means we've left the page
if (!params.assetType) {
return

View File

@ -27,7 +27,7 @@ export default ({ mode }) => {
}),
],
optimizeDeps: {
include: ['ag-grid-community'],
include: ["ag-grid-community"],
exclude: ["@roxi/routify"],
},
resolve: {

View File

@ -2,6 +2,11 @@
const compose = require("docker-compose")
const path = require("path")
const fs = require("fs")
const { processStringSync } = require("@budibase/string-templates")
function isLinux() {
return process.platform !== "darwin" && process.platform !== "win32"
}
// This script wraps docker-compose allowing you to manage your dev infrastructure with simple commands.
const CONFIG = {
@ -17,6 +22,16 @@ const Commands = {
}
async function init() {
// generate envoy file, always do this incase it has changed
const hostingPath = path.join(process.cwd(), "..", "..", "hosting")
const envoyHbsPath = path.join(hostingPath, "envoy.dev.yaml.hbs")
const envoyOutputPath = path.join(hostingPath, "generated-envoy.dev.yaml")
const contents = fs.readFileSync(envoyHbsPath, "utf8")
const config = {
address: isLinux() ? "172.17.0.1" : "host.docker.internal",
}
fs.writeFileSync(envoyOutputPath, processStringSync(contents, config))
const envFilePath = path.join(process.cwd(), ".env")
if (fs.existsSync(envFilePath)) {
return

View File

@ -8,6 +8,7 @@ const { setCookie } = require("../../utilities")
const { outputProcessing } = require("../../utilities/rowProcessor")
const { ViewNames } = require("../../db/utils")
const { UserStatus } = require("../../constants")
const setBuilderToken = require("../../utilities/builder/setBuilderToken")
const INVALID_ERR = "Invalid Credentials"
@ -69,6 +70,11 @@ exports.authenticate = async ctx => {
}
}
exports.builderLogin = async ctx => {
await setBuilderToken(ctx)
ctx.status = 200
}
exports.fetchSelf = async ctx => {
const { userId, appId } = ctx.user
/* istanbul ignore next */

View File

@ -1,9 +1,13 @@
const Router = require("@koa/router")
const controller = require("../controllers/auth")
const authorized = require("../../middleware/authorized")
const { BUILDER } = require("../../utilities/security/permissions")
const router = Router()
router.post("/api/authenticate", controller.authenticate)
// TODO: this is a hack simply to make sure builder has a cookie until auth reworked
router.post("/api/builder/login", authorized(BUILDER), controller.builderLogin)
// doesn't need authorization as can only fetch info about self
router.get("/api/self", controller.fetchSelf)

View File

@ -42,11 +42,6 @@ module.exports = (permType, permLevel = null) => async (ctx, next) => {
const isAdmin = ADMIN_ROLES.includes(role._id)
const isAuthed = ctx.auth.authenticated
// TODO: this was added while we work towards a better auth method
if (permType === PermissionTypes.BUILDER) {
return next()
}
const { basePermissions, permissions } = await getUserPermissions(
ctx.appId,
role._id

View File

@ -144,8 +144,7 @@ describe("Authorization middleware", () => {
expect(config.next).toHaveBeenCalled()
})
// TODO: this has been skipped while auth is still in flux
xit("throws if the user has only builder permissions", async () => {
it("throws if the user has only builder permissions", async () => {
config.setEnvironment(false)
config.setMiddlewareRequiredPermission(PermissionTypes.BUILDER)
config.setUser({