@saltcorn/server 1.1.0-beta.7 → 1.1.0-beta.9

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": "1.1.0-beta.7",
3
+ "version": "1.1.0-beta.9",
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": "1.1.0-beta.7",
11
- "@saltcorn/builder": "1.1.0-beta.7",
12
- "@saltcorn/data": "1.1.0-beta.7",
13
- "@saltcorn/admin-models": "1.1.0-beta.7",
14
- "@saltcorn/filemanager": "1.1.0-beta.7",
15
- "@saltcorn/markup": "1.1.0-beta.7",
16
- "@saltcorn/plugins-loader": "1.1.0-beta.7",
17
- "@saltcorn/sbadmin2": "1.1.0-beta.7",
10
+ "@saltcorn/base-plugin": "1.1.0-beta.9",
11
+ "@saltcorn/builder": "1.1.0-beta.9",
12
+ "@saltcorn/data": "1.1.0-beta.9",
13
+ "@saltcorn/admin-models": "1.1.0-beta.9",
14
+ "@saltcorn/filemanager": "1.1.0-beta.9",
15
+ "@saltcorn/markup": "1.1.0-beta.9",
16
+ "@saltcorn/plugins-loader": "1.1.0-beta.9",
17
+ "@saltcorn/sbadmin2": "1.1.0-beta.9",
18
18
  "@socket.io/cluster-adapter": "^0.2.1",
19
19
  "@socket.io/sticky": "^1.0.1",
20
20
  "adm-zip": "0.5.10",
package/routes/admin.js CHANGED
@@ -1741,8 +1741,8 @@ router.post(
1741
1741
 
1742
1742
  let altname = await tenant_letsencrypt_name(subdomain);
1743
1743
 
1744
- if (!altname || domain) {
1745
- req.json({ error: "Set Base URL for both tenant and root first." });
1744
+ if (!altname || !domain) {
1745
+ res.json({ error: "Set Base URL for both tenant and root first." });
1746
1746
  return;
1747
1747
  }
1748
1748
 
@@ -1759,13 +1759,14 @@ router.post(
1759
1759
 
1760
1760
  await greenlock.sites.add({
1761
1761
  subject: altname,
1762
+ altnames: [altname],
1762
1763
  });
1763
1764
  // letsencrypt
1764
1765
  const tenant_letsencrypt_sites = getState().getConfig(
1765
1766
  "tenant_letsencrypt_sites",
1766
1767
  []
1767
1768
  );
1768
- await getState().setConfig(tenant_letsencrypt_sites, [
1769
+ await getState().setConfig("tenant_letsencrypt_sites", [
1769
1770
  altname,
1770
1771
  ...tenant_letsencrypt_sites,
1771
1772
  ]);
@@ -1775,12 +1776,10 @@ router.post(
1775
1776
  notify: "Certificate added, please restart server",
1776
1777
  });
1777
1778
  } catch (e) {
1778
- req.flash("error", e.message);
1779
- res.redirect("/useradmin/ssl");
1779
+ res.json({ error: e.message });
1780
1780
  }
1781
1781
  } else {
1782
- req.flash("error", req.__("Not possible for tenant"));
1783
- res.redirect("/useradmin/ssl");
1782
+ res.json({ error: req.__("Not possible for tenant") });
1784
1783
  }
1785
1784
  })
1786
1785
  );
@@ -1849,7 +1848,7 @@ router.post(
1849
1848
  "tenant_letsencrypt_sites",
1850
1849
  []
1851
1850
  );
1852
- await getState().setConfig(tenant_letsencrypt_sites, [
1851
+ await getState().setConfig("tenant_letsencrypt_sites", [
1853
1852
  ...altnames,
1854
1853
  ...tenant_letsencrypt_sites,
1855
1854
  ]);
package/routes/tenant.js CHANGED
@@ -58,6 +58,7 @@ const {
58
58
  save_config_from_form,
59
59
  } = require("../markup/admin.js");
60
60
  const { getConfig } = require("@saltcorn/data/models/config");
61
+ const path = require("path");
61
62
  //const {quote} = require("@saltcorn/db-common");
62
63
  // todo add button backup / restore for particular tenant (available in admin tenants screens)
63
64
  //const {
@@ -318,7 +319,48 @@ router.post(
318
319
  if (hasTemplate) {
319
320
  new_url_create += "auth/create_first_user";
320
321
  }
321
-
322
+ const letsencrypt = getState().getConfig("letsencrypt", false);
323
+ if (letsencrypt) {
324
+ let altname = await tenant_letsencrypt_name(subdomain);
325
+ const tenant_letsencrypt_sites = getState().getConfig(
326
+ "tenant_letsencrypt_sites",
327
+ []
328
+ );
329
+ const has_cert = tenant_letsencrypt_sites.includes(altname);
330
+ if (!has_cert) {
331
+ const file_store = db.connectObj.file_store;
332
+ const admin_users = await User.find(
333
+ { role_id: 1 },
334
+ { orderBy: "id" }
335
+ );
336
+ // greenlock logic
337
+ const Greenlock = require("greenlock");
338
+ const greenlock = Greenlock.create({
339
+ packageRoot: path.resolve(__dirname, ".."),
340
+ configDir: path.join(file_store, "greenlock.d"),
341
+ maintainerEmail: admin_users[0].email,
342
+ });
343
+
344
+ await greenlock.sites.add({
345
+ subject: altname,
346
+ altnames: [altname],
347
+ });
348
+ // letsencrypt
349
+ const tenant_letsencrypt_sites = getState().getConfig(
350
+ "tenant_letsencrypt_sites",
351
+ []
352
+ );
353
+ await getState().setConfig("tenant_letsencrypt_sites", [
354
+ altname,
355
+ ...tenant_letsencrypt_sites,
356
+ ]);
357
+ if (req.user?.role_id === 1) {
358
+ req.flash("success", req.__("Tenant created. Certificate will be acquired on first visit."));
359
+ res.redirect("/tenant/list");
360
+ return;
361
+ }
362
+ }
363
+ }
322
364
  res.sendWrap(
323
365
  req.__("Create application"),
324
366
  div(
@@ -628,7 +670,7 @@ router.get(
628
670
  []
629
671
  );
630
672
  const has_cert = tenant_letsencrypt_sites.includes(altname);
631
-
673
+
632
674
  // get list of files
633
675
  let files;
634
676
  await db.runWithTenant(subdomain, async () => {
@@ -161,10 +161,10 @@ describe("Stable versioning install", () => {
161
161
  name: "@christianhugoch/empty_sc_test_plugin",
162
162
  });
163
163
  expect(dbPlugin).not.toBe(null);
164
- expect(dbPlugin.version).toBe("0.0.1");
164
+ expect(dbPlugin.version).toBe("0.1.0");
165
165
  });
166
166
 
167
- it("installs a fixed version", async () => {
167
+ it("installs and upgrades a fixed version", async () => {
168
168
  const loadAndSaveNewPlugin = load_plugins.loadAndSaveNewPlugin;
169
169
  await loadAndSaveNewPlugin(
170
170
  new Plugin({
@@ -178,7 +178,7 @@ describe("Stable versioning install", () => {
178
178
  name: "@christianhugoch/empty_sc_test_plugin",
179
179
  });
180
180
  expect(dbPlugin).not.toBe(null);
181
- expect(dbPlugin.version).toBe("0.0.1");
181
+ expect(dbPlugin.version).toBe("0.1.0");
182
182
  });
183
183
 
184
184
  it("installs and downgrades a fixed version", async () => {
@@ -188,7 +188,7 @@ describe("Stable versioning install", () => {
188
188
  name: "@christianhugoch/empty_sc_test_plugin",
189
189
  location: "@christianhugoch/empty_sc_test_plugin",
190
190
  source: "npm",
191
- version: "0.0.6",
191
+ version: "0.2.0",
192
192
  }),
193
193
  true
194
194
  );
@@ -196,7 +196,7 @@ describe("Stable versioning install", () => {
196
196
  name: "@christianhugoch/empty_sc_test_plugin",
197
197
  });
198
198
  expect(dbPlugin).not.toBe(null);
199
- expect(dbPlugin.version).toBe("0.0.1");
199
+ expect(dbPlugin.version).toBe("0.1.0");
200
200
  });
201
201
  });
202
202
 
@@ -245,7 +245,7 @@ describe("Stable versioning upgrade", () => {
245
245
  expect(newPlugin.version).toBe("0.0.3");
246
246
  });
247
247
 
248
- it("upgrades to latest with downgrade", async () => {
248
+ it("upgrades to latest with downgrade to supported", async () => {
249
249
  const loadAndSaveNewPlugin = load_plugins.loadAndSaveNewPlugin;
250
250
  await loadAndSaveNewPlugin(
251
251
  new Plugin({
@@ -276,7 +276,7 @@ describe("Stable versioning upgrade", () => {
276
276
  name: "@christianhugoch/empty_sc_test_plugin",
277
277
  });
278
278
  expect(newPlugin).not.toBe(null);
279
- expect(newPlugin.version).toBe("0.0.1");
279
+ expect(newPlugin.version).toBe("0.1.0");
280
280
  });
281
281
 
282
282
  it("upgrades to fixed version", async () => {
@@ -313,7 +313,7 @@ describe("Stable versioning upgrade", () => {
313
313
  expect(newPlugin.version).toBe("0.0.3");
314
314
  });
315
315
 
316
- it("upgrades to fixed version with downgrade", async () => {
316
+ it("upgrades to fixed version with downgrade to supported", async () => {
317
317
  const loadAndSaveNewPlugin = load_plugins.loadAndSaveNewPlugin;
318
318
  await loadAndSaveNewPlugin(
319
319
  new Plugin({
@@ -336,7 +336,7 @@ describe("Stable versioning upgrade", () => {
336
336
  name: "@christianhugoch/empty_sc_test_plugin",
337
337
  location: "@christianhugoch/empty_sc_test_plugin",
338
338
  source: "npm",
339
- version: "0.0.6",
339
+ version: "0.2.0",
340
340
  }),
341
341
  true
342
342
  );
@@ -344,6 +344,6 @@ describe("Stable versioning upgrade", () => {
344
344
  name: "@christianhugoch/empty_sc_test_plugin",
345
345
  });
346
346
  expect(newPlugin).not.toBe(null);
347
- expect(newPlugin.version).toBe("0.0.1");
347
+ expect(newPlugin.version).toBe("0.1.0");
348
348
  });
349
349
  });
@@ -365,7 +365,7 @@ describe("Upgrade plugin to supported version", () => {
365
365
  expect(upgradedPlugin.version).toBe("0.0.3");
366
366
  });
367
367
 
368
- it("upgrades to the most current fixed version", async () => {
368
+ it("upgrades to latest as fixed version", async () => {
369
369
  const oldPlugin = await setupPluginVersion(
370
370
  "@christianhugoch/empty_sc_test_plugin_two",
371
371
  "0.0.1"
@@ -389,7 +389,7 @@ describe("Upgrade plugin to supported version", () => {
389
389
  expect(upgradedPlugin.version).toBe("0.0.3");
390
390
  });
391
391
 
392
- it("upgrades with a downgrade of the latest version", async () => {
392
+ it("upgrades with a downgrade of latest", async () => {
393
393
  const oldPlugin = await setupPluginVersion(
394
394
  "@christianhugoch/empty_sc_test_plugin",
395
395
  "0.0.1"
@@ -404,10 +404,10 @@ describe("Upgrade plugin to supported version", () => {
404
404
  const upgradedPlugin = await Plugin.findOne({
405
405
  name: "@christianhugoch/empty_sc_test_plugin",
406
406
  });
407
- expect(upgradedPlugin.version).toBe("0.0.1");
407
+ expect(upgradedPlugin.version).toBe("0.1.0");
408
408
  });
409
409
 
410
- it("upgrades with a downgrade of the most current fixed version", async () => {
410
+ it("upgrades with a downgrade of latest as fixed version", async () => {
411
411
  const oldPlugin = await setupPluginVersion(
412
412
  "@christianhugoch/empty_sc_test_plugin",
413
413
  "0.0.1"
@@ -421,13 +421,13 @@ describe("Upgrade plugin to supported version", () => {
421
421
  "@christianhugoch/empty_sc_test_plugin"
422
422
  )}`
423
423
  )
424
- .send("version=0.1.0")
424
+ .send("version=0.2.0")
425
425
  .set("Cookie", loginCookie)
426
426
  .expect(toRedirect("/plugins"));
427
427
  const upgradedPlugin = await Plugin.findOne({
428
428
  name: "@christianhugoch/empty_sc_test_plugin",
429
429
  });
430
- expect(upgradedPlugin.version).toBe("0.0.1");
430
+ expect(upgradedPlugin.version).toBe("0.1.0");
431
431
  });
432
432
  });
433
433