From 27813f5fbb8dc53bdcad27ced2f522a08007a0d1 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 24 Nov 2020 10:23:29 +0000 Subject: [PATCH 01/13] fix windows url issue --- .../components/settings/SettingsModal.svelte | 5 ----- packages/server/package.json | 1 + packages/server/src/electron.js | 3 ++- packages/server/yarn.lock | 20 +++++++++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/components/settings/SettingsModal.svelte b/packages/builder/src/components/settings/SettingsModal.svelte index 44ab581521..559d28da39 100644 --- a/packages/builder/src/components/settings/SettingsModal.svelte +++ b/packages/builder/src/components/settings/SettingsModal.svelte @@ -8,11 +8,6 @@ key: "GENERAL", component: General, }, - { - title: "Users", - key: "USERS", - component: Users, - }, { title: "API Keys", key: "API_KEYS", diff --git a/packages/server/package.json b/packages/server/package.json index b4b3ace737..6cda3975d0 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -81,6 +81,7 @@ "lodash": "^4.17.13", "mustache": "^4.0.1", "node-fetch": "^2.6.0", + "open": "^7.3.0", "pino-pretty": "^4.0.0", "pouchdb": "^7.2.1", "pouchdb-all-dbs": "^1.0.2", diff --git a/packages/server/src/electron.js b/packages/server/src/electron.js index a6fa3f5e90..1ea2fc8d9c 100644 --- a/packages/server/src/electron.js +++ b/packages/server/src/electron.js @@ -7,6 +7,7 @@ const { existsSync } = require("fs-extra") const initialiseBudibase = require("./utilities/initialiseBudibase") const { budibaseAppsDir } = require("./utilities/budibaseDir") const { openNewGitHubIssue, debugInfo } = require("electron-util") +const open = require("open") const budibaseDir = budibaseAppsDir() const envFile = join(budibaseDir, ".env") @@ -41,7 +42,7 @@ async function startApp() { function handleRedirect(e, url) { e.preventDefault() - shell.openExternal(url) + open(url) } async function createWindow() { diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 9e6671405c..ef8f515468 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -3946,6 +3946,11 @@ is-descriptor@^1.0.0, is-descriptor@^1.0.2: is-data-descriptor "^1.0.0" kind-of "^6.0.2" +is-docker@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.1.1.tgz#4125a88e44e450d384e09047ede71adc2d144156" + integrity sha512-ZOoqiXfEwtGknTiuDEy8pN2CfE3TxMHprvNer1mXiqwkOT77Rw3YVrUQ52EqAOU3QAWDQ+bQdx7HJzrv7LS2Hw== + is-extendable@^0.1.0, is-extendable@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" @@ -4150,6 +4155,13 @@ is-wsl@^1.1.0: resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d" integrity sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0= +is-wsl@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" + integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== + dependencies: + is-docker "^2.0.0" + is-yarn-global@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/is-yarn-global/-/is-yarn-global-0.3.0.tgz#d502d3382590ea3004893746754c89139973e232" @@ -5784,6 +5796,14 @@ only@~0.0.2: resolved "https://registry.yarnpkg.com/only/-/only-0.0.2.tgz#2afde84d03e50b9a8edc444e30610a70295edfb4" integrity sha1-Kv3oTQPlC5qO3EROMGEKcCle37Q= +open@^7.3.0: + version "7.3.0" + resolved "https://registry.yarnpkg.com/open/-/open-7.3.0.tgz#45461fdee46444f3645b6e14eb3ca94b82e1be69" + integrity sha512-mgLwQIx2F/ye9SmbrUkurZCnkoXyXyu9EbHtJZrICjVAJfyMArdHp3KkixGdZx1ZHFPNIwl0DDM1dFFqXbTLZw== + dependencies: + is-docker "^2.0.0" + is-wsl "^2.1.1" + optionator@^0.8.1, optionator@^0.8.3: version "0.8.3" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495" From 327f77dbb31714c7e7321e8c5c4a9585c9ca3fd0 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 24 Nov 2020 14:04:14 +0000 Subject: [PATCH 02/13] user table and relationships complete --- .../DataTable/modals/CreateEditColumn.svelte | 13 ++++++-- .../TableNavigator/TableNavigator.svelte | 3 +- .../components/settings/SettingsModal.svelte | 5 +++ packages/builder/src/constants/index.js | 7 ++++ .../src/pages/[application]/_reset.svelte | 7 +--- .../data/table/users/index.svelte | 1 + .../server/src/api/controllers/application.js | 33 +++++++++++++++++++ packages/server/src/api/controllers/user.js | 3 +- packages/server/src/db/client.js | 2 +- packages/server/src/db/utils.js | 14 ++++---- packages/server/src/electron.js | 3 +- 11 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 packages/builder/src/pages/[application]/data/table/users/index.svelte diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 866e574bca..9c8e985ffd 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -2,6 +2,7 @@ import { Input, Button, TextButton, Select, Toggle } from "@budibase/bbui" import { cloneDeep } from "lodash/fp" import { backendUiStore } from "builderStore" + import { TableNames, UNEDITABLE_USER_FIELDS } from "constants" import { FIELDS } from "constants/backend" import { notifier } from "builderStore/store/notifications" import ValuesList from "components/common/ValuesList.svelte" @@ -30,6 +31,12 @@ table => table._id !== $backendUiStore.draftTable._id ) $: required = !!field?.constraints?.presence || primaryDisplay + $: uneditable = $backendUiStore.selectedTable?._id === TableNames.USERS && UNEDITABLE_USER_FIELDS.includes(field.name) + $: { + console.log($backendUiStore.selectedTable) + console.log(field.name) + console.log(uneditable) + } async function saveColumn() { backendUiStore.update(state => { @@ -87,7 +94,7 @@
- + - - {#if editMode} - - {:else} - - {/if} -
- - diff --git a/packages/builder/src/components/settings/tabs/Users.svelte b/packages/builder/src/components/settings/tabs/Users.svelte deleted file mode 100644 index 9ef5a86235..0000000000 --- a/packages/builder/src/components/settings/tabs/Users.svelte +++ /dev/null @@ -1,113 +0,0 @@ - - -
-
- -
- - - - -
-
-
- - {#await fetchUsersPromise} - Loading... - {:then users} -
    - {#each users as user} -
  • - -
  • - {:else} -
  • No Users found
  • - {/each} -
- {:catch err} - Something went wrong when trying to fetch users. Please refresh (CMD + R / - CTRL + R) the page and try again. - {/await} -
-
- - diff --git a/packages/server/src/api/controllers/user.js b/packages/server/src/api/controllers/user.js index 0be16c32bc..f67ae72a89 100644 --- a/packages/server/src/api/controllers/user.js +++ b/packages/server/src/api/controllers/user.js @@ -11,7 +11,7 @@ const { exports.fetch = async function(ctx) { const database = new CouchDB(ctx.user.appId) const data = await database.allDocs( - getUserParams(null, { + getUserParams("", { include_docs: true, }) ) diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js index 767e892c17..96fd92218e 100644 --- a/packages/server/src/db/utils.js +++ b/packages/server/src/db/utils.js @@ -101,8 +101,12 @@ exports.generateRowID = tableId => { /** * Gets parameters for retrieving users, this is a utility function for the getDocParams function. */ -exports.getUserParams = (username = null, otherProps = {}) => { - return getDocParams(DocumentTypes.USER, username, otherProps) +exports.getUserParams = (username = "", otherProps = {}) => { + return getDocParams( + DocumentTypes.ROW, + `${ViewNames.USERS}${SEPARATOR}${DocumentTypes.USER}${SEPARATOR}${username}`, + otherProps + ) } /** From 792eac2ca5137f06789e419ac78f8e922b4d5067 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 25 Nov 2020 16:27:49 +0000 Subject: [PATCH 08/13] fix filepath issue --- packages/builder/src/components/settings/tabs/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/builder/src/components/settings/tabs/index.js b/packages/builder/src/components/settings/tabs/index.js index 6e34141d09..2f0e958112 100644 --- a/packages/builder/src/components/settings/tabs/index.js +++ b/packages/builder/src/components/settings/tabs/index.js @@ -1,6 +1,5 @@ export { default as General } from "./General.svelte" export { default as Integrations } from "./Integrations.svelte" export { default as Permissions } from "./Permissions.svelte" -export { default as Users } from "./Users.svelte" export { default as APIKeys } from "./APIKeys.svelte" export { default as DangerZone } from "./DangerZone.svelte" From 1014437d42f40a65a53b63e59da534dcabcfdd55 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 27 Nov 2020 13:17:31 +0000 Subject: [PATCH 09/13] fix user test --- .../cypress/integration/createUser.spec.js | 4 +-- packages/builder/cypress/support/commands.js | 31 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/builder/cypress/integration/createUser.spec.js b/packages/builder/cypress/integration/createUser.spec.js index ca2fa225da..cbde6179b2 100644 --- a/packages/builder/cypress/integration/createUser.spec.js +++ b/packages/builder/cypress/integration/createUser.spec.js @@ -9,9 +9,9 @@ context('Create a User', () => { // https://on.cypress.io/interacting-with-elements it('should create a user', () => { - cy.addRow(["Users", "bbuser", "test", "POWER_USER"]) + cy.createUser("bbuser", "test", "ADMIN") // // Check to make sure user was created! - // cy.get("input[disabled]").should('have.value', 'bbuser') + cy.contains("bbuser").should('be.visible') }) }) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 15564083ba..76f3417eac 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -113,23 +113,26 @@ Cypress.Commands.add("addRow", values => { Cypress.Commands.add("createUser", (username, password, accessLevel) => { // Create User - cy.get(".toprightnav > .settings").click() cy.contains("Users").click() - cy.get("[name=Name]") - .first() - .type(username) - cy.get("[name=Password]") - .first() - .type(password) - cy.get("select") - .first() - .select(accessLevel) + cy.contains("Create New Row").click() - // Save - cy.get(".inputs") - .contains("Create") - .click() + cy.get(".modal").within(() => { + cy.get("input") + .first() + .type(password) + cy.get("input") + .eq(1) + .type(username) + cy.get("select") + .first() + .select(accessLevel) + + // Save + cy.get(".buttons") + .contains("Create Row") + .click() + }) }) Cypress.Commands.add("addHeadlineComponent", text => { From f38e701d3821360a0c2a4068b7d24ca9ac1bb84d Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 27 Nov 2020 14:36:36 +0000 Subject: [PATCH 10/13] fix tests --- packages/builder/cypress/integration/createTable.spec.js | 2 +- .../backend/TableNavigator/popovers/EditTablePopover.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/builder/cypress/integration/createTable.spec.js b/packages/builder/cypress/integration/createTable.spec.js index fdad39b956..27560aaeb9 100644 --- a/packages/builder/cypress/integration/createTable.spec.js +++ b/packages/builder/cypress/integration/createTable.spec.js @@ -60,7 +60,7 @@ context("Create a Table", () => { }) it("deletes a table", () => { - cy.contains(".nav-item", "dog").get(".actions").invoke("show").click() + cy.get(".actions").first().invoke("show").click() cy.get("[data-cy=delete-table]").click() cy.contains("Delete Table").click() cy.contains("dog").should("not.exist") diff --git a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte index 1fdbe35151..3aba583ccb 100644 --- a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte +++ b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte @@ -39,7 +39,7 @@ async function deleteTable() { await backendUiStore.actions.tables.delete(table) - store.store.actions.screens.delete(templateScreens) + store.actions.screens.delete(templateScreens) await backendUiStore.actions.tables.fetch() notifier.success("Table deleted") hideEditor() From 88a61b3b723d61b4809e2e496f267d154924d40c Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 27 Nov 2020 14:59:27 +0000 Subject: [PATCH 11/13] prevent username changing --- .../backend/DataTable/RowFieldControl.svelte | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte b/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte index f974e521c4..f18c81afc7 100644 --- a/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte +++ b/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte @@ -1,5 +1,7 @@ {#if type === 'options'} @@ -30,5 +33,11 @@ {:else if type === 'link'} {:else} - + {/if} From b4440abdd60e6cd78ccc22222b2ab23998d6ffb3 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 27 Nov 2020 15:24:43 +0000 Subject: [PATCH 12/13] allow creation of username --- .../src/components/backend/DataTable/RowFieldControl.svelte | 6 ++++-- .../backend/DataTable/modals/CreateEditRowModal.svelte | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte b/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte index f18c81afc7..c21d3449b6 100644 --- a/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte +++ b/packages/builder/src/components/backend/DataTable/RowFieldControl.svelte @@ -7,11 +7,13 @@ import LinkedRowSelector from "components/common/LinkedRowSelector.svelte" export let meta + export let creating export let value = meta.type === "boolean" ? false : "" $: type = meta.type $: label = capitalise(meta.name) - $: userTableSelected = $backendUiStore.selectedTable?._id === TableNames.USERS + $: editingUser = + !creating && $backendUiStore.selectedTable?._id === TableNames.USERS {#if type === 'options'} @@ -39,5 +41,5 @@ data-cy="{meta.name}-input" {type} bind:value - disabled={userTableSelected} /> + disabled={editingUser} /> {/if} diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditRowModal.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditRowModal.svelte index 460c04428e..c4b8888cd2 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditRowModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditRowModal.svelte @@ -47,7 +47,7 @@ {/if} {#each tableSchema as [key, meta]}
- +
{/each} From e14d2517f4f54f6519a604c5e57e2210f4b41f3e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 27 Nov 2020 15:33:32 +0000 Subject: [PATCH 13/13] allow password creation --- .../backend/DataTable/modals/CreateEditRowModal.svelte | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditRowModal.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditRowModal.svelte index c4b8888cd2..e99c5762d8 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditRowModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditRowModal.svelte @@ -42,6 +42,7 @@ {#if creating && table._id === TableNames.USERS} {/if}