@budibase/server 1.0.49-alpha.1 → 1.0.49-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mocks__/arangojs.ts +1 -1
- package/__mocks__/aws-sdk.ts +4 -4
- package/__mocks__/mongodb.ts +4 -5
- package/__mocks__/mssql.ts +3 -3
- package/__mocks__/node-fetch.ts +2 -1
- package/__mocks__/pg.ts +3 -5
- package/builder/assets/{index.ba78c49d.css → index.83c0944f.css} +1 -1
- package/builder/assets/{index.ed1cf508.js → index.f686d3cd.js} +184 -184
- package/builder/index.html +2 -2
- package/coverage/clover.xml +2656 -2712
- package/coverage/coverage-final.json +104 -105
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +157 -136
- package/coverage/lcov-report/api/controllers/auth.js.html +11 -14
- package/coverage/lcov-report/api/controllers/automation.js.html +39 -69
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +8 -11
- package/coverage/lcov-report/api/controllers/component.js.html +10 -13
- package/coverage/lcov-report/api/controllers/datasource.js.html +31 -37
- package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
- package/coverage/lcov-report/api/controllers/index.html +69 -54
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
- package/coverage/lcov-report/api/controllers/metadata.js.html +6 -21
- package/coverage/lcov-report/{migrations/usageQuotas/syncApps.js.html → api/controllers/migrations.js.html} +30 -45
- package/coverage/lcov-report/api/controllers/permission.js.html +19 -19
- package/coverage/lcov-report/api/controllers/query/index.html +10 -10
- package/coverage/lcov-report/api/controllers/query/index.js.html +38 -35
- package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
- package/coverage/lcov-report/api/controllers/role.js.html +16 -16
- package/coverage/lcov-report/api/controllers/routing.js.html +7 -10
- package/coverage/lcov-report/api/controllers/row/external.js.html +48 -141
- package/coverage/lcov-report/api/controllers/row/index.html +28 -28
- package/coverage/lcov-report/api/controllers/row/index.js.html +13 -13
- package/coverage/lcov-report/api/controllers/row/internal.js.html +60 -105
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +25 -31
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +21 -24
- package/coverage/lcov-report/api/controllers/row/utils.js.html +27 -24
- package/coverage/lcov-report/api/controllers/screen.js.html +15 -21
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +27 -57
- package/coverage/lcov-report/api/controllers/table/external.js.html +25 -34
- package/coverage/lcov-report/api/controllers/table/index.html +37 -37
- package/coverage/lcov-report/api/controllers/table/index.js.html +20 -20
- package/coverage/lcov-report/api/controllers/table/internal.js.html +45 -54
- package/coverage/lcov-report/api/controllers/table/utils.js.html +67 -103
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +43 -52
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
- package/coverage/lcov-report/api/controllers/view/index.html +16 -16
- package/coverage/lcov-report/api/controllers/view/index.js.html +27 -33
- package/coverage/lcov-report/api/controllers/view/utils.js.html +35 -20
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +34 -28
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +3 -3
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +22 -7
- package/coverage/lcov-report/api/routes/index.js.html +10 -4
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/{migrations/usageQuotas/index.js.html → api/routes/migrations.js.html} +25 -55
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +24 -24
- package/coverage/lcov-report/automations/automationUtils.js.html +7 -10
- package/coverage/lcov-report/automations/bullboard.js.html +16 -16
- package/coverage/lcov-report/automations/index.html +18 -18
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
- package/coverage/lcov-report/automations/steps/createRow.js.html +7 -10
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +61 -55
- package/coverage/lcov-report/automations/utils.js.html +54 -42
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +26 -26
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/client.js.html +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +15 -27
- package/coverage/lcov-report/db/linkedRows/index.html +27 -27
- package/coverage/lcov-report/db/linkedRows/index.js.html +40 -82
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +40 -40
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +74 -74
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +5 -5
- package/coverage/lcov-report/events/utils.js.html +3 -3
- package/coverage/lcov-report/index.html +97 -112
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +21 -15
- package/coverage/lcov-report/middleware/builder.js.html +3 -3
- package/coverage/lcov-report/middleware/currentapp.js.html +72 -60
- package/coverage/lcov-report/middleware/index.html +28 -28
- package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +29 -35
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +30 -24
- package/coverage/lcov-report/threads/index.html +25 -25
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +26 -47
- package/coverage/lcov-report/threads/utils.js.html +14 -14
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
- package/coverage/lcov-report/utilities/global.js.html +57 -48
- package/coverage/lcov-report/utilities/index.html +27 -27
- package/coverage/lcov-report/utilities/index.js.html +42 -72
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +7 -7
- package/coverage/lcov-report/utilities/rowProcessor/index.html +11 -11
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +32 -74
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +13 -10
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +5 -2
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +9 -9
- package/coverage/lcov-report/utilities/workerRequests.js.html +16 -16
- package/coverage/lcov.info +4018 -4092
- package/dist/api/controllers/application.js +49 -48
- package/dist/api/controllers/auth.js +4 -5
- package/dist/api/controllers/automation.js +14 -19
- package/dist/api/controllers/cloud.js +2 -3
- package/dist/api/controllers/component.js +3 -4
- package/dist/api/controllers/datasource.js +9 -10
- package/dist/api/controllers/deploy/Deployment.js +3 -6
- package/dist/api/controllers/deploy/index.js +12 -13
- package/dist/api/controllers/dev.js +5 -5
- package/dist/api/controllers/layout.js +3 -3
- package/dist/api/controllers/metadata.js +4 -4
- package/dist/api/controllers/migrations.js +21 -0
- package/dist/api/controllers/permission.js +4 -4
- package/dist/api/controllers/query/import/index.js +4 -6
- package/dist/api/controllers/query/index.js +11 -10
- package/dist/api/controllers/role.js +5 -5
- package/dist/api/controllers/routing.js +5 -6
- package/dist/api/controllers/row/ExternalRequest.js +90 -67
- package/dist/api/controllers/row/external.js +14 -22
- package/dist/api/controllers/row/internal.js +29 -44
- package/dist/api/controllers/row/internalSearch.js +11 -13
- package/dist/api/controllers/row/staticFormula.js +11 -11
- package/dist/api/controllers/row/utils.js +7 -6
- package/dist/api/controllers/screen.js +5 -7
- package/dist/api/controllers/static/index.js +4 -4
- package/dist/api/controllers/table/bulkFormula.js +14 -15
- package/dist/api/controllers/table/external.js +7 -10
- package/dist/api/controllers/table/index.js +5 -5
- package/dist/api/controllers/table/internal.js +16 -19
- package/dist/api/controllers/table/utils.js +29 -31
- package/dist/api/controllers/user.js +16 -20
- package/dist/api/controllers/view/index.js +8 -10
- package/dist/api/controllers/view/utils.js +9 -4
- package/dist/api/controllers/webhook.js +10 -8
- package/dist/api/routes/index.js +2 -0
- package/dist/api/routes/migrations.js +9 -0
- package/dist/api/routes/tests/utilities/TestFunctions.js +37 -17
- package/dist/app.js +35 -5
- package/dist/automations/automationUtils.js +2 -3
- package/dist/automations/steps/createRow.js +1 -1
- package/dist/automations/steps/updateRow.js +1 -1
- package/dist/automations/triggers.js +27 -25
- package/dist/automations/utils.js +10 -5
- package/dist/db/linkedRows/LinkController.js +3 -7
- package/dist/db/linkedRows/index.js +16 -26
- package/dist/db/linkedRows/linkUtils.js +6 -6
- package/dist/db/views/staticViews.js +9 -10
- package/dist/environment.js +3 -1
- package/dist/integrations/base/sql.js +49 -15
- package/dist/integrations/utils.js +3 -0
- package/dist/middleware/authorized.js +5 -3
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +41 -37
- package/dist/middleware/usageQuota.js +2 -4
- package/dist/migrations/functions/appUrls.js +46 -0
- package/dist/migrations/functions/quotas1.js +50 -0
- package/dist/migrations/{usageQuotas → functions/usageQuotas}/index.js +6 -10
- package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncApps.js +12 -9
- package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncRows.js +16 -12
- package/dist/migrations/functions/userEmailViewCasing.js +24 -0
- package/dist/migrations/index.js +62 -0
- package/dist/package.json +4 -4
- package/dist/tests/utilities/TestConfiguration.js +70 -44
- package/dist/threads/automation.js +13 -11
- package/dist/threads/query.js +13 -19
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +4 -3
- package/dist/utilities/global.js +15 -12
- package/dist/utilities/index.js +7 -17
- package/dist/utilities/routing/index.js +5 -5
- package/dist/utilities/rowProcessor/index.js +9 -10
- package/dist/utilities/usageQuota/index.js +1 -0
- package/dist/utilities/usageQuota/rows.js +1 -0
- package/dist/utilities/users.js +3 -3
- package/dist/utilities/workerRequests.js +4 -4
- package/package.json +5 -5
- package/scripts/integrations/mssql/data/Dockerfile +1 -1
- package/scripts/integrations/mssql/data/setup.sql +17 -4
- package/scripts/integrations/postgres/init.sql +11 -6
- package/scripts/likeCypress.ts +1 -1
- package/src/api/controllers/application.js +38 -31
- package/src/api/controllers/auth.js +4 -5
- package/src/api/controllers/automation.js +13 -23
- package/src/api/controllers/cloud.js +2 -3
- package/src/api/controllers/component.js +3 -4
- package/src/api/controllers/datasource.js +9 -11
- package/src/api/controllers/deploy/Deployment.js +3 -7
- package/src/api/controllers/deploy/index.js +20 -13
- package/src/api/controllers/dev.js +5 -5
- package/src/api/controllers/layout.js +3 -3
- package/src/api/controllers/metadata.js +4 -9
- package/src/api/controllers/migrations.js +13 -0
- package/src/api/controllers/permission.js +4 -4
- package/src/api/controllers/query/import/index.ts +4 -6
- package/src/api/controllers/query/import/tests/index.spec.js +2 -1
- package/src/api/controllers/query/index.js +11 -10
- package/src/api/controllers/role.js +5 -5
- package/src/api/controllers/routing.js +5 -6
- package/src/api/controllers/row/ExternalRequest.ts +67 -43
- package/src/api/controllers/row/external.js +27 -58
- package/src/api/controllers/row/internal.js +29 -44
- package/src/api/controllers/row/internalSearch.js +11 -13
- package/src/api/controllers/row/staticFormula.js +10 -11
- package/src/api/controllers/row/utils.js +7 -6
- package/src/api/controllers/screen.js +5 -7
- package/src/api/controllers/static/index.js +4 -4
- package/src/api/controllers/table/bulkFormula.js +13 -23
- package/src/api/controllers/table/external.js +7 -10
- package/src/api/controllers/table/index.js +5 -5
- package/src/api/controllers/table/internal.js +18 -21
- package/src/api/controllers/table/utils.js +29 -41
- package/src/api/controllers/user.js +17 -20
- package/src/api/controllers/view/index.js +8 -10
- package/src/api/controllers/view/utils.js +9 -4
- package/src/api/controllers/webhook.js +10 -8
- package/src/api/routes/index.js +2 -0
- package/src/api/routes/migrations.js +14 -0
- package/src/api/routes/tests/automation.spec.js +1 -0
- package/src/api/routes/tests/misc.spec.js +0 -1
- package/src/api/routes/tests/routing.spec.js +21 -12
- package/src/api/routes/tests/row.spec.js +7 -4
- package/src/api/routes/tests/utilities/TestFunctions.js +39 -17
- package/src/app.ts +18 -5
- package/src/automations/automationUtils.js +2 -3
- package/src/automations/steps/createRow.js +0 -1
- package/src/automations/steps/updateRow.js +1 -1
- package/src/automations/triggers.js +33 -31
- package/src/automations/utils.js +9 -5
- package/src/db/linkedRows/LinkController.js +3 -7
- package/src/db/linkedRows/index.js +16 -30
- package/src/db/linkedRows/linkUtils.js +6 -6
- package/src/db/tests/linkController.spec.js +0 -1
- package/src/db/tests/linkTests.spec.js +5 -6
- package/src/db/views/staticViews.js +8 -10
- package/src/environment.js +3 -1
- package/src/integrations/base/sql.ts +61 -22
- package/src/integrations/utils.ts +4 -1
- package/src/middleware/authorized.js +5 -3
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +50 -46
- package/src/middleware/tests/authorized.spec.js +7 -2
- package/src/middleware/tests/currentapp.spec.js +6 -0
- package/src/middleware/usageQuota.js +2 -4
- package/src/migrations/functions/appUrls.ts +34 -0
- package/src/migrations/functions/quotas1.ts +20 -0
- package/src/migrations/functions/tests/appUrls.spec.js +29 -0
- package/src/migrations/{tests/usageQuotas/index.spec.js → functions/tests/quotas1.spec.js} +5 -5
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
- package/src/migrations/functions/usageQuotas/index.ts +8 -0
- package/src/migrations/{usageQuotas/syncApps.js → functions/usageQuotas/syncApps.ts} +6 -6
- package/src/migrations/functions/usageQuotas/syncRows.ts +22 -0
- package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncApps.spec.js +4 -4
- package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncRows.spec.js +4 -4
- package/src/migrations/functions/userEmailViewCasing.ts +13 -0
- package/src/migrations/index.ts +56 -0
- package/src/module.d.ts +3 -0
- package/src/tests/utilities/TestConfiguration.js +73 -50
- package/src/threads/automation.js +17 -15
- package/src/threads/query.js +14 -21
- package/src/utilities/fileSystem/index.js +4 -3
- package/src/utilities/global.js +15 -12
- package/src/utilities/index.js +7 -17
- package/src/utilities/routing/index.js +5 -5
- package/src/utilities/rowProcessor/index.js +9 -23
- package/src/utilities/usageQuota/index.js +1 -0
- package/src/utilities/usageQuota/rows.js +1 -0
- package/src/utilities/users.js +3 -3
- package/src/utilities/workerRequests.js +4 -4
- package/tsconfig.json +2 -1
- package/coverage/lcov-report/migrations/usageQuotas/index.html +0 -141
- package/coverage/lcov-report/migrations/usageQuotas/syncRows.js.html +0 -143
- package/src/migrations/usageQuotas/index.js +0 -24
- package/src/migrations/usageQuotas/syncRows.js +0 -21
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const CouchDB = require("../index")
|
|
2
1
|
const Sentry = require("@sentry/node")
|
|
3
2
|
const { ViewNames, getQueryIndex } = require("../utils")
|
|
4
3
|
const { FieldTypes } = require("../../constants")
|
|
5
4
|
const { createLinkView } = require("../views/staticViews")
|
|
5
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Only needed so that boolean parameters are being used for includeDocs
|
|
@@ -17,7 +17,6 @@ exports.createLinkView = createLinkView
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Gets the linking documents, not the linked documents themselves.
|
|
20
|
-
* @param {string} args.appId The instance in which we are searching for linked rows.
|
|
21
20
|
* @param {string} args.tableId The table which we are searching for linked rows against.
|
|
22
21
|
* @param {string|null} args.fieldName The name of column/field which is being altered, only looking for
|
|
23
22
|
* linking documents that are related to it. If this is not specified then the table level will be assumed.
|
|
@@ -30,8 +29,8 @@ exports.createLinkView = createLinkView
|
|
|
30
29
|
* (if any).
|
|
31
30
|
*/
|
|
32
31
|
exports.getLinkDocuments = async function (args) {
|
|
33
|
-
const {
|
|
34
|
-
const db =
|
|
32
|
+
const { tableId, rowId, includeDocs } = args
|
|
33
|
+
const db = getAppDB()
|
|
35
34
|
let params
|
|
36
35
|
if (rowId != null) {
|
|
37
36
|
params = { key: [tableId, rowId] }
|
|
@@ -68,7 +67,7 @@ exports.getLinkDocuments = async function (args) {
|
|
|
68
67
|
} catch (err) {
|
|
69
68
|
// check if the view doesn't exist, it should for all new instances
|
|
70
69
|
if (err != null && err.name === "not_found") {
|
|
71
|
-
await exports.createLinkView(
|
|
70
|
+
await exports.createLinkView()
|
|
72
71
|
return exports.getLinkDocuments(arguments[0])
|
|
73
72
|
} else {
|
|
74
73
|
/* istanbul ignore next */
|
|
@@ -89,7 +88,8 @@ exports.getLinkedTableIDs = table => {
|
|
|
89
88
|
.map(column => column.tableId)
|
|
90
89
|
}
|
|
91
90
|
|
|
92
|
-
exports.getLinkedTable = async (
|
|
91
|
+
exports.getLinkedTable = async (id, tables) => {
|
|
92
|
+
const db = getAppDB()
|
|
93
93
|
let linkedTable = tables.find(table => table._id === id)
|
|
94
94
|
if (linkedTable) {
|
|
95
95
|
return linkedTable
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const TestConfig = require("../../tests/utilities/TestConfiguration")
|
|
2
|
-
const { basicTable
|
|
2
|
+
const { basicTable } = require("../../tests/utilities/structures")
|
|
3
3
|
const linkUtils = require("../linkedRows/linkUtils")
|
|
4
|
-
const links = require("../linkedRows")
|
|
5
4
|
const CouchDB = require("../index")
|
|
5
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
6
6
|
|
|
7
7
|
describe("test link functionality", () => {
|
|
8
8
|
const config = new TestConfig(false)
|
|
@@ -11,18 +11,18 @@ describe("test link functionality", () => {
|
|
|
11
11
|
let db, table
|
|
12
12
|
beforeEach(async () => {
|
|
13
13
|
await config.init()
|
|
14
|
-
db =
|
|
14
|
+
db = getAppDB()
|
|
15
15
|
table = await config.createTable()
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
it("should be able to retrieve a linked table from a list", async () => {
|
|
19
|
-
const retrieved = await linkUtils.getLinkedTable(
|
|
19
|
+
const retrieved = await linkUtils.getLinkedTable(table._id, [table])
|
|
20
20
|
expect(retrieved._id).toBe(table._id)
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
it("should be able to retrieve a table from DB and update list", async () => {
|
|
24
24
|
const tables = []
|
|
25
|
-
const retrieved = await linkUtils.getLinkedTable(
|
|
25
|
+
const retrieved = await linkUtils.getLinkedTable(table._id, tables)
|
|
26
26
|
expect(retrieved._id).toBe(table._id)
|
|
27
27
|
expect(tables[0]).toBeDefined()
|
|
28
28
|
})
|
|
@@ -51,7 +51,6 @@ describe("test link functionality", () => {
|
|
|
51
51
|
const db = new CouchDB("test")
|
|
52
52
|
await db.put({ _id: "_design/database", views: {} })
|
|
53
53
|
const output = await linkUtils.getLinkDocuments({
|
|
54
|
-
appId: "test",
|
|
55
54
|
tableId: "test",
|
|
56
55
|
rowId: "test",
|
|
57
56
|
includeDocs: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
2
2
|
const {
|
|
3
3
|
DocumentTypes,
|
|
4
4
|
SEPARATOR,
|
|
@@ -21,12 +21,11 @@ const SCREEN_PREFIX = DocumentTypes.SCREEN + SEPARATOR
|
|
|
21
21
|
/**
|
|
22
22
|
* Creates the link view for the instance, this will overwrite the existing one, but this should only
|
|
23
23
|
* be called if it is found that the view does not exist.
|
|
24
|
-
* @param {string} appId The instance to which the view should be added.
|
|
25
24
|
* @returns {Promise<void>} The view now exists, please note that the next view of this query will actually build it,
|
|
26
25
|
* so it may be slow.
|
|
27
26
|
*/
|
|
28
|
-
exports.createLinkView = async
|
|
29
|
-
const db =
|
|
27
|
+
exports.createLinkView = async () => {
|
|
28
|
+
const db = getAppDB()
|
|
30
29
|
const designDoc = await db.get("_design/database")
|
|
31
30
|
const view = {
|
|
32
31
|
map: function (doc) {
|
|
@@ -57,8 +56,8 @@ exports.createLinkView = async appId => {
|
|
|
57
56
|
await db.put(designDoc)
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
exports.createRoutingView = async
|
|
61
|
-
const db =
|
|
59
|
+
exports.createRoutingView = async () => {
|
|
60
|
+
const db = getAppDB()
|
|
62
61
|
const designDoc = await db.get("_design/database")
|
|
63
62
|
const view = {
|
|
64
63
|
// if using variables in a map function need to inject them before use
|
|
@@ -78,8 +77,8 @@ exports.createRoutingView = async appId => {
|
|
|
78
77
|
await db.put(designDoc)
|
|
79
78
|
}
|
|
80
79
|
|
|
81
|
-
async function searchIndex(
|
|
82
|
-
const db =
|
|
80
|
+
async function searchIndex(indexName, fnString) {
|
|
81
|
+
const db = getAppDB()
|
|
83
82
|
const designDoc = await db.get("_design/database")
|
|
84
83
|
designDoc.indexes = {
|
|
85
84
|
[indexName]: {
|
|
@@ -90,9 +89,8 @@ async function searchIndex(appId, indexName, fnString) {
|
|
|
90
89
|
await db.put(designDoc)
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
exports.createAllSearchIndex = async
|
|
92
|
+
exports.createAllSearchIndex = async () => {
|
|
94
93
|
await searchIndex(
|
|
95
|
-
appId,
|
|
96
94
|
SearchIndexes.ROWS,
|
|
97
95
|
function (doc) {
|
|
98
96
|
function idx(input, prev) {
|
package/src/environment.js
CHANGED
|
@@ -2,7 +2,8 @@ function isTest() {
|
|
|
2
2
|
return (
|
|
3
3
|
process.env.NODE_ENV === "jest" ||
|
|
4
4
|
process.env.NODE_ENV === "cypress" ||
|
|
5
|
-
process.env.JEST_WORKER_ID != null
|
|
5
|
+
(process.env.JEST_WORKER_ID != null &&
|
|
6
|
+
process.env.JEST_WORKER_ID !== "null")
|
|
6
7
|
)
|
|
7
8
|
}
|
|
8
9
|
|
|
@@ -43,6 +44,7 @@ module.exports = {
|
|
|
43
44
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
|
44
45
|
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
|
45
46
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
|
47
|
+
HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
|
|
46
48
|
// environment
|
|
47
49
|
NODE_ENV: process.env.NODE_ENV,
|
|
48
50
|
JEST_WORKER_ID: process.env.JEST_WORKER_ID,
|
|
@@ -166,15 +166,13 @@ class InternalBuilder {
|
|
|
166
166
|
|
|
167
167
|
addSorting(query: KnexQuery, json: QueryJson): KnexQuery {
|
|
168
168
|
let { sort, paginate } = json
|
|
169
|
-
if (!sort) {
|
|
170
|
-
return query
|
|
171
|
-
}
|
|
172
169
|
const table = json.meta?.table
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
170
|
+
if (sort) {
|
|
171
|
+
for (let [key, value] of Object.entries(sort)) {
|
|
172
|
+
const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
|
|
173
|
+
query = query.orderBy(`${table?.name}.${key}`, direction)
|
|
174
|
+
}
|
|
175
|
+
} else if (this.client === SqlClients.MS_SQL && paginate?.limit) {
|
|
178
176
|
// @ts-ignore
|
|
179
177
|
query = query.orderBy(`${table?.name}.${table?.primary[0]}`)
|
|
180
178
|
}
|
|
@@ -191,29 +189,70 @@ class InternalBuilder {
|
|
|
191
189
|
if (!relationships) {
|
|
192
190
|
return query
|
|
193
191
|
}
|
|
192
|
+
const tableSets: Record<string, [any]> = {}
|
|
193
|
+
// aggregate into table sets (all the same to tables)
|
|
194
194
|
for (let relationship of relationships) {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
const keyObj: { toTable: string; throughTable: string | undefined } = {
|
|
196
|
+
toTable: relationship.tableName,
|
|
197
|
+
throughTable: undefined,
|
|
198
|
+
}
|
|
199
|
+
if (relationship.through) {
|
|
200
|
+
keyObj.throughTable = relationship.through
|
|
201
|
+
}
|
|
202
|
+
const key = JSON.stringify(keyObj)
|
|
203
|
+
if (tableSets[key]) {
|
|
204
|
+
tableSets[key].push(relationship)
|
|
205
|
+
} else {
|
|
206
|
+
tableSets[key] = [relationship]
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (let [key, relationships] of Object.entries(tableSets)) {
|
|
210
|
+
const { toTable, throughTable } = JSON.parse(key)
|
|
211
|
+
if (!throughTable) {
|
|
199
212
|
// @ts-ignore
|
|
200
|
-
query = query.
|
|
213
|
+
query = query.join(
|
|
201
214
|
toTable,
|
|
202
|
-
|
|
203
|
-
|
|
215
|
+
function () {
|
|
216
|
+
for (let relationship of relationships) {
|
|
217
|
+
const from = relationship.from,
|
|
218
|
+
to = relationship.to
|
|
219
|
+
// @ts-ignore
|
|
220
|
+
this.orOn(`${fromTable}.${from}`, "=", `${toTable}.${to}`)
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
"left"
|
|
204
224
|
)
|
|
205
225
|
} else {
|
|
206
|
-
const throughTable = relationship.through
|
|
207
|
-
const fromPrimary = relationship.fromPrimary
|
|
208
|
-
const toPrimary = relationship.toPrimary
|
|
209
226
|
query = query
|
|
210
227
|
// @ts-ignore
|
|
211
|
-
.
|
|
228
|
+
.join(
|
|
212
229
|
throughTable,
|
|
213
|
-
|
|
214
|
-
|
|
230
|
+
function () {
|
|
231
|
+
for (let relationship of relationships) {
|
|
232
|
+
const fromPrimary = relationship.fromPrimary
|
|
233
|
+
const from = relationship.from
|
|
234
|
+
// @ts-ignore
|
|
235
|
+
this.orOn(
|
|
236
|
+
`${fromTable}.${fromPrimary}`,
|
|
237
|
+
"=",
|
|
238
|
+
`${throughTable}.${from}`
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
"left"
|
|
243
|
+
)
|
|
244
|
+
.join(
|
|
245
|
+
toTable,
|
|
246
|
+
function () {
|
|
247
|
+
for (let relationship of relationships) {
|
|
248
|
+
const toPrimary = relationship.toPrimary
|
|
249
|
+
const to = relationship.to
|
|
250
|
+
// @ts-ignore
|
|
251
|
+
this.orOn(`${toTable}.${toPrimary}`, `${throughTable}.${to}`)
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
"left"
|
|
215
255
|
)
|
|
216
|
-
.leftJoin(toTable, `${toTable}.${toPrimary}`, `${throughTable}.${to}`)
|
|
217
256
|
}
|
|
218
257
|
}
|
|
219
258
|
return query.limit(BASE_LIMIT)
|
|
@@ -52,7 +52,10 @@ export function buildExternalTableId(datasourceId: string, tableName: string) {
|
|
|
52
52
|
return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}`
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
export function breakExternalTableId(tableId: string) {
|
|
55
|
+
export function breakExternalTableId(tableId: string | undefined) {
|
|
56
|
+
if (!tableId) {
|
|
57
|
+
return {}
|
|
58
|
+
}
|
|
56
59
|
const parts = tableId.split(DOUBLE_SEPARATOR)
|
|
57
60
|
let tableName = parts.pop()
|
|
58
61
|
// if they need joined
|
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
const builderMiddleware = require("./builder")
|
|
11
11
|
const { isWebhookEndpoint } = require("./utils")
|
|
12
12
|
const { buildCsrfMiddleware } = require("@budibase/backend-core/auth")
|
|
13
|
+
const { getAppId } = require("@budibase/backend-core/context")
|
|
13
14
|
|
|
14
15
|
function hasResource(ctx) {
|
|
15
16
|
return ctx.resourceId != null
|
|
@@ -45,7 +46,7 @@ const checkAuthorizedResource = async (
|
|
|
45
46
|
) => {
|
|
46
47
|
// get the user's roles
|
|
47
48
|
const roleId = ctx.roleId || BUILTIN_ROLE_IDS.PUBLIC
|
|
48
|
-
const userRoles = await getUserRoleHierarchy(
|
|
49
|
+
const userRoles = await getUserRoleHierarchy(roleId, {
|
|
49
50
|
idOnly: false,
|
|
50
51
|
})
|
|
51
52
|
const permError = "User does not have permission"
|
|
@@ -81,8 +82,9 @@ module.exports =
|
|
|
81
82
|
|
|
82
83
|
// get the resource roles
|
|
83
84
|
let resourceRoles = []
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
const appId = getAppId()
|
|
86
|
+
if (appId && hasResource(ctx)) {
|
|
87
|
+
resourceRoles = await getRequiredResourceRole(permLevel, ctx)
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
// if the resource is public, proceed
|
|
@@ -5,7 +5,7 @@ const {
|
|
|
5
5
|
checkDebounce,
|
|
6
6
|
setDebounce,
|
|
7
7
|
} = require("../utilities/redis")
|
|
8
|
-
const
|
|
8
|
+
const { getDB } = require("@budibase/backend-core/db")
|
|
9
9
|
const { DocumentTypes } = require("../db/utils")
|
|
10
10
|
const { PermissionTypes } = require("@budibase/backend-core/permissions")
|
|
11
11
|
const { app: appCache } = require("@budibase/backend-core/cache")
|
|
@@ -48,7 +48,7 @@ async function updateAppUpdatedAt(ctx) {
|
|
|
48
48
|
if (ctx.method === "GET" || (await checkDebounce(appId))) {
|
|
49
49
|
return
|
|
50
50
|
}
|
|
51
|
-
const db =
|
|
51
|
+
const db = getDB(appId)
|
|
52
52
|
const metadata = await db.get(DocumentTypes.APP_METADATA)
|
|
53
53
|
metadata.updatedAt = new Date().toISOString()
|
|
54
54
|
const response = await db.put(metadata)
|
|
@@ -11,9 +11,9 @@ const { generateUserMetadataID, isDevAppID } = require("../db/utils")
|
|
|
11
11
|
const { dbExists } = require("@budibase/backend-core/db")
|
|
12
12
|
const { isUserInAppTenant } = require("@budibase/backend-core/tenancy")
|
|
13
13
|
const { getCachedSelf } = require("../utilities/global")
|
|
14
|
-
const CouchDB = require("../db")
|
|
15
14
|
const env = require("../environment")
|
|
16
15
|
const { isWebhookEndpoint } = require("./utils")
|
|
16
|
+
const { doInAppContext } = require("@budibase/backend-core/context")
|
|
17
17
|
|
|
18
18
|
module.exports = async (ctx, next) => {
|
|
19
19
|
// try to get the appID from the request
|
|
@@ -31,7 +31,7 @@ module.exports = async (ctx, next) => {
|
|
|
31
31
|
// check the app exists referenced in cookie
|
|
32
32
|
if (appCookie) {
|
|
33
33
|
const appId = appCookie.appId
|
|
34
|
-
const exists = await dbExists(
|
|
34
|
+
const exists = await dbExists(appId)
|
|
35
35
|
if (!exists) {
|
|
36
36
|
clearCookie(ctx, Cookies.CurrentApp)
|
|
37
37
|
return next()
|
|
@@ -41,13 +41,15 @@ module.exports = async (ctx, next) => {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// deny access to application preview
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
if (!env.isTest()) {
|
|
45
|
+
if (
|
|
46
|
+
isDevAppID(requestAppId) &&
|
|
47
|
+
!isWebhookEndpoint(ctx) &&
|
|
48
|
+
(!ctx.user || !ctx.user.builder || !ctx.user.builder.global)
|
|
49
|
+
) {
|
|
50
|
+
clearCookie(ctx, Cookies.CurrentApp)
|
|
51
|
+
return ctx.redirect("/")
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
let appId,
|
|
@@ -68,44 +70,46 @@ module.exports = async (ctx, next) => {
|
|
|
68
70
|
return next()
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
return doInAppContext(appId, async () => {
|
|
74
|
+
let noCookieSet = false
|
|
75
|
+
// if the user not in the right tenant then make sure they have no permissions
|
|
76
|
+
// need to judge this only based on the request app ID,
|
|
77
|
+
if (
|
|
78
|
+
env.MULTI_TENANCY &&
|
|
79
|
+
ctx.user &&
|
|
80
|
+
requestAppId &&
|
|
81
|
+
!isUserInAppTenant(requestAppId)
|
|
82
|
+
) {
|
|
83
|
+
// don't error, simply remove the users rights (they are a public user)
|
|
84
|
+
delete ctx.user.builder
|
|
85
|
+
delete ctx.user.admin
|
|
86
|
+
delete ctx.user.roles
|
|
87
|
+
roleId = BUILTIN_ROLE_IDS.PUBLIC
|
|
88
|
+
noCookieSet = true
|
|
89
|
+
}
|
|
87
90
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
ctx.appId = appId
|
|
92
|
+
if (roleId) {
|
|
93
|
+
ctx.roleId = roleId
|
|
94
|
+
const userId = ctx.user ? generateUserMetadataID(ctx.user._id) : null
|
|
95
|
+
ctx.user = {
|
|
96
|
+
...ctx.user,
|
|
97
|
+
// override userID with metadata one
|
|
98
|
+
_id: userId,
|
|
99
|
+
userId,
|
|
100
|
+
roleId,
|
|
101
|
+
role: await getRole(roleId),
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (
|
|
105
|
+
(requestAppId !== appId ||
|
|
106
|
+
appCookie == null ||
|
|
107
|
+
appCookie.appId !== requestAppId) &&
|
|
108
|
+
!noCookieSet
|
|
109
|
+
) {
|
|
110
|
+
setCookie(ctx, { appId }, Cookies.CurrentApp)
|
|
99
111
|
}
|
|
100
|
-
}
|
|
101
|
-
if (
|
|
102
|
-
(requestAppId !== appId ||
|
|
103
|
-
appCookie == null ||
|
|
104
|
-
appCookie.appId !== requestAppId) &&
|
|
105
|
-
!noCookieSet
|
|
106
|
-
) {
|
|
107
|
-
setCookie(ctx, { appId }, Cookies.CurrentApp)
|
|
108
|
-
}
|
|
109
112
|
|
|
110
|
-
|
|
113
|
+
return next()
|
|
114
|
+
})
|
|
111
115
|
}
|
|
@@ -11,6 +11,9 @@ const authorizedMiddleware = require("../authorized")
|
|
|
11
11
|
const env = require("../../environment")
|
|
12
12
|
const { PermissionTypes, PermissionLevels } = require("@budibase/backend-core/permissions")
|
|
13
13
|
require("@budibase/backend-core").init(require("../../db"))
|
|
14
|
+
const { doInAppContext } = require("@budibase/backend-core/context")
|
|
15
|
+
|
|
16
|
+
const APP_ID = ""
|
|
14
17
|
|
|
15
18
|
class TestConfiguration {
|
|
16
19
|
constructor(role) {
|
|
@@ -23,7 +26,7 @@ class TestConfiguration {
|
|
|
23
26
|
request: {
|
|
24
27
|
url: ""
|
|
25
28
|
},
|
|
26
|
-
appId:
|
|
29
|
+
appId: APP_ID,
|
|
27
30
|
auth: {},
|
|
28
31
|
next: this.next,
|
|
29
32
|
throw: this.throw,
|
|
@@ -32,7 +35,9 @@ class TestConfiguration {
|
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
executeMiddleware() {
|
|
35
|
-
return
|
|
38
|
+
return doInAppContext(APP_ID, () => {
|
|
39
|
+
return this.middleware(this.ctx, this.next)
|
|
40
|
+
})
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
setUser(user) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
mockAuthWithNoCookie()
|
|
2
2
|
mockWorker()
|
|
3
3
|
|
|
4
|
+
jest.mock("@budibase/backend-core/db", () => ({
|
|
5
|
+
...jest.requireActual("@budibase/backend-core/db"),
|
|
6
|
+
dbExists: () => true,
|
|
7
|
+
}))
|
|
8
|
+
|
|
4
9
|
function mockWorker() {
|
|
5
10
|
jest.mock("../../utilities/workerRequests", () => ({
|
|
6
11
|
getGlobalSelf: () => {
|
|
@@ -50,6 +55,7 @@ function mockAuthWithCookie() {
|
|
|
50
55
|
return "app_test"
|
|
51
56
|
},
|
|
52
57
|
setCookie: jest.fn(),
|
|
58
|
+
clearCookie: jest.fn(),
|
|
53
59
|
getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}),
|
|
54
60
|
}))
|
|
55
61
|
jest.mock("@budibase/backend-core/constants", () => ({
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
const CouchDB = require("../db")
|
|
2
1
|
const usageQuota = require("../utilities/usageQuota")
|
|
3
2
|
const { getUniqueRows } = require("../utilities/usageQuota/rows")
|
|
4
3
|
const {
|
|
5
4
|
isExternalTable,
|
|
6
5
|
isRowId: isExternalRowId,
|
|
7
6
|
} = require("../integrations/utils")
|
|
8
|
-
const
|
|
7
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
9
8
|
|
|
10
9
|
// currently only counting new writes and deletes
|
|
11
10
|
const METHOD_MAP = {
|
|
@@ -47,7 +46,7 @@ module.exports = async (ctx, next) => {
|
|
|
47
46
|
const usageId = ctx.request.body._id
|
|
48
47
|
try {
|
|
49
48
|
if (ctx.appId) {
|
|
50
|
-
const db =
|
|
49
|
+
const db = getAppDB()
|
|
51
50
|
await db.get(usageId)
|
|
52
51
|
}
|
|
53
52
|
return next()
|
|
@@ -74,7 +73,6 @@ module.exports = async (ctx, next) => {
|
|
|
74
73
|
usage = files.map(file => file.size).reduce((total, size) => total + size)
|
|
75
74
|
}
|
|
76
75
|
try {
|
|
77
|
-
await migration.run()
|
|
78
76
|
await performRequest(ctx, next, property, usage)
|
|
79
77
|
} catch (err) {
|
|
80
78
|
ctx.throw(400, err)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const { DocumentTypes } = require("@budibase/backend-core/db")
|
|
2
|
+
import { getAppUrl } from "../../api/controllers/application"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Date:
|
|
6
|
+
* January 2022
|
|
7
|
+
*
|
|
8
|
+
* Description:
|
|
9
|
+
* Add the url to the app metadata if it doesn't exist
|
|
10
|
+
*/
|
|
11
|
+
export const run = async (appDb: any) => {
|
|
12
|
+
let metadata
|
|
13
|
+
try {
|
|
14
|
+
metadata = await appDb.get(DocumentTypes.APP_METADATA)
|
|
15
|
+
} catch (e) {
|
|
16
|
+
// sometimes the metadata document doesn't exist
|
|
17
|
+
// exit early instead of failing the migration
|
|
18
|
+
console.error("Error retrieving app metadata. Skipping", e)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!metadata.url) {
|
|
23
|
+
const context = {
|
|
24
|
+
request: {
|
|
25
|
+
body: {
|
|
26
|
+
name: metadata.name,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
metadata.url = getAppUrl(context)
|
|
31
|
+
console.log(`Adding url to app: ${metadata.url}`)
|
|
32
|
+
await appDb.put(metadata)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { runQuotaMigration } from "./usageQuotas"
|
|
2
|
+
import * as syncApps from "./usageQuotas/syncApps"
|
|
3
|
+
import * as syncRows from "./usageQuotas/syncRows"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Date:
|
|
7
|
+
* January 2022
|
|
8
|
+
*
|
|
9
|
+
* Description:
|
|
10
|
+
* Synchronise the app and row quotas to the state of the db after it was
|
|
11
|
+
* discovered that the quota resets were still in place and the row quotas
|
|
12
|
+
* weren't being decremented correctly.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const run = async () => {
|
|
16
|
+
await runQuotaMigration(async () => {
|
|
17
|
+
await syncApps.run()
|
|
18
|
+
await syncRows.run()
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { DocumentTypes } = require("@budibase/backend-core/db")
|
|
2
|
+
const env = require("../../../environment")
|
|
3
|
+
const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
|
4
|
+
|
|
5
|
+
const migration = require("../appUrls")
|
|
6
|
+
|
|
7
|
+
describe("run", () => {
|
|
8
|
+
let config = new TestConfig(false)
|
|
9
|
+
const CouchDB = config.getCouch()
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
await config.init()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterAll(config.end)
|
|
16
|
+
|
|
17
|
+
it("runs successfully", async () => {
|
|
18
|
+
const app = await config.createApp("testApp")
|
|
19
|
+
const appDb = new CouchDB(app.appId)
|
|
20
|
+
let metadata = await appDb.get(DocumentTypes.APP_METADATA)
|
|
21
|
+
delete metadata.url
|
|
22
|
+
await appDb.put(metadata)
|
|
23
|
+
|
|
24
|
+
await migration.run(appDb)
|
|
25
|
+
|
|
26
|
+
metadata = await appDb.get(DocumentTypes.APP_METADATA)
|
|
27
|
+
expect(metadata.url).toEqual("/testapp")
|
|
28
|
+
})
|
|
29
|
+
})
|
|
@@ -4,10 +4,10 @@ const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
|
|
4
4
|
const syncApps = jest.fn()
|
|
5
5
|
const syncRows = jest.fn()
|
|
6
6
|
|
|
7
|
-
jest.mock("
|
|
8
|
-
jest.mock("
|
|
7
|
+
jest.mock("../usageQuotas/syncApps", () => ({ run: syncApps }) )
|
|
8
|
+
jest.mock("../usageQuotas/syncRows", () => ({ run: syncRows }) )
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const migration = require("../quotas1")
|
|
11
11
|
|
|
12
12
|
describe("run", () => {
|
|
13
13
|
let config = new TestConfig(false)
|
|
@@ -19,8 +19,8 @@ describe("run", () => {
|
|
|
19
19
|
|
|
20
20
|
afterAll(config.end)
|
|
21
21
|
|
|
22
|
-
it("runs
|
|
23
|
-
await
|
|
22
|
+
it("runs ", async () => {
|
|
23
|
+
await migration.run()
|
|
24
24
|
expect(syncApps).toHaveBeenCalledTimes(1)
|
|
25
25
|
expect(syncRows).toHaveBeenCalledTimes(1)
|
|
26
26
|
})
|