From 4b3891f68ac18ea5d143c5827bdcdfd66e44ffdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Mon, 22 Mar 2021 09:59:22 +0100 Subject: [PATCH] moves permissions to a separate store --- .../builder/src/builderStore/store/backend.js | 6 ++-- .../src/builderStore/store/backend/index.js | 1 + .../builderStore/store/backend/permissions.js | 29 +++++++++++++++++++ .../buttons/ManageAccessButton.svelte | 16 ++++------ 4 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 packages/builder/src/builderStore/store/backend/index.js create mode 100644 packages/builder/src/builderStore/store/backend/permissions.js diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index a47a231d2b..47dc6725b6 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -1,6 +1,7 @@ import { writable, get } from "svelte/store" import { cloneDeep } from "lodash/fp" import api from "../api" +import { permissions } from './backend/permissions' const INITIAL_BACKEND_UI_STATE = { tables: [], @@ -26,18 +27,15 @@ export const getBackendUiStore = () => { api.get(`/api/tables`).then(r => r.json()), api.get(`/api/datasources`).then(r => r.json()), api.get(`/api/queries`).then(r => r.json()), - api.get("/api/integrations").then(r => r.json()) + api.get("/api/integrations").then(r => r.json()), ]) - const permissionLevels = await store.actions.permissions.fetchLevels() - store.update(state => { state.selectedDatabase = db state.tables = tables state.datasources = datasources state.queries = queries state.integrations = integrations - state.permissionLevels = permissionLevels return state }) }, diff --git a/packages/builder/src/builderStore/store/backend/index.js b/packages/builder/src/builderStore/store/backend/index.js new file mode 100644 index 0000000000..011663961c --- /dev/null +++ b/packages/builder/src/builderStore/store/backend/index.js @@ -0,0 +1 @@ +export { permissions } from "./permissions" diff --git a/packages/builder/src/builderStore/store/backend/permissions.js b/packages/builder/src/builderStore/store/backend/permissions.js new file mode 100644 index 0000000000..70070f9072 --- /dev/null +++ b/packages/builder/src/builderStore/store/backend/permissions.js @@ -0,0 +1,29 @@ +import { writable } from "svelte/store" +import api from "../../api" + +function createPermissionStore() { + const { subscribe, set } = writable([]) + + return { + subscribe, + fetchLevels: async () => { + const response = await api.get("/api/permission/levels") + const json = await response.json() + set(json) + }, + forResource: async resourceId => { + const response = await api.get(`/api/permission/${resourceId}`) + const json = await response.json() + return json + }, + save: async ({ role, resource, level }) => { + const response = await api.post( + `/api/permission/${role}/${resource}/${level}` + ) + const json = await response.json() + return json + }, + } +} + +export const permissions = createPermissionStore() diff --git a/packages/builder/src/components/backend/DataTable/buttons/ManageAccessButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/ManageAccessButton.svelte index 2540267d72..ac3550d5b5 100644 --- a/packages/builder/src/components/backend/DataTable/buttons/ManageAccessButton.svelte +++ b/packages/builder/src/components/backend/DataTable/buttons/ManageAccessButton.svelte @@ -1,22 +1,18 @@ @@ -30,8 +26,8 @@