diff --git a/packages/auth/src/middleware/authenticated.js b/packages/auth/src/middleware/authenticated.js index 34ed0ec186..5d9056b19a 100644 --- a/packages/auth/src/middleware/authenticated.js +++ b/packages/auth/src/middleware/authenticated.js @@ -43,6 +43,7 @@ module.exports = (noAuthPatterns = [], opts) => { // this is an internal request, no user made it if (apiKey && apiKey === env.INTERNAL_API_KEY) { ctx.isAuthenticated = true + ctx.internal = true } else if (authCookie) { try { const db = database.getDB(StaticDatabases.GLOBAL.name) diff --git a/packages/builder/src/pages/builder/portal/_layout.svelte b/packages/builder/src/pages/builder/portal/_layout.svelte index fb488c58d7..9dc4e19b6a 100644 --- a/packages/builder/src/pages/builder/portal/_layout.svelte +++ b/packages/builder/src/pages/builder/portal/_layout.svelte @@ -20,18 +20,40 @@ let userInfoModal let changePasswordModal - const menu = [ - { title: "Apps", href: "/builder/portal/apps" }, - { title: "Users", href: "/builder/portal/manage/users", heading: "Manage" }, - { title: "Auth", href: "/builder/portal/manage/auth" }, - { title: "Email", href: "/builder/portal/manage/email" }, - { - title: "Organisation", - href: "/builder/portal/settings/organisation", - heading: "Settings", - }, - { title: "Theming", href: "/builder/portal/settings/theming" }, - ] + $: menu = buildMenu($auth.isAdmin) + + const buildMenu = admin => { + let menu = [{ title: "Apps", href: "/builder/portal/apps" }] + if (admin) { + menu = menu.concat([ + { + title: "Users", + href: "/builder/portal/manage/users", + heading: "Manage", + }, + { title: "Auth", href: "/builder/portal/manage/auth" }, + { title: "Email", href: "/builder/portal/manage/email" }, + { + title: "Organisation", + href: "/builder/portal/settings/organisation", + heading: "Settings", + }, + { + title: "Theming", + href: "/builder/portal/settings/theming", + }, + ]) + } else { + menu = menu.concat([ + { + title: "Theming", + href: "/builder/portal/settings/theming", + heading: "Settings", + }, + ]) + } + return menu + } onMount(async () => { // Prevent non-builders from accessing the portal diff --git a/packages/builder/src/pages/builder/portal/manage/_layout.svelte b/packages/builder/src/pages/builder/portal/manage/_layout.svelte new file mode 100644 index 0000000000..356b362b0b --- /dev/null +++ b/packages/builder/src/pages/builder/portal/manage/_layout.svelte @@ -0,0 +1,18 @@ + + +{#if $auth.isAdmin} + + + +{/if} diff --git a/packages/builder/src/pages/builder/portal/manage/auth/_layout.svelte b/packages/builder/src/pages/builder/portal/manage/auth/_layout.svelte deleted file mode 100644 index f9c2067a94..0000000000 --- a/packages/builder/src/pages/builder/portal/manage/auth/_layout.svelte +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/packages/builder/src/pages/builder/portal/manage/email/_layout.svelte b/packages/builder/src/pages/builder/portal/manage/email/_layout.svelte index 188f0bb016..410a7d4ff2 100644 --- a/packages/builder/src/pages/builder/portal/manage/email/_layout.svelte +++ b/packages/builder/src/pages/builder/portal/manage/email/_layout.svelte @@ -1,5 +1,6 @@ diff --git a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte index 0fa89bad52..983b31168c 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte @@ -17,7 +17,7 @@ notifications, } from "@budibase/bbui" import { fetchData } from "helpers" - import { users } from "stores/portal" + import { users, auth } from "stores/portal" import TagsRenderer from "./_components/TagsTableRenderer.svelte" import UpdateRolesModal from "./_components/UpdateRolesModal.svelte" @@ -56,13 +56,21 @@ let toggleDisabled = false - async function toggleBuilderAccess({ detail }) { + async function toggleFlag(flagName, detail) { toggleDisabled = true - await users.save({ ...$userFetch?.data, builder: { global: detail } }) + await users.save({ ...$userFetch?.data, [flagName]: { global: detail } }) await userFetch.refresh() toggleDisabled = false } + async function toggleBuilderAccess({ detail }) { + return toggleFlag("builder", detail) + } + + async function toggleAdminAccess({ detail }) { + return toggleFlag("admin", detail) + } + async function openUpdateRolesModal({ detail }) { selectedApp = detail editRolesModal.show() @@ -107,15 +115,27 @@ -
- - -
+ + {#if userId !== $auth.user._id} +
+ + +
+
+ + +
+ {/if}
- import { Page } from "@budibase/bbui" - - - - - diff --git a/packages/builder/src/pages/builder/portal/manage/users/index.svelte b/packages/builder/src/pages/builder/portal/manage/users/index.svelte index 6b0037ddab..6d2134ad02 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/index.svelte @@ -22,6 +22,7 @@ const schema = { email: {}, developmentAccess: { displayName: "Development Access", type: "boolean" }, + adminAccess: { displayName: "Admin Access", type: "boolean" }, // role: { type: "options" }, group: {}, // access: {}, @@ -35,7 +36,8 @@ .map(user => ({ ...user, group: ["All users"], - developmentAccess: user.builder.global, + developmentAccess: !!user.builder?.global, + adminAccess: !!user.admin?.global, })) let createUserModal diff --git a/packages/builder/src/pages/builder/portal/settings/index.svelte b/packages/builder/src/pages/builder/portal/settings/index.svelte index 9e264e0583..57825a095b 100644 --- a/packages/builder/src/pages/builder/portal/settings/index.svelte +++ b/packages/builder/src/pages/builder/portal/settings/index.svelte @@ -1,4 +1,4 @@ diff --git a/packages/builder/src/pages/builder/portal/settings/organisation.svelte b/packages/builder/src/pages/builder/portal/settings/organisation.svelte index ec278fa0e4..046f55615b 100644 --- a/packages/builder/src/pages/builder/portal/settings/organisation.svelte +++ b/packages/builder/src/pages/builder/portal/settings/organisation.svelte @@ -11,10 +11,18 @@ Dropzone, notifications, } from "@budibase/bbui" - import { organisation } from "stores/portal" + import { auth, organisation } from "stores/portal" import { post } from "builderStore/api" import analytics from "analytics" import { writable } from "svelte/store" + import { redirect } from "@roxi/routify" + + // Only admins allowed here + $: { + if (!$auth.isAdmin) { + $redirect("../../portal") + } + } const values = writable({ analytics: !analytics.disabled(), @@ -64,68 +72,70 @@ } - - - Organisation - - Organisation settings is where you can edit your organisation name and - logo. You can also configure your platform URL and enable or disable - analytics. - - - - - Information - Here you can update your logo and organization name. - -
-
- - -
- -
- - - Platform - Here you can set up general platform settings. - -
-
- - -
-
- - +{#if $auth.isAdmin} + - Analytics - - If you would like to send analytics that help us make Budibase better, - please let us know below. + Organisation + + Organisation settings is where you can edit your organisation name and + logo. You can also configure your platform URL and enable or disable + analytics. + + + Information + Here you can update your logo and organization name. +
- - + + +
+
+ + + Platform + Here you can set up general platform settings. + +
+
+ + +
+
+ + + + Analytics + + If you would like to send analytics that help us make Budibase better, + please let us know below. + + +
+
+ + +
+
+
+
+ +
-
- -
-
+{/if}