@saltcorn/server 0.9.6-beta.10 → 0.9.6-beta.12

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/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@saltcorn/server",
3
- "version": "0.9.6-beta.10",
3
+ "version": "0.9.6-beta.12",
4
4
  "description": "Server app for Saltcorn, open-source no-code platform",
5
5
  "homepage": "https://saltcorn.com",
6
6
  "main": "index.js",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
9
  "@aws-sdk/client-s3": "^3.451.0",
10
- "@saltcorn/base-plugin": "0.9.6-beta.10",
11
- "@saltcorn/builder": "0.9.6-beta.10",
12
- "@saltcorn/data": "0.9.6-beta.10",
13
- "@saltcorn/admin-models": "0.9.6-beta.10",
14
- "@saltcorn/filemanager": "0.9.6-beta.10",
15
- "@saltcorn/markup": "0.9.6-beta.10",
16
- "@saltcorn/plugins-loader": "0.9.6-beta.10",
17
- "@saltcorn/sbadmin2": "0.9.6-beta.10",
10
+ "@saltcorn/base-plugin": "0.9.6-beta.12",
11
+ "@saltcorn/builder": "0.9.6-beta.12",
12
+ "@saltcorn/data": "0.9.6-beta.12",
13
+ "@saltcorn/admin-models": "0.9.6-beta.12",
14
+ "@saltcorn/filemanager": "0.9.6-beta.12",
15
+ "@saltcorn/markup": "0.9.6-beta.12",
16
+ "@saltcorn/plugins-loader": "0.9.6-beta.12",
17
+ "@saltcorn/sbadmin2": "0.9.6-beta.12",
18
18
  "@socket.io/cluster-adapter": "^0.2.1",
19
19
  "@socket.io/sticky": "^1.0.1",
20
20
  "adm-zip": "0.5.10",
@@ -1373,15 +1373,15 @@ async function common_done(res, viewnameOrElem, isWeb = true) {
1373
1373
  });
1374
1374
  }
1375
1375
  if (res.eval_js) await handle(res.eval_js, eval_it);
1376
-
1377
- if (res.goto && !isWeb)
1378
- // TODO ch
1379
- notifyAlert({
1380
- type: "danger",
1381
- text: "Goto is not supported in a mobile deployment.",
1382
- });
1383
1376
  else if (res.goto) {
1384
- if (res.target === "_blank") window.open(res.goto, "_blank").focus();
1377
+ if (!isWeb) {
1378
+ const next = new URL(res.goto, "http://localhost");
1379
+ const pathname = next.pathname;
1380
+ if (pathname.startsWith("/view/") || pathname.startsWith("/page/")) {
1381
+ const route = `get${pathname}${next.search ? "?" + next.search : ""}`;
1382
+ await parent.handleRoute(route);
1383
+ } else parent.cordova.InAppBrowser.open(res.goto, "_system");
1384
+ } else if (res.target === "_blank") window.open(res.goto, "_blank").focus();
1385
1385
  else {
1386
1386
  const prev = new URL(window.location.href);
1387
1387
  const next = new URL(res.goto, prev.origin);
package/routes/api.js CHANGED
@@ -260,6 +260,12 @@ router.get(
260
260
  );
261
261
  if (!table) {
262
262
  getState().log(3, `API get ${tableName} table not found`);
263
+ getState().log(
264
+ 6,
265
+ `API get failure additonal info: URL=${req.originalUrl}${
266
+ getState().getConfig("log_ip_address", false) ? ` IP=${req.ip}` : ""
267
+ }`
268
+ );
263
269
  res.status(404).json({ error: req.__("Not found") });
264
270
  return;
265
271
  }
package/routes/fields.js CHANGED
@@ -1149,7 +1149,7 @@ router.post(
1149
1149
  const jf = table.getField(ref);
1150
1150
  const jtable = Table.findOne(jf.reftable_name);
1151
1151
  const jrow = await jtable.getRow(
1152
- { [jtable.pk_name]: row[ref] },
1152
+ { [jtable.pk_name]: row[ref]?.[jtable.pk_name] || row[ref] },
1153
1153
  { forUser: req.user, forPublic: !req.user }
1154
1154
  );
1155
1155
  row[ref] = jrow;
@@ -391,6 +391,27 @@ describe("Field Endpoints", () => {
391
391
  })
392
392
  .expect(toBeTrue((r) => +r.text > 2));
393
393
  });
394
+ it("should show calculated field with two single joinfields", async () => {
395
+ const loginCookie = await getAdminLoginCookie();
396
+ const table = Table.findOne({ name: "patients" });
397
+ await Field.create({
398
+ table,
399
+ label: "pagesp12",
400
+ type: "Integer",
401
+ calculated: true,
402
+ stored: true,
403
+ expression: "favbook.pages+1+favbook.id",
404
+ });
405
+ const app = await getApp({ disableCsrf: true });
406
+
407
+ await request(app)
408
+ .post("/field/show-calculated/patients/pagesp12/show")
409
+ .set("Cookie", loginCookie)
410
+ .send({
411
+ id: 1,
412
+ })
413
+ .expect(toBeTrue((r) => +r.text > 2));
414
+ });
394
415
  it("should show calculated field with double joinfield", async () => {
395
416
  const loginCookie = await getAdminLoginCookie();
396
417
  const table = Table.findOne({ name: "readings" });
@@ -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();