@budibase/server 1.0.49 → 1.0.50-alpha.3
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.2c37968e.js → index.9fe798bd.js} +252 -249
- package/builder/assets/index.c0cc369d.css +6 -0
- package/builder/assets/{vendor.f9faf6ab.js → vendor.5ad9695a.js} +202 -106
- package/builder/index.html +3 -3
- package/coverage/clover.xml +3105 -2814
- package/coverage/coverage-final.json +106 -101
- 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 +257 -152
- package/coverage/lcov-report/api/controllers/auth.js.html +22 -13
- 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 +13 -16
- package/coverage/lcov-report/api/controllers/datasource.js.html +81 -51
- package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
- package/coverage/lcov-report/api/controllers/index.html +78 -78
- 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/api/controllers/migrations.js.html +119 -0
- 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 +55 -40
- package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/row/internal.js.html +118 -226
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +52 -34
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +548 -0
- package/coverage/lcov-report/api/controllers/row/utils.js.html +47 -62
- 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 +599 -0
- package/coverage/lcov-report/api/controllers/table/external.js.html +25 -34
- package/coverage/lcov-report/api/controllers/table/index.html +58 -43
- package/coverage/lcov-report/api/controllers/table/index.js.html +58 -82
- package/coverage/lcov-report/api/controllers/table/internal.js.html +81 -66
- package/coverage/lcov-report/api/controllers/table/utils.js.html +218 -110
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +79 -76
- 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 +8 -8
- 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 +18 -18
- package/coverage/lcov-report/api/routes/index.js.html +3 -3
- 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/api/routes/{hosting.js.html → migrations.js.html} +17 -14
- 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 +17 -2
- 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 +13 -22
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +11 -20
- 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 +13 -13
- 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 +5 -5
- package/coverage/lcov-report/constants/index.js.html +53 -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 +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +25 -37
- package/coverage/lcov-report/db/linkedRows/index.html +27 -27
- package/coverage/lcov-report/db/linkedRows/index.js.html +51 -96
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +42 -42
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +87 -87
- 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 +135 -120
- 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 +173 -65
- package/coverage/lcov-report/middleware/builder.js.html +10 -10
- package/coverage/lcov-report/middleware/currentapp.js.html +95 -83
- package/coverage/lcov-report/middleware/index.html +38 -38
- 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 +281 -53
- 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 +26 -26
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +39 -24
- 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 +58 -49
- package/coverage/lcov-report/utilities/index.html +37 -37
- package/coverage/lcov-report/utilities/index.js.html +43 -73
- 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 +27 -27
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +97 -103
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
- 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 +141 -0
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +359 -0
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +305 -0
- package/coverage/lcov-report/{api/controllers/hosting.js.html → utilities/usageQuota/usageQuoteReset.js.html} +36 -48
- package/coverage/lcov-report/utilities/users.js.html +9 -9
- package/coverage/lcov-report/utilities/workerRequests.js.html +43 -112
- package/coverage/lcov.info +5010 -4425
- package/dist/api/controllers/application.js +90 -60
- package/dist/api/controllers/auth.js +8 -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 +20 -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 +55 -93
- package/dist/api/controllers/row/internalSearch.js +23 -17
- package/dist/api/controllers/row/staticFormula.js +147 -0
- package/dist/api/controllers/row/utils.js +13 -14
- package/dist/api/controllers/screen.js +5 -7
- package/dist/api/controllers/static/index.js +62 -16
- package/dist/api/controllers/table/bulkFormula.js +159 -0
- package/dist/api/controllers/table/external.js +7 -10
- package/dist/api/controllers/table/index.js +16 -13
- package/dist/api/controllers/table/internal.js +22 -16
- package/dist/api/controllers/table/utils.js +62 -35
- package/dist/api/controllers/user.js +43 -43
- 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 -2
- package/dist/api/routes/migrations.js +9 -0
- package/dist/api/routes/static.js +2 -1
- 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 +3 -5
- package/dist/automations/steps/deleteRow.js +1 -4
- package/dist/automations/steps/updateRow.js +1 -1
- package/dist/automations/triggers.js +27 -25
- package/dist/automations/utils.js +10 -5
- package/dist/constants/index.js +7 -0
- package/dist/db/linkedRows/LinkController.js +3 -7
- package/dist/db/linkedRows/index.js +16 -27
- package/dist/db/linkedRows/linkUtils.js +6 -6
- package/dist/db/views/staticViews.js +9 -10
- package/dist/definitions/datasource.js +1 -0
- package/dist/environment.js +4 -1
- package/dist/integrations/base/sql.js +62 -21
- package/dist/integrations/googlesheets.js +340 -0
- package/dist/integrations/index.js +3 -0
- package/dist/integrations/utils.js +60 -9
- package/dist/middleware/authorized.js +57 -30
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +41 -37
- package/dist/middleware/usageQuota.js +82 -15
- package/dist/migrations/functions/appUrls.js +46 -0
- package/dist/migrations/functions/quotas1.js +50 -0
- package/dist/migrations/functions/usageQuotas/index.js +20 -0
- package/dist/migrations/functions/usageQuotas/syncApps.js +29 -0
- package/dist/migrations/functions/usageQuotas/syncRows.js +33 -0
- package/dist/migrations/functions/userEmailViewCasing.js +24 -0
- package/dist/migrations/index.js +62 -0
- package/dist/package.json +8 -5
- package/dist/tests/utilities/TestConfiguration.js +80 -50
- package/dist/threads/automation.js +13 -11
- package/dist/threads/query.js +15 -11
- 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 +23 -17
- package/dist/utilities/rowProcessor/utils.js +14 -4
- package/dist/utilities/{usageQuota.js → usageQuota/index.js} +45 -31
- package/dist/utilities/usageQuota/rows.js +78 -0
- package/dist/utilities/usageQuota/usageQuoteReset.js +16 -0
- package/dist/utilities/users.js +3 -3
- package/dist/utilities/workerRequests.js +4 -24
- package/nodemon.json +1 -1
- package/package.json +9 -6
- 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 +85 -50
- package/src/api/controllers/auth.js +8 -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 +21 -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 +54 -90
- package/src/api/controllers/row/internalSearch.js +23 -17
- package/src/api/controllers/row/staticFormula.js +156 -0
- package/src/api/controllers/row/utils.js +13 -18
- package/src/api/controllers/screen.js +5 -7
- package/src/api/controllers/static/index.js +66 -15
- package/src/api/controllers/table/bulkFormula.js +173 -0
- package/src/api/controllers/table/external.js +7 -10
- package/src/api/controllers/table/index.js +20 -28
- package/src/api/controllers/table/internal.js +24 -19
- package/src/api/controllers/table/utils.js +78 -42
- package/src/api/controllers/user.js +46 -45
- 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 -2
- package/src/api/routes/migrations.js +14 -0
- package/src/api/routes/static.js +5 -0
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/auth.spec.js +1 -2
- 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/static.spec.js +98 -0
- 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 +2 -5
- package/src/automations/steps/deleteRow.js +1 -4
- package/src/automations/steps/updateRow.js +1 -1
- package/src/automations/triggers.js +33 -31
- package/src/automations/utils.js +9 -5
- package/src/constants/index.js +9 -0
- package/src/db/linkedRows/LinkController.js +3 -7
- package/src/db/linkedRows/index.js +16 -31
- 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/definitions/common.ts +3 -0
- package/src/definitions/datasource.ts +3 -0
- package/src/environment.js +4 -1
- package/src/integrations/base/sql.ts +75 -29
- package/src/integrations/googlesheets.ts +353 -0
- package/src/integrations/index.ts +3 -0
- package/src/integrations/tests/sql.spec.js +16 -0
- package/src/integrations/utils.ts +75 -12
- package/src/middleware/authorized.js +66 -30
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +50 -46
- package/src/middleware/tests/authorized.spec.js +13 -6
- package/src/middleware/tests/currentapp.spec.js +6 -0
- package/src/middleware/tests/usageQuota.spec.js +18 -24
- package/src/middleware/usageQuota.js +93 -17
- 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/functions/tests/quotas1.spec.js +27 -0
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
- package/src/migrations/functions/usageQuotas/index.ts +8 -0
- package/src/migrations/functions/usageQuotas/syncApps.ts +18 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +22 -0
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +37 -0
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +43 -0
- 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 +82 -55
- package/src/threads/automation.js +17 -15
- package/src/threads/query.js +17 -12
- 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 +25 -27
- package/src/utilities/rowProcessor/utils.js +23 -7
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
- package/src/utilities/usageQuota/index.js +93 -0
- package/src/utilities/usageQuota/rows.js +75 -0
- package/src/utilities/usageQuota/usageQuoteReset.js +18 -0
- package/src/utilities/users.js +3 -3
- package/src/utilities/workerRequests.js +4 -27
- package/tsconfig.json +4 -2
- package/builder/assets/index.39e01193.css +0 -1
- package/dist/api/controllers/hosting.js +0 -30
- package/dist/api/routes/hosting.js +0 -11
- package/src/api/controllers/hosting.js +0 -22
- package/src/api/routes/hosting.js +0 -13
- package/src/api/routes/tests/hosting.spec.js +0 -36
- package/src/utilities/usageQuota.js +0 -73
|
@@ -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,26 +11,33 @@ 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) {
|
|
17
20
|
this.middleware = authorizedMiddleware(role)
|
|
18
21
|
this.next = jest.fn()
|
|
19
22
|
this.throw = jest.fn()
|
|
23
|
+
this.headers = {}
|
|
20
24
|
this.ctx = {
|
|
21
25
|
headers: {},
|
|
22
26
|
request: {
|
|
23
27
|
url: ""
|
|
24
28
|
},
|
|
25
|
-
appId:
|
|
29
|
+
appId: APP_ID,
|
|
26
30
|
auth: {},
|
|
27
31
|
next: this.next,
|
|
28
|
-
throw: this.throw
|
|
32
|
+
throw: this.throw,
|
|
33
|
+
get: (name) => this.headers[name],
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
executeMiddleware() {
|
|
33
|
-
return
|
|
38
|
+
return doInAppContext(APP_ID, () => {
|
|
39
|
+
return this.middleware(this.ctx, this.next)
|
|
40
|
+
})
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
setUser(user) {
|
|
@@ -46,7 +53,7 @@ class TestConfiguration {
|
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
setAuthenticated(isAuthed) {
|
|
49
|
-
this.ctx.
|
|
56
|
+
this.ctx.isAuthenticated = isAuthed
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
setRequestUrl(url) {
|
|
@@ -107,7 +114,7 @@ describe("Authorization middleware", () => {
|
|
|
107
114
|
expect(config.next).toHaveBeenCalled()
|
|
108
115
|
})
|
|
109
116
|
|
|
110
|
-
it("throws if the user
|
|
117
|
+
it("throws if the user does not have builder permissions", async () => {
|
|
111
118
|
config.setEnvironment(false)
|
|
112
119
|
config.setMiddlewareRequiredPermission(PermissionTypes.BUILDER)
|
|
113
120
|
config.setUser({
|
|
@@ -133,7 +140,7 @@ describe("Authorization middleware", () => {
|
|
|
133
140
|
expect(config.next).toHaveBeenCalled()
|
|
134
141
|
})
|
|
135
142
|
|
|
136
|
-
it("throws if the user session is not authenticated
|
|
143
|
+
it("throws if the user session is not authenticated", async () => {
|
|
137
144
|
config.setUser({
|
|
138
145
|
role: {
|
|
139
146
|
_id: ""
|
|
@@ -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,5 @@
|
|
|
1
1
|
jest.mock("../../db")
|
|
2
2
|
jest.mock("../../utilities/usageQuota")
|
|
3
|
-
jest.mock("../../environment", () => ({
|
|
4
|
-
isTest: () => true,
|
|
5
|
-
isProd: () => false,
|
|
6
|
-
isDev: () => true,
|
|
7
|
-
_set: () => {},
|
|
8
|
-
}))
|
|
9
3
|
jest.mock("@budibase/backend-core/tenancy", () => ({
|
|
10
4
|
getTenantId: () => "testing123"
|
|
11
5
|
}))
|
|
@@ -29,9 +23,10 @@ class TestConfiguration {
|
|
|
29
23
|
},
|
|
30
24
|
req: {
|
|
31
25
|
method: "POST",
|
|
32
|
-
url: "/
|
|
26
|
+
url: "/applications"
|
|
33
27
|
}
|
|
34
28
|
}
|
|
29
|
+
usageQuota.useQuotas = () => true
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
executeMiddleware() {
|
|
@@ -113,7 +108,6 @@ describe("usageQuota middleware", () => {
|
|
|
113
108
|
|
|
114
109
|
it("calculates and persists the correct usage quota for the relevant action", async () => {
|
|
115
110
|
config.setUrl("/rows")
|
|
116
|
-
config.setProd(true)
|
|
117
111
|
|
|
118
112
|
await config.executeMiddleware()
|
|
119
113
|
|
|
@@ -121,20 +115,20 @@ describe("usageQuota middleware", () => {
|
|
|
121
115
|
expect(config.next).toHaveBeenCalled()
|
|
122
116
|
})
|
|
123
117
|
|
|
124
|
-
it("calculates the correct file size from a file upload call and adds it to quota", async () => {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
})
|
|
118
|
+
// it("calculates the correct file size from a file upload call and adds it to quota", async () => {
|
|
119
|
+
// config.setUrl("/upload")
|
|
120
|
+
// config.setProd(true)
|
|
121
|
+
// config.setFiles([
|
|
122
|
+
// {
|
|
123
|
+
// size: 100
|
|
124
|
+
// },
|
|
125
|
+
// {
|
|
126
|
+
// size: 10000
|
|
127
|
+
// },
|
|
128
|
+
// ])
|
|
129
|
+
// await config.executeMiddleware()
|
|
130
|
+
|
|
131
|
+
// expect(usageQuota.update).toHaveBeenCalledWith("storage", 10100)
|
|
132
|
+
// expect(config.next).toHaveBeenCalled()
|
|
133
|
+
// })
|
|
140
134
|
})
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
const CouchDB = require("../db")
|
|
2
1
|
const usageQuota = require("../utilities/usageQuota")
|
|
3
|
-
const
|
|
4
|
-
const { getTenantId } = require("@budibase/backend-core/tenancy")
|
|
2
|
+
const { getUniqueRows } = require("../utilities/usageQuota/rows")
|
|
5
3
|
const {
|
|
6
4
|
isExternalTable,
|
|
7
5
|
isRowId: isExternalRowId,
|
|
8
6
|
} = require("../integrations/utils")
|
|
9
|
-
|
|
10
|
-
// tenants without limits
|
|
11
|
-
const EXCLUDED_TENANTS = ["bb", "default", "bbtest", "bbstaging"]
|
|
7
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
12
8
|
|
|
13
9
|
// currently only counting new writes and deletes
|
|
14
10
|
const METHOD_MAP = {
|
|
@@ -18,13 +14,13 @@ const METHOD_MAP = {
|
|
|
18
14
|
|
|
19
15
|
const DOMAIN_MAP = {
|
|
20
16
|
rows: usageQuota.Properties.ROW,
|
|
21
|
-
upload: usageQuota.Properties.UPLOAD,
|
|
22
|
-
views: usageQuota.Properties.VIEW,
|
|
23
|
-
users: usageQuota.Properties.USER,
|
|
17
|
+
// upload: usageQuota.Properties.UPLOAD, // doesn't work yet
|
|
18
|
+
// views: usageQuota.Properties.VIEW, // doesn't work yet
|
|
19
|
+
// users: usageQuota.Properties.USER, // doesn't work yet
|
|
24
20
|
applications: usageQuota.Properties.APPS,
|
|
25
21
|
// this will not be updated by endpoint calls
|
|
26
22
|
// instead it will be updated by triggerInfo
|
|
27
|
-
automationRuns: usageQuota.Properties.AUTOMATION,
|
|
23
|
+
// automationRuns: usageQuota.Properties.AUTOMATION, // doesn't work yet
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
function getProperty(url) {
|
|
@@ -36,10 +32,7 @@ function getProperty(url) {
|
|
|
36
32
|
}
|
|
37
33
|
|
|
38
34
|
module.exports = async (ctx, next) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// if in development or a self hosted cloud usage quotas should not be executed
|
|
42
|
-
if (env.isDev() || env.SELF_HOSTED || EXCLUDED_TENANTS.includes(tenantId)) {
|
|
35
|
+
if (!usageQuota.useQuotas()) {
|
|
43
36
|
return next()
|
|
44
37
|
}
|
|
45
38
|
|
|
@@ -53,7 +46,7 @@ module.exports = async (ctx, next) => {
|
|
|
53
46
|
const usageId = ctx.request.body._id
|
|
54
47
|
try {
|
|
55
48
|
if (ctx.appId) {
|
|
56
|
-
const db =
|
|
49
|
+
const db = getAppDB()
|
|
57
50
|
await db.get(usageId)
|
|
58
51
|
}
|
|
59
52
|
return next()
|
|
@@ -80,9 +73,92 @@ module.exports = async (ctx, next) => {
|
|
|
80
73
|
usage = files.map(file => file.size).reduce((total, size) => total + size)
|
|
81
74
|
}
|
|
82
75
|
try {
|
|
83
|
-
await
|
|
84
|
-
return next()
|
|
76
|
+
await performRequest(ctx, next, property, usage)
|
|
85
77
|
} catch (err) {
|
|
86
78
|
ctx.throw(400, err)
|
|
87
79
|
}
|
|
88
80
|
}
|
|
81
|
+
|
|
82
|
+
const performRequest = async (ctx, next, property, usage) => {
|
|
83
|
+
const usageContext = {
|
|
84
|
+
skipNext: false,
|
|
85
|
+
skipUsage: false,
|
|
86
|
+
[usageQuota.Properties.APPS]: {},
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (usage === -1) {
|
|
90
|
+
if (PRE_DELETE[property]) {
|
|
91
|
+
await PRE_DELETE[property](ctx, usageContext)
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
if (PRE_CREATE[property]) {
|
|
95
|
+
await PRE_CREATE[property](ctx, usageContext)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// run the request
|
|
100
|
+
if (!usageContext.skipNext) {
|
|
101
|
+
await usageQuota.update(property, usage, { dryRun: true })
|
|
102
|
+
await next()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (usage === -1) {
|
|
106
|
+
if (POST_DELETE[property]) {
|
|
107
|
+
await POST_DELETE[property](ctx, usageContext)
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
if (POST_CREATE[property]) {
|
|
111
|
+
await POST_CREATE[property](ctx, usageContext)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// update the usage
|
|
116
|
+
if (!usageContext.skipUsage) {
|
|
117
|
+
await usageQuota.update(property, usage)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const appPreDelete = async (ctx, usageContext) => {
|
|
122
|
+
if (ctx.query.unpublish) {
|
|
123
|
+
// don't run usage decrement for unpublish
|
|
124
|
+
usageContext.skipUsage = true
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// store the row count to delete
|
|
129
|
+
const rows = await getUniqueRows([ctx.appId])
|
|
130
|
+
if (rows.length) {
|
|
131
|
+
usageContext[usageQuota.Properties.APPS] = { rowCount: rows.length }
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const appPostDelete = async (ctx, usageContext) => {
|
|
136
|
+
// delete the app rows from usage
|
|
137
|
+
const rowCount = usageContext[usageQuota.Properties.APPS].rowCount
|
|
138
|
+
if (rowCount) {
|
|
139
|
+
await usageQuota.update(usageQuota.Properties.ROW, -rowCount)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const appPostCreate = async ctx => {
|
|
144
|
+
// app import & template creation
|
|
145
|
+
if (ctx.request.body.useTemplate === "true") {
|
|
146
|
+
const rows = await getUniqueRows([ctx.response.body.appId])
|
|
147
|
+
const rowCount = rows ? rows.length : 0
|
|
148
|
+
await usageQuota.update(usageQuota.Properties.ROW, rowCount)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const PRE_DELETE = {
|
|
153
|
+
[usageQuota.Properties.APPS]: appPreDelete,
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const POST_DELETE = {
|
|
157
|
+
[usageQuota.Properties.APPS]: appPostDelete,
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const PRE_CREATE = {}
|
|
161
|
+
|
|
162
|
+
const POST_CREATE = {
|
|
163
|
+
[usageQuota.Properties.APPS]: appPostCreate,
|
|
164
|
+
}
|
|
@@ -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
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const env = require("../../../environment")
|
|
2
|
+
const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
|
3
|
+
|
|
4
|
+
const syncApps = jest.fn()
|
|
5
|
+
const syncRows = jest.fn()
|
|
6
|
+
|
|
7
|
+
jest.mock("../usageQuotas/syncApps", () => ({ run: syncApps }) )
|
|
8
|
+
jest.mock("../usageQuotas/syncRows", () => ({ run: syncRows }) )
|
|
9
|
+
|
|
10
|
+
const migration = require("../quotas1")
|
|
11
|
+
|
|
12
|
+
describe("run", () => {
|
|
13
|
+
let config = new TestConfig(false)
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
await config.init()
|
|
17
|
+
env._set("USE_QUOTAS", 1)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
afterAll(config.end)
|
|
21
|
+
|
|
22
|
+
it("runs ", async () => {
|
|
23
|
+
await migration.run()
|
|
24
|
+
expect(syncApps).toHaveBeenCalledTimes(1)
|
|
25
|
+
expect(syncRows).toHaveBeenCalledTimes(1)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const TestConfig = require("../../../tests/utilities/TestConfiguration")
|
|
2
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
3
|
+
|
|
4
|
+
// mock email view creation
|
|
5
|
+
const coreDb = require("@budibase/backend-core/db")
|
|
6
|
+
const createUserEmailView = jest.fn()
|
|
7
|
+
coreDb.createUserEmailView = createUserEmailView
|
|
8
|
+
|
|
9
|
+
const migration = require("../userEmailViewCasing")
|
|
10
|
+
|
|
11
|
+
describe("run", () => {
|
|
12
|
+
let config = new TestConfig(false)
|
|
13
|
+
const globalDb = getGlobalDB()
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
await config.init()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
afterAll(config.end)
|
|
20
|
+
|
|
21
|
+
it("runs successfully", async () => {
|
|
22
|
+
await migration.run(globalDb)
|
|
23
|
+
expect(createUserEmailView).toHaveBeenCalledTimes(1)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getGlobalDB, getTenantId } from "@budibase/backend-core/tenancy"
|
|
2
|
+
import { getAllApps } from "@budibase/backend-core/db"
|
|
3
|
+
import { getUsageQuotaDoc } from "../../../utilities/usageQuota"
|
|
4
|
+
|
|
5
|
+
export const run = async () => {
|
|
6
|
+
const db = getGlobalDB()
|
|
7
|
+
// get app count
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const devApps = await getAllApps({ dev: true })
|
|
10
|
+
const appCount = devApps ? devApps.length : 0
|
|
11
|
+
|
|
12
|
+
// sync app count
|
|
13
|
+
const tenantId = getTenantId()
|
|
14
|
+
console.log(`[Tenant: ${tenantId}] Syncing app count: ${appCount}`)
|
|
15
|
+
const usageDoc = await getUsageQuotaDoc(db)
|
|
16
|
+
usageDoc.usageQuota.apps = appCount
|
|
17
|
+
await db.put(usageDoc)
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getGlobalDB, getTenantId } from "@budibase/backend-core/tenancy"
|
|
2
|
+
import { getAllApps } from "@budibase/backend-core/db"
|
|
3
|
+
import { getUsageQuotaDoc } from "../../../utilities/usageQuota"
|
|
4
|
+
import { getUniqueRows } from "../../../utilities/usageQuota/rows"
|
|
5
|
+
|
|
6
|
+
export const run = async () => {
|
|
7
|
+
const db = getGlobalDB()
|
|
8
|
+
// get all rows in all apps
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const allApps = await getAllApps({ all: true })
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : []
|
|
13
|
+
const rows = await getUniqueRows(appIds)
|
|
14
|
+
const rowCount = rows ? rows.length : 0
|
|
15
|
+
|
|
16
|
+
// sync row count
|
|
17
|
+
const tenantId = getTenantId()
|
|
18
|
+
console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`)
|
|
19
|
+
const usageDoc = await getUsageQuotaDoc(db)
|
|
20
|
+
usageDoc.usageQuota.rows = rowCount
|
|
21
|
+
await db.put(usageDoc)
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
2
|
+
const TestConfig = require("../../../../tests/utilities/TestConfiguration")
|
|
3
|
+
const { getUsageQuotaDoc, update, Properties } = require("../../../../utilities/usageQuota")
|
|
4
|
+
const syncApps = require("../syncApps")
|
|
5
|
+
const env = require("../../../../environment")
|
|
6
|
+
|
|
7
|
+
describe("syncApps", () => {
|
|
8
|
+
let config = new TestConfig(false)
|
|
9
|
+
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
await config.init()
|
|
12
|
+
env._set("USE_QUOTAS", 1)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterAll(config.end)
|
|
16
|
+
|
|
17
|
+
it("runs successfully", async () => {
|
|
18
|
+
// create the usage quota doc and mock usages
|
|
19
|
+
const db = getGlobalDB()
|
|
20
|
+
await getUsageQuotaDoc(db)
|
|
21
|
+
await update(Properties.APPS, 3)
|
|
22
|
+
|
|
23
|
+
let usageDoc = await getUsageQuotaDoc(db)
|
|
24
|
+
expect(usageDoc.usageQuota.apps).toEqual(3)
|
|
25
|
+
|
|
26
|
+
// create an extra app to test the migration
|
|
27
|
+
await config.createApp("quota-test")
|
|
28
|
+
|
|
29
|
+
// migrate
|
|
30
|
+
await syncApps.run()
|
|
31
|
+
|
|
32
|
+
// assert the migration worked
|
|
33
|
+
usageDoc = await getUsageQuotaDoc(db)
|
|
34
|
+
expect(usageDoc.usageQuota.apps).toEqual(2)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|