@budibase/server 1.0.49-alpha.6 → 1.0.49

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.
Files changed (376) hide show
  1. package/__mocks__/arangojs.ts +1 -1
  2. package/__mocks__/aws-sdk.ts +4 -4
  3. package/__mocks__/mongodb.ts +5 -4
  4. package/__mocks__/mssql.ts +3 -3
  5. package/__mocks__/node-fetch.ts +1 -2
  6. package/__mocks__/pg.ts +5 -3
  7. package/builder/assets/{index.1b905242.js → index.2c37968e.js} +231 -234
  8. package/builder/assets/index.39e01193.css +1 -0
  9. package/builder/assets/{vendor.d526bfe8.js → vendor.f9faf6ab.js} +12 -12
  10. package/builder/index.html +3 -3
  11. package/coverage/clover.xml +2816 -3119
  12. package/coverage/coverage-final.json +101 -106
  13. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/application.js.html +152 -257
  16. package/coverage/lcov-report/api/controllers/auth.js.html +13 -22
  17. package/coverage/lcov-report/api/controllers/automation.js.html +69 -39
  18. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -8
  20. package/coverage/lcov-report/api/controllers/component.js.html +16 -13
  21. package/coverage/lcov-report/api/controllers/datasource.js.html +51 -81
  22. package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
  23. package/coverage/lcov-report/{utilities/usageQuota/usageQuoteReset.js.html → api/controllers/hosting.js.html} +48 -36
  24. package/coverage/lcov-report/api/controllers/index.html +76 -76
  25. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
  27. package/coverage/lcov-report/api/controllers/metadata.js.html +21 -6
  28. package/coverage/lcov-report/api/controllers/permission.js.html +19 -19
  29. package/coverage/lcov-report/api/controllers/query/index.html +10 -10
  30. package/coverage/lcov-report/api/controllers/query/index.js.html +35 -38
  31. package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
  32. package/coverage/lcov-report/api/controllers/role.js.html +16 -16
  33. package/coverage/lcov-report/api/controllers/routing.js.html +10 -7
  34. package/coverage/lcov-report/api/controllers/row/external.js.html +27 -21
  35. package/coverage/lcov-report/api/controllers/row/index.html +34 -49
  36. package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
  37. package/coverage/lcov-report/api/controllers/row/internal.js.html +226 -118
  38. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +34 -52
  39. package/coverage/lcov-report/api/controllers/row/utils.js.html +62 -47
  40. package/coverage/lcov-report/api/controllers/screen.js.html +21 -15
  41. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  42. package/coverage/lcov-report/api/controllers/table/external.js.html +34 -25
  43. package/coverage/lcov-report/api/controllers/table/index.html +43 -58
  44. package/coverage/lcov-report/api/controllers/table/index.js.html +82 -58
  45. package/coverage/lcov-report/api/controllers/table/internal.js.html +66 -81
  46. package/coverage/lcov-report/api/controllers/table/utils.js.html +110 -218
  47. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  48. package/coverage/lcov-report/api/controllers/user.js.html +50 -47
  49. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  50. package/coverage/lcov-report/api/controllers/view/index.html +16 -16
  51. package/coverage/lcov-report/api/controllers/view/index.js.html +33 -27
  52. package/coverage/lcov-report/api/controllers/view/utils.js.html +20 -35
  53. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  54. package/coverage/lcov-report/api/controllers/webhook.js.html +28 -34
  55. package/coverage/lcov-report/api/index.html +1 -1
  56. package/coverage/lcov-report/api/index.js.html +8 -8
  57. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/{migrations.js.html → hosting.js.html} +14 -17
  69. package/coverage/lcov-report/api/routes/index.html +18 -18
  70. package/coverage/lcov-report/api/routes/index.js.html +3 -3
  71. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/static.js.html +2 -17
  82. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  83. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  84. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  85. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  86. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  87. package/coverage/lcov-report/automations/actions.js.html +24 -24
  88. package/coverage/lcov-report/automations/automationUtils.js.html +10 -7
  89. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  90. package/coverage/lcov-report/automations/index.html +18 -18
  91. package/coverage/lcov-report/automations/index.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  93. package/coverage/lcov-report/automations/steps/createRow.js.html +22 -13
  94. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  95. package/coverage/lcov-report/automations/steps/deleteRow.js.html +20 -11
  96. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  97. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  98. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  99. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  100. package/coverage/lcov-report/automations/steps/index.html +13 -13
  101. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  102. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  103. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  104. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  105. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  106. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  107. package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
  108. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  109. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  110. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  111. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  112. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  113. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  114. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  115. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  116. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  117. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  118. package/coverage/lcov-report/automations/triggers.js.html +55 -61
  119. package/coverage/lcov-report/automations/utils.js.html +42 -54
  120. package/coverage/lcov-report/constants/index.html +5 -5
  121. package/coverage/lcov-report/constants/index.js.html +26 -53
  122. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  123. package/coverage/lcov-report/constants/screens.js.html +4 -4
  124. package/coverage/lcov-report/db/client.js.html +18 -18
  125. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  126. package/coverage/lcov-report/db/index.html +15 -15
  127. package/coverage/lcov-report/db/index.js.html +3 -3
  128. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +37 -25
  129. package/coverage/lcov-report/db/linkedRows/index.html +27 -27
  130. package/coverage/lcov-report/db/linkedRows/index.js.html +96 -51
  131. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +42 -42
  132. package/coverage/lcov-report/db/newid.js.html +4 -4
  133. package/coverage/lcov-report/db/utils.js.html +87 -87
  134. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  135. package/coverage/lcov-report/events/index.html +1 -1
  136. package/coverage/lcov-report/events/index.js.html +5 -5
  137. package/coverage/lcov-report/events/utils.js.html +3 -3
  138. package/coverage/lcov-report/index.html +120 -135
  139. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  140. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  141. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  142. package/coverage/lcov-report/middleware/authorized.js.html +65 -173
  143. package/coverage/lcov-report/middleware/builder.js.html +10 -10
  144. package/coverage/lcov-report/middleware/currentapp.js.html +83 -95
  145. package/coverage/lcov-report/middleware/index.html +38 -38
  146. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  147. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  148. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  149. package/coverage/lcov-report/middleware/usageQuota.js.html +53 -281
  150. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  151. package/coverage/lcov-report/threads/automation.js.html +24 -30
  152. package/coverage/lcov-report/threads/index.html +26 -26
  153. package/coverage/lcov-report/threads/index.js.html +10 -10
  154. package/coverage/lcov-report/threads/query.js.html +26 -62
  155. package/coverage/lcov-report/threads/utils.js.html +14 -14
  156. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  157. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  158. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  159. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  160. package/coverage/lcov-report/utilities/global.js.html +49 -58
  161. package/coverage/lcov-report/utilities/index.html +37 -37
  162. package/coverage/lcov-report/utilities/index.js.html +73 -43
  163. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  164. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  165. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  166. package/coverage/lcov-report/utilities/routing/index.js.html +7 -7
  167. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
  168. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +103 -97
  169. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +27 -75
  170. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  171. package/coverage/lcov-report/utilities/security.js.html +8 -8
  172. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  173. package/coverage/lcov-report/utilities/users.js.html +9 -9
  174. package/coverage/lcov-report/utilities/workerRequests.js.html +112 -43
  175. package/coverage/lcov.info +4423 -5022
  176. package/dist/api/controllers/application.js +60 -90
  177. package/dist/api/controllers/auth.js +5 -8
  178. package/dist/api/controllers/automation.js +19 -14
  179. package/dist/api/controllers/cloud.js +3 -2
  180. package/dist/api/controllers/component.js +4 -3
  181. package/dist/api/controllers/datasource.js +10 -20
  182. package/dist/api/controllers/deploy/Deployment.js +6 -3
  183. package/dist/api/controllers/deploy/index.js +13 -12
  184. package/dist/api/controllers/dev.js +5 -5
  185. package/dist/api/controllers/hosting.js +30 -0
  186. package/dist/api/controllers/layout.js +3 -3
  187. package/dist/api/controllers/metadata.js +4 -4
  188. package/dist/api/controllers/permission.js +4 -4
  189. package/dist/api/controllers/query/import/index.js +6 -4
  190. package/dist/api/controllers/query/index.js +10 -11
  191. package/dist/api/controllers/role.js +5 -5
  192. package/dist/api/controllers/routing.js +6 -5
  193. package/dist/api/controllers/row/ExternalRequest.js +63 -76
  194. package/dist/api/controllers/row/external.js +4 -4
  195. package/dist/api/controllers/row/internal.js +93 -55
  196. package/dist/api/controllers/row/internalSearch.js +17 -23
  197. package/dist/api/controllers/row/utils.js +14 -13
  198. package/dist/api/controllers/screen.js +7 -5
  199. package/dist/api/controllers/static/index.js +12 -61
  200. package/dist/api/controllers/table/external.js +10 -7
  201. package/dist/api/controllers/table/index.js +13 -16
  202. package/dist/api/controllers/table/internal.js +16 -22
  203. package/dist/api/controllers/table/utils.js +35 -62
  204. package/dist/api/controllers/user.js +20 -18
  205. package/dist/api/controllers/view/index.js +10 -8
  206. package/dist/api/controllers/view/utils.js +4 -9
  207. package/dist/api/controllers/webhook.js +8 -10
  208. package/dist/api/routes/hosting.js +11 -0
  209. package/dist/api/routes/index.js +2 -2
  210. package/dist/api/routes/static.js +1 -2
  211. package/dist/api/routes/tests/utilities/TestFunctions.js +17 -37
  212. package/dist/app.js +5 -35
  213. package/dist/automations/automationUtils.js +3 -2
  214. package/dist/automations/steps/createRow.js +5 -3
  215. package/dist/automations/steps/deleteRow.js +4 -1
  216. package/dist/automations/steps/updateRow.js +1 -1
  217. package/dist/automations/triggers.js +25 -27
  218. package/dist/automations/utils.js +5 -10
  219. package/dist/constants/index.js +0 -7
  220. package/dist/db/linkedRows/LinkController.js +7 -3
  221. package/dist/db/linkedRows/index.js +27 -16
  222. package/dist/db/linkedRows/linkUtils.js +6 -6
  223. package/dist/db/views/staticViews.js +10 -9
  224. package/dist/definitions/datasource.js +0 -1
  225. package/dist/environment.js +1 -4
  226. package/dist/integrations/base/sql.js +6 -13
  227. package/dist/integrations/index.js +0 -3
  228. package/dist/integrations/utils.js +9 -60
  229. package/dist/middleware/authorized.js +30 -57
  230. package/dist/middleware/builder.js +2 -2
  231. package/dist/middleware/currentapp.js +37 -41
  232. package/dist/middleware/usageQuota.js +15 -82
  233. package/dist/package.json +5 -8
  234. package/dist/tests/utilities/TestConfiguration.js +50 -80
  235. package/dist/threads/automation.js +11 -13
  236. package/dist/threads/query.js +13 -23
  237. package/dist/tsconfig.tsbuildinfo +1 -1
  238. package/dist/utilities/fileSystem/index.js +3 -4
  239. package/dist/utilities/global.js +12 -15
  240. package/dist/utilities/index.js +17 -7
  241. package/dist/utilities/routing/index.js +5 -5
  242. package/dist/utilities/rowProcessor/index.js +17 -23
  243. package/dist/utilities/rowProcessor/utils.js +4 -14
  244. package/dist/utilities/{usageQuota/index.js → usageQuota.js} +31 -45
  245. package/dist/utilities/users.js +3 -3
  246. package/dist/utilities/workerRequests.js +24 -4
  247. package/nodemon.json +1 -1
  248. package/package.json +6 -9
  249. package/scripts/likeCypress.ts +1 -1
  250. package/src/api/controllers/application.js +50 -85
  251. package/src/api/controllers/auth.js +5 -8
  252. package/src/api/controllers/automation.js +23 -13
  253. package/src/api/controllers/cloud.js +3 -2
  254. package/src/api/controllers/component.js +4 -3
  255. package/src/api/controllers/datasource.js +11 -21
  256. package/src/api/controllers/deploy/Deployment.js +7 -3
  257. package/src/api/controllers/deploy/index.js +13 -20
  258. package/src/api/controllers/dev.js +5 -5
  259. package/src/api/controllers/hosting.js +22 -0
  260. package/src/api/controllers/layout.js +3 -3
  261. package/src/api/controllers/metadata.js +9 -4
  262. package/src/api/controllers/permission.js +4 -4
  263. package/src/api/controllers/query/import/index.ts +6 -4
  264. package/src/api/controllers/query/import/tests/index.spec.js +1 -2
  265. package/src/api/controllers/query/index.js +10 -11
  266. package/src/api/controllers/role.js +5 -5
  267. package/src/api/controllers/routing.js +6 -5
  268. package/src/api/controllers/row/ExternalRequest.ts +42 -53
  269. package/src/api/controllers/row/external.js +6 -4
  270. package/src/api/controllers/row/internal.js +90 -54
  271. package/src/api/controllers/row/internalSearch.js +17 -23
  272. package/src/api/controllers/row/utils.js +18 -13
  273. package/src/api/controllers/screen.js +7 -5
  274. package/src/api/controllers/static/index.js +12 -65
  275. package/src/api/controllers/table/external.js +10 -7
  276. package/src/api/controllers/table/index.js +28 -20
  277. package/src/api/controllers/table/internal.js +19 -24
  278. package/src/api/controllers/table/utils.js +42 -78
  279. package/src/api/controllers/user.js +20 -19
  280. package/src/api/controllers/view/index.js +10 -8
  281. package/src/api/controllers/view/utils.js +4 -9
  282. package/src/api/controllers/webhook.js +8 -10
  283. package/src/api/routes/hosting.js +13 -0
  284. package/src/api/routes/index.js +2 -2
  285. package/src/api/routes/static.js +0 -5
  286. package/src/api/routes/tests/application.spec.js +2 -2
  287. package/src/api/routes/tests/auth.spec.js +2 -1
  288. package/src/api/routes/tests/automation.spec.js +0 -1
  289. package/src/api/routes/tests/hosting.spec.js +36 -0
  290. package/src/api/routes/tests/misc.spec.js +1 -0
  291. package/src/api/routes/tests/routing.spec.js +12 -21
  292. package/src/api/routes/tests/row.spec.js +4 -7
  293. package/src/api/routes/tests/utilities/TestFunctions.js +17 -39
  294. package/src/app.ts +5 -18
  295. package/src/automations/automationUtils.js +3 -2
  296. package/src/automations/steps/createRow.js +5 -2
  297. package/src/automations/steps/deleteRow.js +4 -1
  298. package/src/automations/steps/updateRow.js +1 -1
  299. package/src/automations/triggers.js +31 -33
  300. package/src/automations/utils.js +5 -9
  301. package/src/constants/index.js +0 -9
  302. package/src/db/linkedRows/LinkController.js +7 -3
  303. package/src/db/linkedRows/index.js +31 -16
  304. package/src/db/linkedRows/linkUtils.js +6 -6
  305. package/src/db/tests/linkController.spec.js +1 -0
  306. package/src/db/tests/linkTests.spec.js +6 -5
  307. package/src/db/views/staticViews.js +10 -8
  308. package/src/definitions/common.ts +0 -3
  309. package/src/definitions/datasource.ts +0 -3
  310. package/src/environment.js +1 -4
  311. package/src/integrations/base/sql.ts +7 -14
  312. package/src/integrations/index.ts +0 -3
  313. package/src/integrations/tests/sql.spec.js +0 -16
  314. package/src/integrations/utils.ts +12 -75
  315. package/src/middleware/authorized.js +30 -66
  316. package/src/middleware/builder.js +2 -2
  317. package/src/middleware/currentapp.js +46 -50
  318. package/src/middleware/tests/authorized.spec.js +6 -13
  319. package/src/middleware/tests/currentapp.spec.js +0 -6
  320. package/src/middleware/tests/usageQuota.spec.js +24 -18
  321. package/src/middleware/usageQuota.js +17 -93
  322. package/src/tests/utilities/TestConfiguration.js +55 -82
  323. package/src/threads/automation.js +15 -17
  324. package/src/threads/query.js +14 -26
  325. package/src/utilities/fileSystem/index.js +3 -4
  326. package/src/utilities/global.js +12 -15
  327. package/src/utilities/index.js +17 -7
  328. package/src/utilities/routing/index.js +5 -5
  329. package/src/utilities/rowProcessor/index.js +27 -25
  330. package/src/utilities/rowProcessor/utils.js +7 -23
  331. package/src/utilities/usageQuota.js +73 -0
  332. package/src/utilities/users.js +3 -3
  333. package/src/utilities/workerRequests.js +27 -4
  334. package/builder/assets/index.83c0944f.css +0 -1
  335. package/coverage/lcov-report/api/controllers/migrations.js.html +0 -119
  336. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +0 -548
  337. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +0 -599
  338. package/coverage/lcov-report/utilities/usageQuota/index.html +0 -141
  339. package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
  340. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +0 -305
  341. package/dist/api/controllers/migrations.js +0 -21
  342. package/dist/api/controllers/row/staticFormula.js +0 -147
  343. package/dist/api/controllers/table/bulkFormula.js +0 -159
  344. package/dist/api/routes/migrations.js +0 -9
  345. package/dist/integrations/googlesheets.js +0 -340
  346. package/dist/migrations/functions/appUrls.js +0 -46
  347. package/dist/migrations/functions/quotas1.js +0 -50
  348. package/dist/migrations/functions/usageQuotas/index.js +0 -20
  349. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -30
  350. package/dist/migrations/functions/usageQuotas/syncRows.js +0 -33
  351. package/dist/migrations/functions/userEmailViewCasing.js +0 -24
  352. package/dist/migrations/index.js +0 -62
  353. package/dist/utilities/usageQuota/rows.js +0 -78
  354. package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
  355. package/src/api/controllers/migrations.js +0 -13
  356. package/src/api/controllers/row/staticFormula.js +0 -156
  357. package/src/api/controllers/table/bulkFormula.js +0 -173
  358. package/src/api/routes/migrations.js +0 -14
  359. package/src/api/routes/tests/static.spec.js +0 -98
  360. package/src/integrations/googlesheets.ts +0 -353
  361. package/src/migrations/functions/appUrls.ts +0 -34
  362. package/src/migrations/functions/quotas1.ts +0 -20
  363. package/src/migrations/functions/tests/appUrls.spec.js +0 -29
  364. package/src/migrations/functions/tests/quotas1.spec.js +0 -27
  365. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +0 -25
  366. package/src/migrations/functions/usageQuotas/index.ts +0 -8
  367. package/src/migrations/functions/usageQuotas/syncApps.ts +0 -19
  368. package/src/migrations/functions/usageQuotas/syncRows.ts +0 -22
  369. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
  370. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
  371. package/src/migrations/functions/userEmailViewCasing.ts +0 -13
  372. package/src/migrations/index.ts +0 -56
  373. package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
  374. package/src/utilities/usageQuota/index.js +0 -93
  375. package/src/utilities/usageQuota/rows.js +0 -75
  376. package/src/utilities/usageQuota/usageQuoteReset.js +0 -18
@@ -1,8 +1,8 @@
1
+ const CouchDB = require("../index")
1
2
  const Sentry = require("@sentry/node")
2
3
  const { ViewNames, getQueryIndex } = require("../utils")
3
4
  const { FieldTypes } = require("../../constants")
4
5
  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,6 +17,7 @@ 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.
20
21
  * @param {string} args.tableId The table which we are searching for linked rows against.
21
22
  * @param {string|null} args.fieldName The name of column/field which is being altered, only looking for
22
23
  * linking documents that are related to it. If this is not specified then the table level will be assumed.
@@ -29,8 +30,8 @@ exports.createLinkView = createLinkView
29
30
  * (if any).
30
31
  */
31
32
  exports.getLinkDocuments = async function (args) {
32
- const { tableId, rowId, includeDocs } = args
33
- const db = getAppDB()
33
+ const { appId, tableId, rowId, includeDocs } = args
34
+ const db = new CouchDB(appId)
34
35
  let params
35
36
  if (rowId != null) {
36
37
  params = { key: [tableId, rowId] }
@@ -67,7 +68,7 @@ exports.getLinkDocuments = async function (args) {
67
68
  } catch (err) {
68
69
  // check if the view doesn't exist, it should for all new instances
69
70
  if (err != null && err.name === "not_found") {
70
- await exports.createLinkView()
71
+ await exports.createLinkView(appId)
71
72
  return exports.getLinkDocuments(arguments[0])
72
73
  } else {
73
74
  /* istanbul ignore next */
@@ -88,8 +89,7 @@ exports.getLinkedTableIDs = table => {
88
89
  .map(column => column.tableId)
89
90
  }
90
91
 
91
- exports.getLinkedTable = async (id, tables) => {
92
- const db = getAppDB()
92
+ exports.getLinkedTable = async (db, id, tables) => {
93
93
  let linkedTable = tables.find(table => table._id === id)
94
94
  if (linkedTable) {
95
95
  return linkedTable
@@ -20,6 +20,7 @@ describe("test the link controller", () => {
20
20
 
21
21
  function createLinkController(table, row = null, oldTable = null) {
22
22
  const linkConfig = {
23
+ appId: config.getAppId(),
23
24
  tableId: table._id,
24
25
  table,
25
26
  }
@@ -1,8 +1,8 @@
1
1
  const TestConfig = require("../../tests/utilities/TestConfiguration")
2
- const { basicTable } = require("../../tests/utilities/structures")
2
+ const { basicTable, basicLinkedRow } = require("../../tests/utilities/structures")
3
3
  const linkUtils = require("../linkedRows/linkUtils")
4
+ const links = require("../linkedRows")
4
5
  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 = getAppDB()
14
+ db = new CouchDB(config.getAppId())
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(table._id, [table])
19
+ const retrieved = await linkUtils.getLinkedTable(db, 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(table._id, tables)
25
+ const retrieved = await linkUtils.getLinkedTable(db, table._id, tables)
26
26
  expect(retrieved._id).toBe(table._id)
27
27
  expect(tables[0]).toBeDefined()
28
28
  })
@@ -51,6 +51,7 @@ 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",
54
55
  tableId: "test",
55
56
  rowId: "test",
56
57
  includeDocs: false,
@@ -1,4 +1,4 @@
1
- const { getAppDB } = require("@budibase/backend-core/context")
1
+ const CouchDB = require("../index")
2
2
  const {
3
3
  DocumentTypes,
4
4
  SEPARATOR,
@@ -21,11 +21,12 @@ 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.
24
25
  * @returns {Promise<void>} The view now exists, please note that the next view of this query will actually build it,
25
26
  * so it may be slow.
26
27
  */
27
- exports.createLinkView = async () => {
28
- const db = getAppDB()
28
+ exports.createLinkView = async appId => {
29
+ const db = new CouchDB(appId)
29
30
  const designDoc = await db.get("_design/database")
30
31
  const view = {
31
32
  map: function (doc) {
@@ -56,8 +57,8 @@ exports.createLinkView = async () => {
56
57
  await db.put(designDoc)
57
58
  }
58
59
 
59
- exports.createRoutingView = async () => {
60
- const db = getAppDB()
60
+ exports.createRoutingView = async appId => {
61
+ const db = new CouchDB(appId)
61
62
  const designDoc = await db.get("_design/database")
62
63
  const view = {
63
64
  // if using variables in a map function need to inject them before use
@@ -77,8 +78,8 @@ exports.createRoutingView = async () => {
77
78
  await db.put(designDoc)
78
79
  }
79
80
 
80
- async function searchIndex(indexName, fnString) {
81
- const db = getAppDB()
81
+ async function searchIndex(appId, indexName, fnString) {
82
+ const db = new CouchDB(appId)
82
83
  const designDoc = await db.get("_design/database")
83
84
  designDoc.indexes = {
84
85
  [indexName]: {
@@ -89,8 +90,9 @@ async function searchIndex(indexName, fnString) {
89
90
  await db.put(designDoc)
90
91
  }
91
92
 
92
- exports.createAllSearchIndex = async () => {
93
+ exports.createAllSearchIndex = async appId => {
93
94
  await searchIndex(
95
+ appId,
94
96
  SearchIndexes.ROWS,
95
97
  function (doc) {
96
98
  function idx(input, prev) {
@@ -17,8 +17,6 @@ export interface FieldSchema {
17
17
  autocolumn?: boolean
18
18
  throughFrom?: string
19
19
  throughTo?: string
20
- formula?: string
21
- formulaType?: string
22
20
  main?: boolean
23
21
  meta?: {
24
22
  toTable: string
@@ -48,7 +46,6 @@ export interface Table extends Base {
48
46
  schema: TableSchema
49
47
  primaryDisplay?: string
50
48
  sourceId?: string
51
- relatedFormula?: string[]
52
49
  constrained?: string[]
53
50
  }
54
51
 
@@ -47,7 +47,6 @@ export enum SourceNames {
47
47
  ARANGODB = "ARANGODB",
48
48
  REST = "REST",
49
49
  ORACLE = "ORACLE",
50
- GOOGLE_SHEETS = "GOOGLE_SHEETS",
51
50
  }
52
51
 
53
52
  export enum IncludeRelationships {
@@ -87,8 +86,6 @@ export interface ExtraQueryConfig {
87
86
  export interface Integration {
88
87
  docs: string
89
88
  plus?: boolean
90
- auth?: { type: string }
91
- relationships?: boolean
92
89
  description: string
93
90
  friendlyName: string
94
91
  datasource: {}
@@ -2,8 +2,7 @@ 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 &&
6
- process.env.JEST_WORKER_ID !== "null")
5
+ process.env.JEST_WORKER_ID != null
7
6
  )
8
7
  }
9
8
 
@@ -39,12 +38,10 @@ module.exports = {
39
38
  MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
40
39
  MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
41
40
  USE_QUOTAS: process.env.USE_QUOTAS,
42
- EXCLUDE_QUOTAS_TENANTS: process.env.EXCLUDE_QUOTAS_TENANTS,
43
41
  REDIS_URL: process.env.REDIS_URL,
44
42
  REDIS_PASSWORD: process.env.REDIS_PASSWORD,
45
43
  INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
46
44
  MULTI_TENANCY: process.env.MULTI_TENANCY,
47
- HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
48
45
  // environment
49
46
  NODE_ENV: process.env.NODE_ENV,
50
47
  JEST_WORKER_ID: process.env.JEST_WORKER_ID,
@@ -72,22 +72,16 @@ class InternalBuilder {
72
72
 
73
73
  // right now we only do filters on the specific table being queried
74
74
  addFilters(
75
+ tableName: string,
75
76
  query: KnexQuery,
76
- filters: SearchFilters | undefined,
77
- opts: { relationship?: boolean; tableName?: string }
77
+ filters: SearchFilters | undefined
78
78
  ): KnexQuery {
79
79
  function iterate(
80
80
  structure: { [key: string]: any },
81
81
  fn: (key: string, value: any) => void
82
82
  ) {
83
83
  for (let [key, value] of Object.entries(structure)) {
84
- const isRelationshipField = key.includes(".")
85
- if (!opts.relationship && !isRelationshipField) {
86
- fn(`${opts.tableName}.${key}`, value)
87
- }
88
- if (opts.relationship && isRelationshipField) {
89
- fn(key, value)
90
- }
84
+ fn(`${tableName}.${key}`, value)
91
85
  }
92
86
  }
93
87
  if (!filters) {
@@ -278,7 +272,7 @@ class InternalBuilder {
278
272
  if (foundOffset) {
279
273
  query = query.offset(foundOffset)
280
274
  }
281
- query = this.addFilters(query, filters, { tableName })
275
+ query = this.addFilters(tableName, query, filters)
282
276
  // add sorting to pre-query
283
277
  query = this.addSorting(query, json)
284
278
  // @ts-ignore
@@ -291,21 +285,20 @@ class InternalBuilder {
291
285
  preQuery = this.addSorting(preQuery, json)
292
286
  }
293
287
  // handle joins
294
- query = this.addRelationships(
288
+ return this.addRelationships(
295
289
  knex,
296
290
  preQuery,
297
291
  selectStatement,
298
292
  tableName,
299
293
  relationships
300
294
  )
301
- return this.addFilters(query, filters, { relationship: true })
302
295
  }
303
296
 
304
297
  update(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
305
298
  const { endpoint, body, filters } = json
306
299
  let query: KnexQuery = knex(endpoint.entityId)
307
300
  const parsedBody = parseBody(body)
308
- query = this.addFilters(query, filters, { tableName: endpoint.entityId })
301
+ query = this.addFilters(endpoint.entityId, query, filters)
309
302
  // mysql can't use returning
310
303
  if (opts.disableReturning) {
311
304
  return query.update(parsedBody)
@@ -317,7 +310,7 @@ class InternalBuilder {
317
310
  delete(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
318
311
  const { endpoint, filters } = json
319
312
  let query: KnexQuery = knex(endpoint.entityId)
320
- query = this.addFilters(query, filters, { tableName: endpoint.entityId })
313
+ query = this.addFilters(endpoint.entityId, query, filters)
321
314
  // mysql can't use returning
322
315
  if (opts.disableReturning) {
323
316
  return query.delete()
@@ -9,7 +9,6 @@ const airtable = require("./airtable")
9
9
  const mysql = require("./mysql")
10
10
  const arangodb = require("./arangodb")
11
11
  const rest = require("./rest")
12
- const googlesheets = require("./googlesheets")
13
12
  const { SourceNames } = require("../definitions/datasource")
14
13
 
15
14
  const DEFINITIONS = {
@@ -24,7 +23,6 @@ const DEFINITIONS = {
24
23
  [SourceNames.MYSQL]: mysql.schema,
25
24
  [SourceNames.ARANGODB]: arangodb.schema,
26
25
  [SourceNames.REST]: rest.schema,
27
- [SourceNames.GOOGLE_SHEETS]: googlesheets.schema,
28
26
  }
29
27
 
30
28
  const INTEGRATIONS = {
@@ -39,7 +37,6 @@ const INTEGRATIONS = {
39
37
  [SourceNames.MYSQL]: mysql.integration,
40
38
  [SourceNames.ARANGODB]: arangodb.integration,
41
39
  [SourceNames.REST]: rest.integration,
42
- [SourceNames.GOOGLE_SHEETS]: googlesheets.integration,
43
40
  }
44
41
 
45
42
  // optionally add oracle integration if the oracle binary can be installed
@@ -119,22 +119,6 @@ describe("SQL query builder", () => {
119
119
  })
120
120
  })
121
121
 
122
- it("should allow filtering on a related field", () => {
123
- const query = sql._query(generateReadJson({
124
- filters: {
125
- equal: {
126
- age: 10,
127
- "task.name": "task 1",
128
- },
129
- },
130
- }))
131
- // order of bindings changes because relationship filters occur outside inner query
132
- expect(query).toEqual({
133
- bindings: [10, limit, "task 1"],
134
- sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."age" = $1 limit $2) as "${TABLE_NAME}" where "task"."name" = $3`
135
- })
136
- })
137
-
138
122
  it("should test an create statement", () => {
139
123
  const query = sql._query(generateCreateJson(TABLE_NAME, {
140
124
  name: "Michael",
@@ -1,5 +1,6 @@
1
- import { SourceNames, SqlQuery } from "../definitions/datasource"
1
+ import { SqlQuery } from "../definitions/datasource"
2
2
  import { Datasource, Table } from "../definitions/common"
3
+ import { SourceNames } from "../definitions/datasource"
3
4
  import { DocumentTypes, SEPARATOR } from "../db/utils"
4
5
  import { FieldTypes, BuildSchemaErrors, InvalidColumns } from "../constants"
5
6
 
@@ -52,10 +53,7 @@ export function buildExternalTableId(datasourceId: string, tableName: string) {
52
53
  return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}`
53
54
  }
54
55
 
55
- export function breakExternalTableId(tableId: string | undefined) {
56
- if (!tableId) {
57
- return {}
58
- }
56
+ export function breakExternalTableId(tableId: string) {
59
57
  const parts = tableId.split(DOUBLE_SEPARATOR)
60
58
  let tableName = parts.pop()
61
59
  // if they need joined
@@ -129,12 +127,7 @@ export function isSQL(datasource: Datasource): boolean {
129
127
  if (!datasource || !datasource.source) {
130
128
  return false
131
129
  }
132
- const SQL = [
133
- SourceNames.POSTGRES,
134
- SourceNames.SQL_SERVER,
135
- SourceNames.MYSQL,
136
- SourceNames.ORACLE,
137
- ]
130
+ const SQL = [SourceNames.POSTGRES, SourceNames.SQL_SERVER, SourceNames.MYSQL]
138
131
  return SQL.indexOf(datasource.source) !== -1
139
132
  }
140
133
 
@@ -146,60 +139,11 @@ export function isIsoDateString(str: string) {
146
139
  return d.toISOString() === str
147
140
  }
148
141
 
149
- /**
150
- * This function will determine whether a column is a relationship and whether it
151
- * is currently valid. The reason for the validity check is that tables can be deleted
152
- * outside of Budibase control and if this is the case it will break Budibase relationships.
153
- * The tableIds is a list passed down from the main finalise tables function, which is
154
- * based on the tables that have just been fetched. This will only really be used on subsequent
155
- * fetches to the first one - if the user is periodically refreshing Budibase knowledge of tables.
156
- * @param column The column to check, to see if it is a valid relationship.
157
- * @param tableIds The IDs of the tables which currently exist.
158
- */
159
- function shouldCopyRelationship(
160
- column: { type: string; tableId?: string },
161
- tableIds: [string]
162
- ) {
163
- return (
164
- column.type === FieldTypes.LINK &&
165
- column.tableId &&
166
- tableIds.includes(column.tableId)
167
- )
168
- }
169
-
170
- /**
171
- * Similar function to the shouldCopyRelationship function, but instead this looks for options and boolean
172
- * types. It is possible to switch a string -> options and a number -> boolean (and vice versus) need to make
173
- * sure that these get copied over when tables are fetched. Also checks whether they are still valid, if a
174
- * column has changed type in the external database then copying it over may not be possible.
175
- * @param column The column to check for options or boolean type.
176
- * @param fetchedColumn The fetched column to check for the type in the external database.
177
- */
178
- function shouldCopySpecialColumn(
179
- column: { type: string },
180
- fetchedColumn: { type: string } | undefined
181
- ) {
182
- return (
183
- column.type === FieldTypes.OPTIONS ||
184
- column.type === FieldTypes.ARRAY ||
185
- ((!fetchedColumn || fetchedColumn.type === FieldTypes.NUMBER) &&
186
- column.type === FieldTypes.BOOLEAN)
187
- )
188
- }
189
-
190
- /**
191
- * Looks for columns which need to be copied over into the new table definitions, like relationships
192
- * and options types.
193
- * @param tableName The name of the table which is being checked.
194
- * @param table The specific table which is being checked.
195
- * @param entities All the tables that existed before - the old table definitions.
196
- * @param tableIds The IDs of the tables which exist now, to check if anything has been removed.
197
- */
142
+ // add the existing relationships from the entities if they exist, to prevent them from being overridden
198
143
  function copyExistingPropsOver(
199
144
  tableName: string,
200
145
  table: Table,
201
- entities: { [key: string]: any },
202
- tableIds: [string]
146
+ entities: { [key: string]: any }
203
147
  ) {
204
148
  if (entities && entities[tableName]) {
205
149
  if (entities[tableName].primaryDisplay) {
@@ -210,10 +154,12 @@ function copyExistingPropsOver(
210
154
  if (!existingTableSchema.hasOwnProperty(key)) {
211
155
  continue
212
156
  }
213
- const column = existingTableSchema[key]
214
157
  if (
215
- shouldCopyRelationship(column, tableIds) ||
216
- shouldCopySpecialColumn(column, table.schema[key])
158
+ existingTableSchema[key].type === FieldTypes.LINK ||
159
+ existingTableSchema[key].type === FieldTypes.OPTIONS ||
160
+ existingTableSchema[key].type === FieldTypes.ARRAY ||
161
+ ((!table.schema[key] || table.schema[key].type === FieldTypes.NUMBER) &&
162
+ existingTableSchema[key].type === FieldTypes.BOOLEAN)
217
163
  ) {
218
164
  table.schema[key] = existingTableSchema[key]
219
165
  }
@@ -222,13 +168,6 @@ function copyExistingPropsOver(
222
168
  return table
223
169
  }
224
170
 
225
- /**
226
- * Look through the final table definitions to see if anything needs to be
227
- * copied over from the old and if any errors have occurred mark them so
228
- * that the user can be made aware.
229
- * @param tables The list of tables that have been retrieved from the external database.
230
- * @param entities The old list of tables, if there was any to look for definitions in.
231
- */
232
171
  export function finaliseExternalTables(
233
172
  tables: { [key: string]: any },
234
173
  entities: { [key: string]: any }
@@ -236,8 +175,6 @@ export function finaliseExternalTables(
236
175
  const invalidColumns = Object.values(InvalidColumns)
237
176
  let finalTables: { [key: string]: any } = {}
238
177
  const errors: { [key: string]: string } = {}
239
- // @ts-ignore
240
- const tableIds: [string] = Object.values(tables).map(table => table._id)
241
178
  for (let [name, table] of Object.entries(tables)) {
242
179
  const schemaFields = Object.keys(table.schema)
243
180
  // make sure every table has a key
@@ -249,7 +186,7 @@ export function finaliseExternalTables(
249
186
  continue
250
187
  }
251
188
  // make sure all previous props have been added back
252
- finalTables[name] = copyExistingPropsOver(name, table, entities, tableIds)
189
+ finalTables[name] = copyExistingPropsOver(name, table, entities)
253
190
  }
254
191
  // sort the tables by name
255
192
  finalTables = Object.entries(finalTables)
@@ -9,60 +9,11 @@ const {
9
9
  } = require("@budibase/backend-core/permissions")
10
10
  const builderMiddleware = require("./builder")
11
11
  const { isWebhookEndpoint } = require("./utils")
12
- const { buildCsrfMiddleware } = require("@budibase/backend-core/auth")
13
- const { getAppId } = require("@budibase/backend-core/context")
14
12
 
15
13
  function hasResource(ctx) {
16
14
  return ctx.resourceId != null
17
15
  }
18
16
 
19
- const csrf = buildCsrfMiddleware()
20
-
21
- /**
22
- * Apply authorization to the requested resource:
23
- * - If this is a builder resource the user must be a builder.
24
- * - Builders can access all resources.
25
- * - Otherwise the user must have the required role.
26
- */
27
- const checkAuthorized = async (ctx, resourceRoles, permType, permLevel) => {
28
- // check if this is a builder api and the user is not a builder
29
- const isBuilder = ctx.user && ctx.user.builder && ctx.user.builder.global
30
- const isBuilderApi = permType === PermissionTypes.BUILDER
31
- if (isBuilderApi && !isBuilder) {
32
- return ctx.throw(403, "Not Authorized")
33
- }
34
-
35
- // check for resource authorization
36
- if (!isBuilder) {
37
- await checkAuthorizedResource(ctx, resourceRoles, permType, permLevel)
38
- }
39
- }
40
-
41
- const checkAuthorizedResource = async (
42
- ctx,
43
- resourceRoles,
44
- permType,
45
- permLevel
46
- ) => {
47
- // get the user's roles
48
- const roleId = ctx.roleId || BUILTIN_ROLE_IDS.PUBLIC
49
- const userRoles = await getUserRoleHierarchy(roleId, {
50
- idOnly: false,
51
- })
52
- const permError = "User does not have permission"
53
- // check if the user has the required role
54
- if (resourceRoles.length > 0) {
55
- // deny access if the user doesn't have the required resource role
56
- const found = userRoles.find(role => resourceRoles.indexOf(role._id) !== -1)
57
- if (!found) {
58
- ctx.throw(403, permError)
59
- }
60
- // fallback to the base permissions when no resource roles are found
61
- } else if (!doesHaveBasePermission(permType, permLevel, userRoles)) {
62
- ctx.throw(403, permError)
63
- }
64
- }
65
-
66
17
  module.exports =
67
18
  (permType, permLevel = null) =>
68
19
  async (ctx, next) => {
@@ -80,27 +31,40 @@ module.exports =
80
31
  // to find API endpoints which are builder focused
81
32
  await builderMiddleware(ctx, permType)
82
33
 
83
- // get the resource roles
84
- let resourceRoles = []
85
- const appId = getAppId()
86
- if (appId && hasResource(ctx)) {
87
- resourceRoles = await getRequiredResourceRole(permLevel, ctx)
88
- }
89
-
90
- // if the resource is public, proceed
91
- const isPublicResource = resourceRoles.includes(BUILTIN_ROLE_IDS.PUBLIC)
92
- if (isPublicResource) {
34
+ const isAuthed = ctx.isAuthenticated
35
+ // builders for now have permission to do anything
36
+ let isBuilder = ctx.user && ctx.user.builder && ctx.user.builder.global
37
+ const isBuilderApi = permType === PermissionTypes.BUILDER
38
+ if (isBuilder) {
93
39
  return next()
40
+ } else if (isBuilderApi && !isBuilder) {
41
+ return ctx.throw(403, "Not Authorized")
94
42
  }
95
43
 
96
- // check authenticated
97
- if (!ctx.isAuthenticated) {
98
- return ctx.throw(403, "Session not authenticated")
44
+ // need to check this first, in-case public access, don't check authed until last
45
+ const roleId = ctx.roleId || BUILTIN_ROLE_IDS.PUBLIC
46
+ const hierarchy = await getUserRoleHierarchy(ctx.appId, roleId, {
47
+ idOnly: false,
48
+ })
49
+ const permError = "User does not have permission"
50
+ let possibleRoleIds = []
51
+ if (hasResource(ctx)) {
52
+ possibleRoleIds = await getRequiredResourceRole(ctx.appId, permLevel, ctx)
53
+ }
54
+ // check if we found a role, if not fallback to base permissions
55
+ if (possibleRoleIds.length > 0) {
56
+ const found = hierarchy.find(
57
+ role => possibleRoleIds.indexOf(role._id) !== -1
58
+ )
59
+ return found ? next() : ctx.throw(403, permError)
60
+ } else if (!doesHaveBasePermission(permType, permLevel, hierarchy)) {
61
+ ctx.throw(403, permError)
99
62
  }
100
63
 
101
- // check authorized
102
- await checkAuthorized(ctx, resourceRoles, permType, permLevel)
64
+ // if they are not authed, then anything using the authorized middleware will fail
65
+ if (!isAuthed) {
66
+ ctx.throw(403, "Session not authenticated")
67
+ }
103
68
 
104
- // csrf protection
105
- return csrf(ctx, next)
69
+ return next()
106
70
  }
@@ -5,7 +5,7 @@ const {
5
5
  checkDebounce,
6
6
  setDebounce,
7
7
  } = require("../utilities/redis")
8
- const { getDB } = require("@budibase/backend-core/db")
8
+ const CouchDB = require("../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 = getDB(appId)
51
+ const db = new CouchDB(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)