Getting client library loading in Webstorm debug, as well as adding accessible roles endpoint.
This commit is contained in:
parent
60c1922a37
commit
bb2892cbc2
|
@ -1,8 +1,9 @@
|
||||||
import { PermissionType, PermissionLevel } from "@budibase/types"
|
import { PermissionLevel, PermissionType } from "@budibase/types"
|
||||||
export { PermissionType, PermissionLevel } from "@budibase/types"
|
|
||||||
import flatten from "lodash/flatten"
|
import flatten from "lodash/flatten"
|
||||||
import cloneDeep from "lodash/fp/cloneDeep"
|
import cloneDeep from "lodash/fp/cloneDeep"
|
||||||
|
|
||||||
|
export { PermissionType, PermissionLevel } from "@budibase/types"
|
||||||
|
|
||||||
export type RoleHierarchy = {
|
export type RoleHierarchy = {
|
||||||
permissionId: string
|
permissionId: string
|
||||||
}[]
|
}[]
|
||||||
|
@ -78,6 +79,7 @@ export const BUILTIN_PERMISSIONS = {
|
||||||
permissions: [
|
permissions: [
|
||||||
new Permission(PermissionType.QUERY, PermissionLevel.READ),
|
new Permission(PermissionType.QUERY, PermissionLevel.READ),
|
||||||
new Permission(PermissionType.TABLE, PermissionLevel.READ),
|
new Permission(PermissionType.TABLE, PermissionLevel.READ),
|
||||||
|
new Permission(PermissionType.APP, PermissionLevel.READ),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
WRITE: {
|
WRITE: {
|
||||||
|
@ -88,6 +90,7 @@ export const BUILTIN_PERMISSIONS = {
|
||||||
new Permission(PermissionType.TABLE, PermissionLevel.WRITE),
|
new Permission(PermissionType.TABLE, PermissionLevel.WRITE),
|
||||||
new Permission(PermissionType.AUTOMATION, PermissionLevel.EXECUTE),
|
new Permission(PermissionType.AUTOMATION, PermissionLevel.EXECUTE),
|
||||||
new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ),
|
new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ),
|
||||||
|
new Permission(PermissionType.APP, PermissionLevel.READ),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
POWER: {
|
POWER: {
|
||||||
|
@ -99,6 +102,7 @@ export const BUILTIN_PERMISSIONS = {
|
||||||
new Permission(PermissionType.AUTOMATION, PermissionLevel.EXECUTE),
|
new Permission(PermissionType.AUTOMATION, PermissionLevel.EXECUTE),
|
||||||
new Permission(PermissionType.WEBHOOK, PermissionLevel.READ),
|
new Permission(PermissionType.WEBHOOK, PermissionLevel.READ),
|
||||||
new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ),
|
new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ),
|
||||||
|
new Permission(PermissionType.APP, PermissionLevel.READ),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
ADMIN: {
|
ADMIN: {
|
||||||
|
@ -111,6 +115,7 @@ export const BUILTIN_PERMISSIONS = {
|
||||||
new Permission(PermissionType.WEBHOOK, PermissionLevel.READ),
|
new Permission(PermissionType.WEBHOOK, PermissionLevel.READ),
|
||||||
new Permission(PermissionType.QUERY, PermissionLevel.ADMIN),
|
new Permission(PermissionType.QUERY, PermissionLevel.ADMIN),
|
||||||
new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ),
|
new Permission(PermissionType.LEGACY_VIEW, PermissionLevel.READ),
|
||||||
|
new Permission(PermissionType.APP, PermissionLevel.READ),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
builderStore,
|
builderStore,
|
||||||
themeStore,
|
themeStore,
|
||||||
appStore,
|
appStore,
|
||||||
|
roleStore,
|
||||||
devToolsStore,
|
devToolsStore,
|
||||||
devToolsEnabled,
|
devToolsEnabled,
|
||||||
} from "stores"
|
} from "stores"
|
||||||
|
@ -84,6 +85,7 @@
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await initialise()
|
await initialise()
|
||||||
await authStore.actions.fetchUser()
|
await authStore.actions.fetchUser()
|
||||||
|
await roleStore.actions.fetchAccessibleRoles()
|
||||||
dataLoaded = true
|
dataLoaded = true
|
||||||
if (get(builderStore).inBuilder) {
|
if (get(builderStore).inBuilder) {
|
||||||
builderStore.actions.notifyLoaded()
|
builderStore.actions.notifyLoaded()
|
||||||
|
|
|
@ -11,12 +11,13 @@ export { stateStore } from "./state"
|
||||||
export { themeStore } from "./theme"
|
export { themeStore } from "./theme"
|
||||||
export { devToolsStore } from "./devTools"
|
export { devToolsStore } from "./devTools"
|
||||||
export { componentStore } from "./components"
|
export { componentStore } from "./components"
|
||||||
export { uploadStore } from "./uploads.js"
|
export { uploadStore } from "./uploads"
|
||||||
export { rowSelectionStore } from "./rowSelection.js"
|
export { rowSelectionStore } from "./rowSelection"
|
||||||
export { blockStore } from "./blocks.js"
|
export { blockStore } from "./blocks"
|
||||||
export { environmentStore } from "./environment"
|
export { environmentStore } from "./environment"
|
||||||
export { eventStore } from "./events.js"
|
export { eventStore } from "./events"
|
||||||
export { orgStore } from "./org.js"
|
export { orgStore } from "./org"
|
||||||
|
export { roleStore } from "./roles"
|
||||||
export {
|
export {
|
||||||
dndStore,
|
dndStore,
|
||||||
dndIndex,
|
dndIndex,
|
||||||
|
@ -25,7 +26,7 @@ export {
|
||||||
dndIsNewComponent,
|
dndIsNewComponent,
|
||||||
dndIsDragging,
|
dndIsDragging,
|
||||||
} from "./dnd"
|
} from "./dnd"
|
||||||
export { sidePanelStore } from "./sidePanel.js"
|
export { sidePanelStore } from "./sidePanel"
|
||||||
|
|
||||||
// Context stores are layered and duplicated, so it is not a singleton
|
// Context stores are layered and duplicated, so it is not a singleton
|
||||||
export { createContextStore } from "./context"
|
export { createContextStore } from "./context"
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { API } from "api"
|
||||||
|
import { writable } from "svelte/store"
|
||||||
|
|
||||||
|
const createRoleStore = () => {
|
||||||
|
const store = writable([])
|
||||||
|
|
||||||
|
// Fetches the user object if someone is logged in and has reloaded the page
|
||||||
|
const fetchAccessibleRoles = async () => {
|
||||||
|
const accessible = await API.getAccessibleRoles()
|
||||||
|
// Use the app self if present, otherwise fallback to the global self
|
||||||
|
store.set(accessible || [])
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
subscribe: store.subscribe,
|
||||||
|
actions: { fetchAccessibleRoles },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const roleStore = createRoleStore()
|
|
@ -38,4 +38,13 @@ export const buildRoleEndpoints = API => ({
|
||||||
url: `/api/global/roles/${appId}`,
|
url: `/api/global/roles/${appId}`,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the logging in user and current app - retrieves accessible roles.
|
||||||
|
*/
|
||||||
|
getAccessibleRoles: async () => {
|
||||||
|
return await API.get({
|
||||||
|
url: `/api/roles/accessible`,
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { roles, context, events, db as dbCore } from "@budibase/backend-core"
|
import { context, db as dbCore, events, roles } from "@budibase/backend-core"
|
||||||
import { getUserMetadataParams, InternalTables } from "../../db/utils"
|
import { getUserMetadataParams, InternalTables } from "../../db/utils"
|
||||||
import { UserCtx, Database, UserRoles, Role } from "@budibase/types"
|
import { Database, Role, UserCtx, UserRoles } from "@budibase/types"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
|
|
||||||
const UpdateRolesOptions = {
|
const UpdateRolesOptions = {
|
||||||
|
@ -94,7 +94,6 @@ export async function save(ctx: UserCtx) {
|
||||||
)
|
)
|
||||||
role._rev = result.rev
|
role._rev = result.rev
|
||||||
ctx.body = role
|
ctx.body = role
|
||||||
ctx.message = `Role '${role.name}' created successfully.`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function destroy(ctx: UserCtx) {
|
export async function destroy(ctx: UserCtx) {
|
||||||
|
@ -129,5 +128,12 @@ export async function destroy(ctx: UserCtx) {
|
||||||
role.version
|
role.version
|
||||||
)
|
)
|
||||||
ctx.message = `Role ${ctx.params.roleId} deleted successfully`
|
ctx.message = `Role ${ctx.params.roleId} deleted successfully`
|
||||||
ctx.status = 200
|
}
|
||||||
|
|
||||||
|
export async function accessible(ctx: UserCtx) {
|
||||||
|
const user = ctx.user
|
||||||
|
if (!user || !user.roleId) {
|
||||||
|
ctx.throw(400, "User does not have a valid role")
|
||||||
|
}
|
||||||
|
ctx.body = await roles.getUserRoleHierarchy(user.roleId!)
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,11 @@ export const serveApp = async function (ctx: any) {
|
||||||
//Public Settings
|
//Public Settings
|
||||||
const { config } = await configs.getSettingsConfigDoc()
|
const { config } = await configs.getSettingsConfigDoc()
|
||||||
const branding = await pro.branding.getBrandingConfig(config)
|
const branding = await pro.branding.getBrandingConfig(config)
|
||||||
|
// incase running direct from TS
|
||||||
|
let appHbsPath = join(__dirname, "app.hbs")
|
||||||
|
if (!fs.existsSync(appHbsPath)) {
|
||||||
|
appHbsPath = join(__dirname, "templates", "app.hbs")
|
||||||
|
}
|
||||||
|
|
||||||
let db
|
let db
|
||||||
try {
|
try {
|
||||||
|
@ -138,7 +143,7 @@ export const serveApp = async function (ctx: any) {
|
||||||
? objectStore.getGlobalFileUrl("settings", "logoUrl")
|
? objectStore.getGlobalFileUrl("settings", "logoUrl")
|
||||||
: "",
|
: "",
|
||||||
})
|
})
|
||||||
const appHbs = loadHandlebarsFile(`${__dirname}/app.hbs`)
|
const appHbs = loadHandlebarsFile(appHbsPath)
|
||||||
ctx.body = await processString(appHbs, {
|
ctx.body = await processString(appHbs, {
|
||||||
head,
|
head,
|
||||||
body: html,
|
body: html,
|
||||||
|
@ -166,7 +171,7 @@ export const serveApp = async function (ctx: any) {
|
||||||
: "",
|
: "",
|
||||||
})
|
})
|
||||||
|
|
||||||
const appHbs = loadHandlebarsFile(`${__dirname}/app.hbs`)
|
const appHbs = loadHandlebarsFile(appHbsPath)
|
||||||
ctx.body = await processString(appHbs, {
|
ctx.body = await processString(appHbs, {
|
||||||
head,
|
head,
|
||||||
body: html,
|
body: html,
|
||||||
|
@ -193,8 +198,12 @@ export const serveBuilderPreview = async function (ctx: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const serveClientLibrary = async function (ctx: any) {
|
export const serveClientLibrary = async function (ctx: any) {
|
||||||
|
let rootPath = join(NODE_MODULES_PATH, "@budibase", "client", "dist")
|
||||||
|
if (!fs.existsSync(rootPath)) {
|
||||||
|
rootPath = join(__dirname, "..", "..", "..", "..", "client")
|
||||||
|
}
|
||||||
return send(ctx, "budibase-client.js", {
|
return send(ctx, "budibase-client.js", {
|
||||||
root: join(NODE_MODULES_PATH, "@budibase", "client", "dist"),
|
root: rootPath,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,17 @@ import * as controller from "../controllers/role"
|
||||||
import authorized from "../../middleware/authorized"
|
import authorized from "../../middleware/authorized"
|
||||||
import { permissions } from "@budibase/backend-core"
|
import { permissions } from "@budibase/backend-core"
|
||||||
import { roleValidator } from "./utils/validators"
|
import { roleValidator } from "./utils/validators"
|
||||||
|
import { PermissionLevel, PermissionType } from "@budibase/types"
|
||||||
|
|
||||||
const router: Router = new Router()
|
const router: Router = new Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
|
// retrieve a list of the roles a user can access
|
||||||
|
.get(
|
||||||
|
"/api/roles/accessible",
|
||||||
|
authorized(PermissionType.APP, PermissionLevel.READ),
|
||||||
|
controller.accessible
|
||||||
|
)
|
||||||
.post(
|
.post(
|
||||||
"/api/roles",
|
"/api/roles",
|
||||||
authorized(permissions.BUILDER),
|
authorized(permissions.BUILDER),
|
||||||
|
|
|
@ -8,7 +8,7 @@ import path from "path"
|
||||||
* @param args Any number of string arguments to add to a path
|
* @param args Any number of string arguments to add to a path
|
||||||
* @returns {string} The final path ready to use
|
* @returns {string} The final path ready to use
|
||||||
*/
|
*/
|
||||||
export function join(...args: any) {
|
export function join(...args: string[]) {
|
||||||
return path.join(...args)
|
return path.join(...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,6 @@ export function join(...args: any) {
|
||||||
* @param args Any number of string arguments to add to a path
|
* @param args Any number of string arguments to add to a path
|
||||||
* @returns {string} The final path ready to use
|
* @returns {string} The final path ready to use
|
||||||
*/
|
*/
|
||||||
export function resolve(...args: any) {
|
export function resolve(...args: string[]) {
|
||||||
return path.resolve(...args)
|
return path.resolve(...args)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue