@saltcorn/server 0.9.6-beta.2 → 0.9.6-beta.20

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 (49) hide show
  1. package/app.js +6 -1
  2. package/auth/admin.js +55 -53
  3. package/auth/routes.js +28 -10
  4. package/auth/testhelp.js +86 -0
  5. package/help/Field label.tmd +11 -0
  6. package/help/Field types.tmd +39 -0
  7. package/help/Ownership field.tmd +76 -0
  8. package/help/Ownership formula.tmd +75 -0
  9. package/help/Table roles.tmd +20 -0
  10. package/help/User groups.tmd +35 -0
  11. package/load_plugins.js +33 -5
  12. package/locales/en.json +29 -1
  13. package/locales/it.json +3 -2
  14. package/markup/admin.js +1 -0
  15. package/markup/forms.js +5 -1
  16. package/package.json +9 -9
  17. package/public/log_viewer_utils.js +32 -0
  18. package/public/mermaid.min.js +705 -306
  19. package/public/saltcorn-builder.css +23 -0
  20. package/public/saltcorn-common.js +248 -80
  21. package/public/saltcorn.css +80 -0
  22. package/public/saltcorn.js +86 -2
  23. package/restart_watcher.js +1 -0
  24. package/routes/actions.js +27 -0
  25. package/routes/admin.js +175 -64
  26. package/routes/api.js +6 -0
  27. package/routes/common_lists.js +42 -32
  28. package/routes/fields.js +70 -42
  29. package/routes/homepage.js +2 -0
  30. package/routes/index.js +2 -0
  31. package/routes/menu.js +69 -4
  32. package/routes/notifications.js +90 -10
  33. package/routes/pageedit.js +18 -13
  34. package/routes/plugins.js +11 -2
  35. package/routes/registry.js +289 -0
  36. package/routes/search.js +10 -4
  37. package/routes/tables.js +51 -27
  38. package/routes/tenant.js +4 -15
  39. package/routes/utils.js +25 -8
  40. package/routes/view.js +1 -1
  41. package/routes/viewedit.js +11 -7
  42. package/serve.js +27 -5
  43. package/tests/edit.test.js +426 -0
  44. package/tests/fields.test.js +21 -0
  45. package/tests/filter.test.js +68 -0
  46. package/tests/page.test.js +2 -2
  47. package/tests/plugins.test.js +2 -0
  48. package/tests/sync.test.js +59 -0
  49. package/wrapper.js +4 -1
@@ -9,6 +9,7 @@ const {
9
9
  toInclude,
10
10
  toSucceed,
11
11
  } = require("../auth/testhelp");
12
+ const load_plugins = require("../load_plugins");
12
13
  const db = require("@saltcorn/data/db");
13
14
  const { sleep } = require("@saltcorn/data/tests/mocks");
14
15
 
@@ -16,6 +17,7 @@ const Table = require("@saltcorn/data/models/table");
16
17
  const TableConstraint = require("@saltcorn/data/models/table_constraints");
17
18
  const Field = require("@saltcorn/data/models/field");
18
19
  const User = require("@saltcorn/data/models/user");
20
+ const Plugin = require("@saltcorn/data/models/plugin");
19
21
 
20
22
  beforeAll(async () => {
21
23
  await resetToFixtures();
@@ -35,6 +37,27 @@ const initSyncInfo = async (tbls) => {
35
37
  }
36
38
  };
37
39
 
40
+ const createAnswersTbl = async () => {
41
+ await load_plugins.loadAndSaveNewPlugin(
42
+ new Plugin({
43
+ name: "json",
44
+ source: "npm",
45
+ location: "@saltcorn/json",
46
+ version: "latest",
47
+ })
48
+ );
49
+ const table = await Table.create("Answers", {
50
+ min_role_read: 100,
51
+ min_role_write: 100,
52
+ });
53
+ await Field.create({
54
+ table,
55
+ name: "answer",
56
+ label: "Answer",
57
+ type: "JSON",
58
+ });
59
+ };
60
+
38
61
  describe("load remote insert/updates", () => {
39
62
  if (!db.isSQLite) {
40
63
  beforeAll(async () => {
@@ -416,6 +439,42 @@ describe("Upload changes", () => {
416
439
  });
417
440
  });
418
441
 
442
+ it("upload json", async () => {
443
+ await createAnswersTbl();
444
+ const table = Table.findOne({ name: "Answers" });
445
+ expect(table).toBeDefined();
446
+ const app = await getApp({ disableCsrf: true });
447
+ const loginCookie = await getAdminLoginCookie();
448
+ const rows = [
449
+ {
450
+ id: 1,
451
+ answer: true,
452
+ },
453
+ {
454
+ id: 2,
455
+ answer: false,
456
+ },
457
+ {
458
+ id: 3,
459
+ answer: 1,
460
+ },
461
+ {
462
+ id: 4,
463
+ answer: ["latte", "americano", "filter"],
464
+ },
465
+ ];
466
+ const resp = await doUpload(app, loginCookie, new Date().valueOf(), {
467
+ Answers: {
468
+ inserts: rows,
469
+ },
470
+ });
471
+ expect(resp.status).toBe(200);
472
+ const { syncDir } = resp._body;
473
+ const result = await getResult(app, loginCookie, syncDir);
474
+ expect(result).toBeDefined();
475
+ expect(await table.getRows()).toEqual(rows);
476
+ });
477
+
419
478
  it("handles inserts with TableConstraint conflicts", async () => {
420
479
  const books = Table.findOne({ name: "books" });
421
480
  const oldCount = await books.countRows();
package/wrapper.js CHANGED
@@ -170,6 +170,7 @@ const get_headers = (req, version_tag, description, extras = []) => {
170
170
  const favicon = state.getConfig("favicon_id", null);
171
171
  const notification_in_menu = state.getConfig("notification_in_menu");
172
172
  const pwa_enabled = state.getConfig("pwa_enabled");
173
+ const is_root = req.user?.role_id === 1;
173
174
 
174
175
  const iconHeader = favicon
175
176
  ? [
@@ -219,7 +220,9 @@ const get_headers = (req, version_tag, description, extras = []) => {
219
220
  from_cfg.push({ scriptBody: domReady(`check_saltcorn_notifications()`) });
220
221
  if (pwa_enabled) {
221
222
  from_cfg.push({
222
- headerTag: `<link rel="manifest" href="/notifications/manifest.json">`,
223
+ headerTag: `<link rel="manifest" href="/notifications/manifest.json${
224
+ is_root ? new Date().valueOf() : ""
225
+ }">`,
223
226
  });
224
227
  from_cfg.push({
225
228
  scriptBody: `if('serviceWorker' in navigator) {