Browse Source

Merge pull request #3159 from Budibase/feature/template-urls

allow opening a template directly from a URL
pull/4023/head
Martin McKeaveney 5 years ago
committed by GitHub
parent
commit
cb5df8fe1e
  1. 1
      packages/auth/src/constants.js
  2. 15
      packages/builder/src/components/start/CreateAppModal.svelte
  3. 6
      packages/builder/src/pages/builder/_layout.svelte
  4. 18
      packages/builder/src/pages/builder/portal/apps/index.svelte
  5. 7
      packages/builder/src/stores/portal/auth.js
  6. 858
      packages/builder/yarn.lock
  7. 11
      packages/worker/src/api/controllers/global/auth.js
  8. 2
      packages/worker/src/api/routes/global/auth.js

1
packages/auth/src/constants.js

@ -6,6 +6,7 @@ exports.UserStatus = {
exports.Cookies = {
CurrentApp: "budibase:currentapp",
Auth: "budibase:auth",
Init: "budibase:init",
OIDC_CONFIG: "budibase:oidc:config",
}

15
packages/builder/src/components/start/CreateAppModal.svelte

@ -9,7 +9,7 @@
Checkbox,
} from "@budibase/bbui"
import { store, automationStore, hostingStore } from "builderStore"
import { admin } from "stores/portal"
import { admin, auth } from "stores/portal"
import { string, mixed, object } from "yup"
import api, { get, post } from "builderStore/api"
import analytics, { Events } from "analytics"
@ -139,6 +139,7 @@
}
const userResp = await api.post(`/api/users/metadata/self`, user)
await userResp.json()
await auth.setInitInfo({})
$goto(`/builder/app/${appJson.instance._id}`)
} catch (error) {
console.error(error)
@ -146,6 +147,16 @@
submitting = false
}
}
function getModalTitle() {
let title = "Create App"
if (template.fromFile) {
title = "Import App"
} else if (template.key) {
title = "Create app from template"
}
return title
}
</script>
{#if showTemplateSelection}
@ -172,7 +183,7 @@
</ModalContent>
{:else}
<ModalContent
title={template?.fromFile ? "Import app" : "Create app"}
title={getModalTitle()}
confirmText={template?.fromFile ? "Import app" : "Create app"}
onConfirm={createNewApp}
onCancel={inline ? () => (template = null) : null}

6
packages/builder/src/pages/builder/_layout.svelte

@ -1,5 +1,5 @@
<script>
import { isActive, redirect } from "@roxi/routify"
import { isActive, redirect, params } from "@roxi/routify"
import { admin, auth } from "stores/portal"
import { onMount } from "svelte"
@ -47,6 +47,10 @@
}
onMount(async () => {
if ($params["?template"]) {
await auth.setInitInfo({ init_template: $params["?template"] })
}
await auth.checkAuth()
await admin.init()

18
packages/builder/src/pages/builder/portal/apps/index.svelte

@ -184,9 +184,27 @@
}
}
function createAppFromTemplateUrl(templateKey) {
// validate the template key just to make sure
const templateParts = templateKey.split("/")
if (templateParts.length === 2 && templateParts[0] === "app") {
template = {
key: templateKey,
}
initiateAppCreation()
} else {
notifications.error("Your Template URL is invalid. Please try another.")
}
}
onMount(async () => {
await apps.load()
loaded = true
// if the portal is loaded from an external URL with a template param
const initInfo = await auth.getInitInfo()
if (initInfo.init_template) {
createAppFromTemplateUrl(initInfo.init_template)
}
})
</script>

7
packages/builder/src/stores/portal/auth.js

@ -83,6 +83,13 @@ export function createAuthStore() {
return {
subscribe: store.subscribe,
setOrganisation: setOrganisation,
getInitInfo: async () => {
const response = await api.get(`/api/global/auth/init`)
return await response.json()
},
setInitInfo: async info => {
await api.post(`/api/global/auth/init`, info)
},
checkQueryString: async () => {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has("tenantId")) {

858
packages/builder/yarn.lock

File diff suppressed because it is too large

11
packages/worker/src/api/controllers/global/auth.js

@ -77,6 +77,17 @@ exports.authenticate = async (ctx, next) => {
})(ctx, next)
}
exports.setInitInfo = ctx => {
const initInfo = ctx.request.body
setCookie(ctx, initInfo, Cookies.Init)
ctx.status = 200
}
exports.getInitInfo = ctx => {
const initInfo = getCookie(ctx, Cookies.Init)
ctx.body = initInfo
}
/**
* Reset the user password, used as part of a forgotten password flow.
*/

2
packages/worker/src/api/routes/global/auth.js

@ -56,6 +56,8 @@ router
authController.resetUpdate
)
.post("/api/global/auth/logout", authController.logout)
.post("/api/global/auth/init", authController.setInitInfo)
.get("/api/global/auth/init", authController.getInitInfo)
.get(
"/api/global/auth/:tenantId/google",
updateTenant,

Loading…
Cancel
Save