@saltcorn/server 1.1.1-beta.5 → 1.1.1-beta.7

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 (153) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/auth/admin.js +8 -0
  3. package/locales/en.json +16 -1
  4. package/markup/admin.js +8 -3
  5. package/markup/blockly.js +4 -4
  6. package/package.json +9 -9
  7. package/public/blockly/blockly_compressed.js +2016 -0
  8. package/public/blockly/blockly_compressed.js.map +1 -0
  9. package/public/blockly/blocks_compressed.js +212 -0
  10. package/public/blockly/blocks_compressed.js.map +1 -0
  11. package/public/blockly/javascript_compressed.js +121 -0
  12. package/public/blockly/javascript_compressed.js.map +1 -0
  13. package/public/blockly/msg/ab.js +440 -0
  14. package/public/blockly/msg/ace.js +440 -0
  15. package/public/blockly/msg/af.js +440 -0
  16. package/public/blockly/msg/am.js +440 -0
  17. package/public/blockly/msg/ar.js +440 -0
  18. package/public/blockly/msg/ast.js +440 -0
  19. package/public/blockly/msg/az.js +440 -0
  20. package/public/blockly/msg/ba.js +440 -0
  21. package/public/blockly/msg/bcc.js +440 -0
  22. package/public/blockly/msg/be-tarask.js +440 -0
  23. package/public/blockly/msg/be.js +440 -0
  24. package/public/blockly/msg/bg.js +440 -0
  25. package/public/blockly/msg/bn.js +440 -0
  26. package/public/blockly/msg/br.js +440 -0
  27. package/public/blockly/msg/bs.js +440 -0
  28. package/public/blockly/msg/ca.js +440 -0
  29. package/public/blockly/msg/cdo.js +440 -0
  30. package/public/blockly/msg/cs.js +440 -0
  31. package/public/blockly/msg/da.js +440 -0
  32. package/public/blockly/msg/de.js +440 -0
  33. package/public/blockly/msg/diq.js +440 -0
  34. package/public/blockly/msg/dty.js +440 -0
  35. package/public/blockly/msg/ee.js +440 -0
  36. package/public/blockly/msg/el.js +440 -0
  37. package/public/blockly/msg/en-gb.js +440 -0
  38. package/public/blockly/msg/en.js +440 -0
  39. package/public/blockly/msg/eo.js +440 -0
  40. package/public/blockly/msg/es.js +440 -0
  41. package/public/blockly/msg/et.js +440 -0
  42. package/public/blockly/msg/eu.js +440 -0
  43. package/public/blockly/msg/fa.js +440 -0
  44. package/public/blockly/msg/fi.js +440 -0
  45. package/public/blockly/msg/fo.js +440 -0
  46. package/public/blockly/msg/fr.js +440 -0
  47. package/public/blockly/msg/frr.js +440 -0
  48. package/public/blockly/msg/gl.js +440 -0
  49. package/public/blockly/msg/gn.js +440 -0
  50. package/public/blockly/msg/gor.js +440 -0
  51. package/public/blockly/msg/ha.js +440 -0
  52. package/public/blockly/msg/hak.js +440 -0
  53. package/public/blockly/msg/he.js +440 -0
  54. package/public/blockly/msg/hi.js +440 -0
  55. package/public/blockly/msg/hr.js +440 -0
  56. package/public/blockly/msg/hrx.js +440 -0
  57. package/public/blockly/msg/hu.js +440 -0
  58. package/public/blockly/msg/hy.js +440 -0
  59. package/public/blockly/msg/ia.js +440 -0
  60. package/public/blockly/msg/id.js +440 -0
  61. package/public/blockly/msg/ig.js +440 -0
  62. package/public/blockly/msg/inh.js +440 -0
  63. package/public/blockly/msg/is.js +440 -0
  64. package/public/blockly/msg/it.js +440 -0
  65. package/public/blockly/msg/ja.js +440 -0
  66. package/public/blockly/msg/ka.js +440 -0
  67. package/public/blockly/msg/kab.js +440 -0
  68. package/public/blockly/msg/kbd-cyrl.js +440 -0
  69. package/public/blockly/msg/km.js +440 -0
  70. package/public/blockly/msg/kn.js +440 -0
  71. package/public/blockly/msg/ko.js +440 -0
  72. package/public/blockly/msg/ksh.js +440 -0
  73. package/public/blockly/msg/ku-latn.js +440 -0
  74. package/public/blockly/msg/ky.js +440 -0
  75. package/public/blockly/msg/la.js +440 -0
  76. package/public/blockly/msg/lb.js +440 -0
  77. package/public/blockly/msg/lki.js +440 -0
  78. package/public/blockly/msg/lo.js +440 -0
  79. package/public/blockly/msg/lrc.js +440 -0
  80. package/public/blockly/msg/lt.js +440 -0
  81. package/public/blockly/msg/lv.js +440 -0
  82. package/public/blockly/msg/mg.js +440 -0
  83. package/public/blockly/msg/mk.js +440 -0
  84. package/public/blockly/msg/ml.js +440 -0
  85. package/public/blockly/msg/mnw.js +440 -0
  86. package/public/blockly/msg/ms.js +440 -0
  87. package/public/blockly/msg/msg.d.ts +444 -0
  88. package/public/blockly/msg/my.js +440 -0
  89. package/public/blockly/msg/mzn.js +440 -0
  90. package/public/blockly/msg/nb.js +440 -0
  91. package/public/blockly/msg/ne.js +440 -0
  92. package/public/blockly/msg/nl.js +440 -0
  93. package/public/blockly/msg/oc.js +440 -0
  94. package/public/blockly/msg/olo.js +440 -0
  95. package/public/blockly/msg/pa.js +440 -0
  96. package/public/blockly/msg/pl.js +440 -0
  97. package/public/blockly/msg/pms.js +440 -0
  98. package/public/blockly/msg/ps.js +440 -0
  99. package/public/blockly/msg/pt-br.js +440 -0
  100. package/public/blockly/msg/pt.js +440 -0
  101. package/public/blockly/msg/ro.js +440 -0
  102. package/public/blockly/msg/ru.js +440 -0
  103. package/public/blockly/msg/sc.js +440 -0
  104. package/public/blockly/msg/sco.js +440 -0
  105. package/public/blockly/msg/sd.js +440 -0
  106. package/public/blockly/msg/shn.js +440 -0
  107. package/public/blockly/msg/si.js +440 -0
  108. package/public/blockly/msg/sk.js +440 -0
  109. package/public/blockly/msg/skr-arab.js +440 -0
  110. package/public/blockly/msg/sl.js +440 -0
  111. package/public/blockly/msg/smn.js +440 -0
  112. package/public/blockly/msg/sq.js +440 -0
  113. package/public/blockly/msg/sr-latn.js +440 -0
  114. package/public/blockly/msg/sr.js +440 -0
  115. package/public/blockly/msg/sv.js +440 -0
  116. package/public/blockly/msg/sw.js +440 -0
  117. package/public/blockly/msg/ta.js +440 -0
  118. package/public/blockly/msg/tcy.js +440 -0
  119. package/public/blockly/msg/te.js +440 -0
  120. package/public/blockly/msg/th.js +440 -0
  121. package/public/blockly/msg/ti.js +440 -0
  122. package/public/blockly/msg/tl.js +440 -0
  123. package/public/blockly/msg/tlh.js +440 -0
  124. package/public/blockly/msg/tr.js +440 -0
  125. package/public/blockly/msg/ug-arab.js +440 -0
  126. package/public/blockly/msg/uk.js +440 -0
  127. package/public/blockly/msg/ur.js +440 -0
  128. package/public/blockly/msg/uz.js +440 -0
  129. package/public/blockly/msg/vi.js +440 -0
  130. package/public/blockly/msg/xmf.js +440 -0
  131. package/public/blockly/msg/yo.js +440 -0
  132. package/public/blockly/msg/yue.js +440 -0
  133. package/public/blockly/msg/zgh.js +440 -0
  134. package/public/blockly/msg/zh-hans.js +440 -0
  135. package/public/blockly/msg/zh-hant.js +440 -0
  136. package/public/saltcorn-common.js +8 -1
  137. package/public/saltcorn.js +12 -0
  138. package/routes/actions.js +32 -25
  139. package/routes/admin.js +90 -63
  140. package/routes/common_lists.js +46 -24
  141. package/routes/fields.js +31 -9
  142. package/routes/list.js +17 -4
  143. package/routes/notifications.js +27 -20
  144. package/routes/pageedit.js +14 -13
  145. package/routes/plugins.js +0 -32
  146. package/routes/tables.js +173 -92
  147. package/routes/utils.js +27 -0
  148. package/routes/view.js +2 -1
  149. package/routes/viewedit.js +14 -13
  150. package/serve.js +52 -1
  151. package/tests/api.test.js +0 -18
  152. package/tests/plugins.test.js +2 -2
  153. package/wrapper.js +80 -42
package/routes/list.js CHANGED
@@ -24,7 +24,11 @@ const {
24
24
  form,
25
25
  } = require("@saltcorn/markup/tags");
26
26
  const Table = require("@saltcorn/data/models/table");
27
- const { isAdmin, error_catcher } = require("./utils");
27
+ const {
28
+ isAdmin,
29
+ error_catcher,
30
+ isAdminOrHasConfigMinRole,
31
+ } = require("./utils");
28
32
  const moment = require("moment");
29
33
  const { getState } = require("@saltcorn/data/db/state");
30
34
 
@@ -49,7 +53,10 @@ module.exports = router;
49
53
  */
50
54
  router.get(
51
55
  "/_versions/:tableName/:id",
52
- isAdmin,
56
+ isAdminOrHasConfigMinRole([
57
+ "min_role_edit_tables",
58
+ "min_role_inspect_tables",
59
+ ]),
53
60
  error_catcher(async (req, res) => {
54
61
  const { tableName, id } = req.params;
55
62
  const table = Table.findOne({ name: tableName });
@@ -97,7 +104,10 @@ router.get(
97
104
  */
98
105
  router.post(
99
106
  "/_restore/:tableName/:id/:_version",
100
- isAdmin,
107
+ isAdminOrHasConfigMinRole([
108
+ "min_role_edit_tables",
109
+ "min_role_inspect_tables",
110
+ ]),
101
111
  error_catcher(async (req, res) => {
102
112
  const { tableName, id, _version } = req.params;
103
113
  const table = Table.findOne({ name: tableName });
@@ -226,7 +236,10 @@ const arrangeIdFirst = (flds) => {
226
236
  */
227
237
  router.get(
228
238
  "/:tname",
229
- isAdmin,
239
+ isAdminOrHasConfigMinRole([
240
+ "min_role_edit_tables",
241
+ "min_role_inspect_tables",
242
+ ]),
230
243
  error_catcher(async (req, res) => {
231
244
  const { tname } = req.params;
232
245
  const table = Table.findOne({ name: tname });
@@ -204,26 +204,31 @@ router.post(
204
204
  req.flash("error", msg);
205
205
  res.redirect("/auth/login");
206
206
  } else res.json({ error: msg });
207
- } else if (!getState().getConfig("pwa_share_to_enabled", false)) {
208
- const msg = req.__("Sharing not enabled");
209
- if (!req.smr) {
210
- req.flash("error", msg);
211
- res.redirect("/");
212
- } else res.json({ error: msg });
213
207
  } else {
214
- Trigger.emitEvent("ReceiveMobileShareData", null, req.user, {
215
- row: req.body,
208
+ const receiveShareTriggers = Trigger.find({
209
+ when_trigger: "ReceiveMobileShareData",
216
210
  });
217
- if (!req.smr) {
218
- req.flash(
219
- "success",
220
- req.__(
221
- "Shared: %s",
222
- req.body.title || req.body.text || req.body.url || ""
223
- )
224
- );
225
- res.status(303).redirect("/");
226
- } else res.json({ success: "ok" });
211
+ if (receiveShareTriggers.length === 0) {
212
+ const msg = req.__("Sharing not enabled");
213
+ if (!req.smr) {
214
+ req.flash("error", msg);
215
+ res.redirect("/");
216
+ } else res.json({ error: msg });
217
+ } else {
218
+ Trigger.emitEvent("ReceiveMobileShareData", null, req.user, {
219
+ row: req.body,
220
+ });
221
+ if (!req.smr) {
222
+ req.flash(
223
+ "success",
224
+ req.__(
225
+ "Shared: %s",
226
+ req.body.title || req.body.text || req.body.url || ""
227
+ )
228
+ );
229
+ res.status(303).redirect("/");
230
+ } else res.json({ success: "ok" });
231
+ }
227
232
  }
228
233
  })
229
234
  );
@@ -240,8 +245,10 @@ router.get(
240
245
  };
241
246
  const site_logo = state.getConfig("site_logo_id");
242
247
  const pwa_icons = state.getConfig("pwa_icons");
243
- const pwa_share_to_enabled = state.getConfig("pwa_share_to_enabled", false);
244
- if (pwa_share_to_enabled) {
248
+ const receiveShareTriggers = Trigger.find({
249
+ when_trigger: "ReceiveMobileShareData",
250
+ });
251
+ if (receiveShareTriggers.length > 0) {
245
252
  manifest.share_target = {
246
253
  action: "/notifications/share-handler",
247
254
  method: "POST",
@@ -30,6 +30,7 @@ const {
30
30
  addOnDoneRedirect,
31
31
  is_relative_url,
32
32
  setRole,
33
+ isAdminOrHasConfigMinRole,
33
34
  } = require("./utils.js");
34
35
  const { asyncMap } = require("@saltcorn/data/utils");
35
36
  const {
@@ -278,7 +279,7 @@ const getRootPageForm = (pages, pageGroups, roles, req) => {
278
279
  noSubmitButton: true,
279
280
  onChange: "saveAndContinue(this)",
280
281
  blurb: req.__(
281
- "The root page is the page that is served when the user visits the home location (/). This can be set for each user role."
282
+ "The home page is the page that is served when the user visits the home location (/). This can be set for each user role."
282
283
  ),
283
284
  fields: roles.map(
284
285
  (r) =>
@@ -314,7 +315,7 @@ const getRootPageForm = (pages, pageGroups, roles, req) => {
314
315
  */
315
316
  router.get(
316
317
  "/",
317
- isAdmin,
318
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
318
319
  error_catcher(async (req, res) => {
319
320
  const pageq = {};
320
321
  let filterOnTag;
@@ -357,7 +358,7 @@ router.get(
357
358
  },
358
359
  {
359
360
  type: "card",
360
- title: req.__("Root pages"),
361
+ title: req.__("Home pages"),
361
362
  titleAjaxIndicator: true,
362
363
  contents: renderForm(
363
364
  getRootPageForm(pages, pageGroups, roles, req),
@@ -425,7 +426,7 @@ const wrap = (contents, noCard, req, page) => ({
425
426
  */
426
427
  router.get(
427
428
  "/edit-properties/:pagename",
428
- isAdmin,
429
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
429
430
  error_catcher(async (req, res) => {
430
431
  const { pagename } = req.params;
431
432
  const page = Page.findOne({ name: pagename });
@@ -456,7 +457,7 @@ router.get(
456
457
  */
457
458
  router.get(
458
459
  "/new",
459
- isAdmin,
460
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
460
461
  error_catcher(async (req, res) => {
461
462
  const form = await pagePropertiesForm(req, true);
462
463
  res.sendWrap(
@@ -474,7 +475,7 @@ router.get(
474
475
  */
475
476
  router.post(
476
477
  "/edit-properties",
477
- isAdmin,
478
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
478
479
  error_catcher(async (req, res) => {
479
480
  const form = await pagePropertiesForm(req, !req.body.id);
480
481
  form.hidden("id");
@@ -652,7 +653,7 @@ const getEditPageWithHtmlFile = async (req, res, page) => {
652
653
  */
653
654
  router.get(
654
655
  "/edit/:pagename",
655
- isAdmin,
656
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
656
657
  error_catcher(async (req, res) => {
657
658
  const { pagename } = req.params;
658
659
  const [page] = await Page.find({ name: pagename });
@@ -674,7 +675,7 @@ router.get(
674
675
  */
675
676
  router.post(
676
677
  "/edit/:pagename",
677
- isAdmin,
678
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
678
679
  error_catcher(async (req, res) => {
679
680
  const { pagename } = req.params;
680
681
 
@@ -765,7 +766,7 @@ router.post(
765
766
  */
766
767
  router.post(
767
768
  "/delete/:id",
768
- isAdmin,
769
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
769
770
  error_catcher(async (req, res) => {
770
771
  const { id } = req.params;
771
772
  const page = await Page.findOne({ id });
@@ -787,7 +788,7 @@ router.post(
787
788
  */
788
789
  router.post(
789
790
  "/set_root_page",
790
- isAdmin,
791
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
791
792
  error_catcher(async (req, res) => {
792
793
  const pages = await Page.find({}, { orderBy: "name" });
793
794
  const pageGroups = await PageGroup.find({}, { orderBy: "name" });
@@ -815,7 +816,7 @@ router.post(
815
816
  */
816
817
  router.post(
817
818
  "/add-to-menu/:id",
818
- isAdmin,
819
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
819
820
  error_catcher(async (req, res) => {
820
821
  const { id } = req.params;
821
822
  const page = Page.findOne({ id });
@@ -845,7 +846,7 @@ router.post(
845
846
  */
846
847
  router.post(
847
848
  "/clone/:id",
848
- isAdmin,
849
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
849
850
  error_catcher(async (req, res) => {
850
851
  const { id } = req.params;
851
852
  const page = await Page.findOne({ id });
@@ -870,7 +871,7 @@ router.post(
870
871
  */
871
872
  router.post(
872
873
  "/setrole/:id",
873
- isAdmin,
874
+ isAdminOrHasConfigMinRole("min_role_edit_pages"),
874
875
  error_catcher(async (req, res) => {
875
876
  await setRole(req, res, Page);
876
877
  })
package/routes/plugins.js CHANGED
@@ -1182,38 +1182,6 @@ router.get(
1182
1182
  })
1183
1183
  );
1184
1184
 
1185
- /**
1186
- * @name get/pubdeps/:plugin/:dependency/:version/*
1187
- * @function
1188
- * @memberof module:routes/plugins~pluginsRouter
1189
- * @function
1190
- */
1191
- router.get(
1192
- "/pubdeps/:plugin/:dependency/:version/*",
1193
- error_catcher(async (req, res) => {
1194
- const { plugin, dependency } = req.params;
1195
- const filepath = req.params[0];
1196
-
1197
- const pluginObj = getState().plugins[plugin];
1198
- if (
1199
- pluginObj &&
1200
- pluginObj.serve_dependencies &&
1201
- pluginObj.serve_dependencies[dependency]
1202
- ) {
1203
- const deppath = path.dirname(pluginObj.serve_dependencies[dependency]);
1204
- const safeFile = path
1205
- .normalize(filepath)
1206
- .replace(/^(\.\.(\/|\\|$))+/, "");
1207
- const abspath = path.join(deppath, safeFile);
1208
- if (fs.existsSync(abspath)) res.sendFile(abspath, { maxAge: "100d" });
1209
- //100d
1210
- else res.status(404).send(req.__("Not found"));
1211
- } else {
1212
- res.status(404).send(req.__("Not found"));
1213
- }
1214
- })
1215
- );
1216
-
1217
1185
  /**
1218
1186
  * @name get/info/:name
1219
1187
  * @function