From fe79f294b4cad10d8b0116172245432c4431fdf4 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Wed, 27 May 2020 17:23:01 +0100 Subject: [PATCH] access levels --- .../components/database/ModelDataTable/api.js | 8 +- .../ModelDataTable/modals/CreateUser.svelte | 15 +- packages/cli/src/commands/init/index.js | 9 +- packages/cli/src/commands/init/initHandler.js | 26 +-- packages/server/.vscode/launch.json | 13 ++ .../server/src/api/controllers/accesslevel.js | 108 ++++++++++ packages/server/src/api/controllers/auth.js | 17 +- packages/server/src/api/controllers/record.js | 27 ++- packages/server/src/api/controllers/user.js | 39 +++- packages/server/src/api/index.js | 10 +- packages/server/src/api/routes/accesslevel.js | 14 ++ packages/server/src/api/routes/application.js | 12 +- packages/server/src/api/routes/client.js | 4 +- packages/server/src/api/routes/component.js | 3 + packages/server/src/api/routes/index.js | 8 +- packages/server/src/api/routes/instance.js | 6 +- packages/server/src/api/routes/model.js | 45 ++++- packages/server/src/api/routes/pages.js | 120 ++++++----- packages/server/src/api/routes/record.js | 12 -- packages/server/src/api/routes/screen.js | 12 +- .../src/api/routes/tests/accesslevel.spec.js | 184 +++++++++++++++++ .../src/api/routes/tests/application.spec.js | 27 ++- .../src/api/routes/tests/couchTestUtils.js | 190 +++++++++++++++++- .../server/src/api/routes/tests/model.spec.js | 48 ++++- .../src/api/routes/tests/record.spec.js | 137 ++++++++++--- .../server/src/api/routes/tests/user.spec.js | 31 ++- .../server/src/api/routes/tests/view.spec.js | 72 ++++++- .../src/api/routes/tests/workflow.spec.js | 42 +++- packages/server/src/api/routes/user.js | 22 +- packages/server/src/api/routes/view.js | 14 +- packages/server/src/api/routes/workflow.js | 27 ++- .../server/src/middleware/authenticated.js | 40 +++- packages/server/src/middleware/authorized.js | 58 ++++++ packages/server/src/utilities/accessLevels.js | 79 ++++++++ 34 files changed, 1274 insertions(+), 205 deletions(-) create mode 100644 packages/server/src/api/controllers/accesslevel.js create mode 100644 packages/server/src/api/routes/accesslevel.js delete mode 100644 packages/server/src/api/routes/record.js create mode 100644 packages/server/src/api/routes/tests/accesslevel.spec.js create mode 100644 packages/server/src/middleware/authorized.js create mode 100644 packages/server/src/utilities/accessLevels.js diff --git a/packages/builder/src/components/database/ModelDataTable/api.js b/packages/builder/src/components/database/ModelDataTable/api.js index c573814e88..e9592074bf 100644 --- a/packages/builder/src/components/database/ModelDataTable/api.js +++ b/packages/builder/src/components/database/ModelDataTable/api.js @@ -1,6 +1,6 @@ import api from "builderStore/api" -export async function createUser(user, appId, instanceId) { +export async function createUser(user, instanceId) { const CREATE_USER_URL = `/api/${instanceId}/users` const response = await api.post(CREATE_USER_URL, user) return await response.json() @@ -15,20 +15,20 @@ export async function createDatabase(appname, instanceName) { } export async function deleteRecord(record, instanceId) { - const DELETE_RECORDS_URL = `/api/${instanceId}/records/${record._id}/${record._rev}` + const DELETE_RECORDS_URL = `/api/${instanceId}/${record.modelId}/records/${record._id}/${record._rev}` const response = await api.delete(DELETE_RECORDS_URL) return response } export async function saveRecord(record, instanceId) { - const SAVE_RECORDS_URL = `/api/${instanceId}/records` + const SAVE_RECORDS_URL = `/api/${instanceId}/${record.modelId}/records` const response = await api.post(SAVE_RECORDS_URL, record) return await response.json() } export async function fetchDataForView(viewName, instanceId) { - const FETCH_RECORDS_URL = `/api/${instanceId}/${viewName}/records` + const FETCH_RECORDS_URL = `/api/${instanceId}/views/${viewName}` const response = await api.get(FETCH_RECORDS_URL) return await response.json() diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateUser.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateUser.svelte index 842703af1c..77e0850b87 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateUser.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateUser.svelte @@ -7,14 +7,15 @@ let username let password + let accessLevelId - $: valid = username && password + $: valid = username && password && accessLevelId $: instanceId = $backendUiStore.selectedDatabase._id $: appId = $store.appId async function createUser() { - const user = { name: username, username, password } - const response = await api.createUser(user, appId, instanceId) + const user = { name: username, username, password, accessLevelId } + const response = await api.createUser(user, instanceId) backendUiStore.actions.users.create(response) onClosed() } @@ -30,6 +31,14 @@ +
+ + +