From c0c81a05743d684011dd41d6343fbef5db5ec77b Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Thu, 25 Jan 2024 08:26:02 -0800 Subject: [PATCH 01/16] Identity Provider from hardcode to config Signed-off-by: Jason Sherman --- .devcontainer/README.md | 33 +++++ .devcontainer/devcontainer.json | 25 ++++ .devcontainer/post-install.sh | 2 + .vscode/launch.json | 4 +- .vscode/tasks.json | 6 +- .../src/components/base/BaseSecure.vue | 14 ++- .../src/components/base/BaseStepper.vue | 9 +- .../src/components/bcgov/BCGovNavBar.vue | 5 +- .../src/components/designer/FormsTable.vue | 5 +- .../designer/settings/FormAccessSettings.vue | 34 ++--- .../settings/FormFunctionalitySettings.vue | 10 +- .../components/forms/manage/AddTeamMember.vue | 68 +++++----- .../forms/manage/TeamManagement.vue | 21 +--- .../submission/ManageSubmissionUsers.vue | 49 ++++---- app/frontend/src/main.js | 26 ++++ app/frontend/src/router.js | 28 +++-- app/frontend/src/services/rbacService.js | 8 ++ app/frontend/src/store/auth.js | 4 +- app/frontend/src/store/identityProviders.js | 114 +++++++++++++++++ app/frontend/src/utils/constants.js | 22 ++-- app/frontend/src/utils/permissionUtils.js | 11 +- app/frontend/src/views/Admin.vue | 6 +- app/frontend/src/views/Login.vue | 38 ++---- app/frontend/src/views/file/Download.vue | 6 +- app/frontend/src/views/form/Create.vue | 3 +- app/frontend/src/views/form/Emails.vue | 6 +- app/frontend/src/views/form/Export.vue | 6 +- app/frontend/src/views/form/Manage.vue | 6 +- app/frontend/src/views/form/Preview.vue | 6 +- app/frontend/src/views/form/Submissions.vue | 6 +- app/frontend/src/views/form/Teams.vue | 6 +- app/frontend/src/views/form/View.vue | 6 +- app/frontend/src/views/user/Submissions.vue | 6 +- ...119172630_identity_provider_permissions.js | 118 ++++++++++++++++++ app/src/forms/common/constants.js | 17 +++ .../common/models/tables/identityProvider.js | 7 +- 36 files changed, 534 insertions(+), 207 deletions(-) create mode 100644 app/frontend/src/store/identityProviders.js create mode 100644 app/src/db/migrations/20240119172630_identity_provider_permissions.js diff --git a/.devcontainer/README.md b/.devcontainer/README.md index fc50bfc97..1bc39036b 100644 --- a/.devcontainer/README.md +++ b/.devcontainer/README.md @@ -15,6 +15,8 @@ The `.devcontainer` folder contains the `devcontainer.json` file which defines t In order to run CHEFS you require Keycloak (configured), Postgresql (seeded) and the CHEFS backend/API and frontend/UX. Previously, this was a series of downloads and configuration updates and numerous commands to run. See `.devcontainer/chefs_local` files. +**NODE_CONFIG_DIR** to simplify loading a default configuration to the CHEFS infrastructure (Keycloak, Postgresql, etc), we set an environment variable [`NODE_CONFIG_DIR`](https://github.com/node-config/node-config/wiki/Environment-Variables#node_config_dir). This supercedes the files found under `app/config`. Running node apps and commands (ex. knex, launch configurations) will use this environment variable and load configuration from `.devcontainer/chefs_local`. + Also included are convenient launch tasks to run and debug CHEFS. ## Open CHEFS in the devcontainer @@ -65,6 +67,37 @@ When the devcontainer is built, it copies `.devcontainer/chefs_local/local.json. ## Formio Components If you are developing the formio components, you should build and redeploy them before running your local debug instances of CHEFS. Use tasks `Components build` and `Components Deploy`. +## KNEX - Database tools +[knex](https://knexjs.org) is installed globally and should be run from the `/app` directory where the knex configuration is located. Use knex to stub out migrations or to rollback migrations as you are developing. + +### create a migration file +This will create a stub file with a timestamp. You will populate the up and down methods to add/update/delete database objects. + +``` +cd app +knex migrate:make my_new_migration_script +> Created Migration: /workspaces/common-hosted-form-service/app/src/db/migrations/20240119172630_my_new_migration_script.js +``` + +### rollback previous migration +When developing your migrations, you may find it useful to run the migration and roll it back if it isn't exactly what you expect to happen. + +#### run the migration(s) +``` +cd app +knex migrate:latest +> Batch 2 run: 1 migrations +``` + +#### rollback the migration(s) +``` +cd app +knex migrate:rollback +> Batch 2 rolled back: 1 migrations +``` + +Please review the [knex](https://knexjs.org) for more detail and how to leverage the tool. + ## Troubleshooting All development machines are unique and here we will document problems that have been encountered and how to fix them. diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 84375ad6d..7d7b8355f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,10 +10,35 @@ } }, + "customizations": { + "vscode": { + "extensions": [ + "cweijan.vscode-postgresql-client2", + "Vue.volar", + "esbenp.prettier-vscode" + ], + "settings": { + "database-client.telemetry.usesOnlineServices": false, + "editor.defaultFormatter": null, + "editor.formatOnSave": false, + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "prettier.configPath": "${containerWorkspaceFolder}/app/frontend/.prettierrc", + "prettier.documentSelectors": ["${containerWorkspaceFolder}/app/frontend/**/*.{js,vue}"] + } + } + }, + "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {} }, + "containerEnv": { + "NODE_CONFIG_DIR": "${containerWorkspaceFolder}/.devcontainer/chefs_local" + }, + // Use this environment variable if you need to bind mount your local source code into a new container. "remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" diff --git a/.devcontainer/post-install.sh b/.devcontainer/post-install.sh index c6d2ea823..891641159 100644 --- a/.devcontainer/post-install.sh +++ b/.devcontainer/post-install.sh @@ -5,6 +5,8 @@ set -ex WORKSPACE_DIR=$(pwd) CHEFS_LOCAL_DIR=${WORKSPACE_DIR}/.devcontainer/chefs_local +npm install knex -g + # install app libraries, prepare for app development and debugging... cd app npm install diff --git a/.vscode/launch.json b/.vscode/launch.json index 95afba61f..9f576b64a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,9 +14,7 @@ "runtimeArgs": ["run", "serve"], "runtimeExecutable": "npm", "type": "node", - "env": { - "NODE_CONFIG_DIR": "${workspaceFolder}/.devcontainer/chefs_local", - } + "env": {} }, { "cwd": "${workspaceFolder}/app/frontend", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 85aa0490c..de14b394e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -62,14 +62,16 @@ { "label": "chefs_local up", "type": "shell", - "command": "docker-compose -f ${workspaceFolder}/.devcontainer/chefs_local/docker-compose.yml up -d", + "command": "docker-compose", + "args": ["-f", "${workspaceFolder}/.devcontainer/chefs_local/docker-compose.yml", "up", "-d"], "isBackground": true, "problemMatcher": [], }, { "label": "chefs_local down", "type": "shell", - "command": "docker-compose -f ${workspaceFolder}/.devcontainer/chefs_local/docker-compose.yml down", + "command": "docker-compose", + "args": ["-f", "${workspaceFolder}/.devcontainer/chefs_local/docker-compose.yml", "down"], "isBackground": true, "problemMatcher": [], }, diff --git a/app/frontend/src/components/base/BaseSecure.vue b/app/frontend/src/components/base/BaseSecure.vue index 0a27df9e3..30da86712 100755 --- a/app/frontend/src/components/base/BaseSecure.vue +++ b/app/frontend/src/components/base/BaseSecure.vue @@ -2,6 +2,7 @@ import { mapActions, mapState } from 'pinia'; import { useAuthStore } from '~/store/auth'; import { useFormStore } from '~/store/form'; +import { useIdpStore } from '~/store/identityProviders'; export default { props: { @@ -13,6 +14,10 @@ export default { type: Array, default: undefined, }, + permission: { + type: String, + default: undefined, + }, }, computed: { ...mapState(useAuthStore, [ @@ -23,6 +28,7 @@ export default { 'ready', ]), ...mapState(useFormStore, ['lang']), + ...mapState(useIdpStore, ['hasPermission']), mailToLink() { return `mailto:${ import.meta.env.VITE_CONTACT @@ -34,7 +40,9 @@ export default { return import.meta.env.VITE_CONTACT; }, }, - methods: mapActions(useAuthStore, ['login']), + methods: { + ...mapActions(useAuthStore, ['login']), + }, }; @@ -50,7 +58,7 @@ export default {

@@ -59,7 +67,7 @@ export default {

{{ $t('trans.baseSecure.403ErrorMsg', { - idp: idp, + idp: permission, }) }}

diff --git a/app/frontend/src/components/base/BaseStepper.vue b/app/frontend/src/components/base/BaseStepper.vue index df720f53c..c50f81251 100644 --- a/app/frontend/src/components/base/BaseStepper.vue +++ b/app/frontend/src/components/base/BaseStepper.vue @@ -2,7 +2,7 @@ import { mapState } from 'pinia'; import BaseSecure from '~/components/base/BaseSecure.vue'; import { useFormStore } from '~/store/form'; -import { IdentityProviders } from '~/utils/constants'; +import { AppPermissions } from '~/utils/constants'; export default { name: 'BaseStepper', @@ -17,7 +17,7 @@ export default { }, computed: { ...mapState(useFormStore, ['lang', 'isRTL']), - IDP: () => IdentityProviders, + APP_PERMS: () => AppPermissions, creatorStep() { return this.step; }, @@ -26,7 +26,10 @@ export default {