@saltcorn/server 0.7.4-beta.1 → 0.7.4-beta.2

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/auth/routes.js CHANGED
@@ -335,7 +335,7 @@ router.get(
335
335
  if (result.error) req.flash("danger", result.error);
336
336
  else if (result) {
337
337
  req.flash("success", req.__("Email verified"));
338
- const u = await User.findOne({ email });
338
+ const u = await User.findForSession({ email });
339
339
  if (u) u.relogin(req);
340
340
  }
341
341
  res.redirect("/");
@@ -470,11 +470,11 @@ router.get(
470
470
  form,
471
471
  {},
472
472
  restore +
473
- script(
474
- domReady(
475
- `$('form.create-first-user button[type=submit]').click(function(){press_store_button(this)})`
476
- )
473
+ script(
474
+ domReady(
475
+ `$('form.create-first-user button[type=submit]').click(function(){press_store_button(this)})`
477
476
  )
477
+ )
478
478
  );
479
479
  } else {
480
480
  req.flash("danger", req.__("Users already present"));
@@ -503,7 +503,7 @@ router.post(
503
503
  );
504
504
  if (err) req.flash("error", err);
505
505
  else req.flash("success", req.__("Successfully restored backup"));
506
- fs.unlink(newPath, function () {});
506
+ fs.unlink(newPath, function () { });
507
507
  res.redirect(`/auth/login`);
508
508
  } else {
509
509
  req.flash("danger", req.__("Users already present"));
@@ -536,12 +536,7 @@ router.post(
536
536
  const { email, password } = form.values;
537
537
  const u = await User.create({ email, password, role_id: 1 });
538
538
  req.login(
539
- {
540
- email: u.email,
541
- id: u.id,
542
- role_id: u.role_id,
543
- tenant: db.getTenantSchema(),
544
- },
539
+ u.session_object,
545
540
  function (err) {
546
541
  if (!err) {
547
542
  Trigger.emitEvent("Login", null, u);
@@ -646,12 +641,7 @@ const getNewUserForm = async (new_user_view_name, req, askEmail) => {
646
641
  */
647
642
  const signup_login_with_user = (u, req, res) =>
648
643
  req.login(
649
- {
650
- email: u.email,
651
- id: u.id,
652
- role_id: u.role_id,
653
- tenant: db.getTenantSchema(),
654
- },
644
+ u.session_object,
655
645
  function (err) {
656
646
  if (!err) {
657
647
  Trigger.emitEvent("Login", null, u);
@@ -930,7 +920,7 @@ function handler(req, res) {
930
920
  req.flash(
931
921
  "error",
932
922
  "You've made too many failed attempts in a short period of time, please try again " +
933
- moment(req.rateLimit.resetTime).fromNow()
923
+ moment(req.rateLimit.resetTime).fromNow()
934
924
  );
935
925
  res.redirect("/auth/login"); // brute force protection triggered, send them back to the login page
936
926
  }
@@ -1194,7 +1184,7 @@ const userSettings = async ({ req, res, pwform, user }) => {
1194
1184
  div(
1195
1185
  user.api_token
1196
1186
  ? span({ class: "me-1" }, req.__("API token for this user: ")) +
1197
- code(user.api_token)
1187
+ code(user.api_token)
1198
1188
  : req.__("No API token issued")
1199
1189
  ),
1200
1190
  // button for reset or generate api token
@@ -1208,16 +1198,16 @@ const userSettings = async ({ req, res, pwform, user }) => {
1208
1198
  ),
1209
1199
  // button for remove api token
1210
1200
  user.api_token &&
1211
- div(
1212
- { class: "mt-4 ms-2 d-inline-block" },
1213
- post_btn(
1214
- `/auth/remove-api-token`,
1215
- // TBD localization
1216
- user.api_token ? req.__("Remove") : req.__("Generate"),
1217
- req.csrfToken(),
1218
- { req: req, confirm: true }
1219
- )
1220
- ),
1201
+ div(
1202
+ { class: "mt-4 ms-2 d-inline-block" },
1203
+ post_btn(
1204
+ `/auth/remove-api-token`,
1205
+ // TBD localization
1206
+ user.api_token ? req.__("Remove") : req.__("Generate"),
1207
+ req.csrfToken(),
1208
+ { req: req, confirm: true }
1209
+ )
1210
+ ),
1221
1211
  ],
1222
1212
  };
1223
1213
  return {
@@ -1228,13 +1218,13 @@ const userSettings = async ({ req, res, pwform, user }) => {
1228
1218
  },
1229
1219
  ...(usersets
1230
1220
  ? [
1231
- {
1232
- type: "card",
1233
- class: "mt-0",
1234
- title: userSetsName,
1235
- contents: usersets,
1236
- },
1237
- ]
1221
+ {
1222
+ type: "card",
1223
+ class: "mt-0",
1224
+ title: userSetsName,
1225
+ contents: usersets,
1226
+ },
1227
+ ]
1238
1228
  : []),
1239
1229
  {
1240
1230
  type: "card",
@@ -1257,35 +1247,35 @@ const userSettings = async ({ req, res, pwform, user }) => {
1257
1247
  },
1258
1248
  ...(show2FAPolicy
1259
1249
  ? [
1260
- {
1261
- type: "card",
1262
- title: req.__("Two-factor authentication"),
1263
- contents: [
1264
- div(
1265
- user._attributes.totp_enabled
1266
- ? req.__("Two-factor authentication is enabled")
1267
- : req.__("Two-factor authentication is disabled")
1268
- ),
1269
- div(
1270
- user._attributes.totp_enabled
1271
- ? a(
1272
- {
1273
- href: "/auth/twofa/disable/totp",
1274
- class: "btn btn-danger mt-2",
1275
- },
1276
- req.__("Disable TWA")
1277
- )
1278
- : a(
1279
- {
1280
- href: "/auth/twofa/setup/totp",
1281
- class: "btn btn-primary mt-2",
1282
- },
1283
- req.__("Enable TWA")
1284
- )
1285
- ),
1286
- ],
1287
- },
1288
- ]
1250
+ {
1251
+ type: "card",
1252
+ title: req.__("Two-factor authentication"),
1253
+ contents: [
1254
+ div(
1255
+ user._attributes.totp_enabled
1256
+ ? req.__("Two-factor authentication is enabled")
1257
+ : req.__("Two-factor authentication is disabled")
1258
+ ),
1259
+ div(
1260
+ user._attributes.totp_enabled
1261
+ ? a(
1262
+ {
1263
+ href: "/auth/twofa/disable/totp",
1264
+ class: "btn btn-danger mt-2",
1265
+ },
1266
+ req.__("Disable TWA")
1267
+ )
1268
+ : a(
1269
+ {
1270
+ href: "/auth/twofa/setup/totp",
1271
+ class: "btn btn-primary mt-2",
1272
+ },
1273
+ req.__("Enable TWA")
1274
+ )
1275
+ ),
1276
+ ],
1277
+ },
1278
+ ]
1289
1279
  : []),
1290
1280
  ...(apikeycard ? [apikeycard] : []),
1291
1281
  ],
@@ -1338,18 +1328,12 @@ router.post(
1338
1328
  "/setlanguage",
1339
1329
  loggedIn,
1340
1330
  error_catcher(async (req, res) => {
1341
- const u = await User.findOne({ id: req.user.id });
1331
+ const u = await User.findForSession({ id: req.user.id });
1342
1332
  const newlang = available_languages[req.body.locale];
1343
1333
  if (newlang && u) {
1344
1334
  await u.set_language(req.body.locale);
1345
1335
  req.login(
1346
- {
1347
- email: u.email,
1348
- id: u.id,
1349
- role_id: u.role_id,
1350
- language: req.body.locale,
1351
- tenant: db.getTenantSchema(),
1352
- },
1336
+ u.session_object,
1353
1337
  function (err) {
1354
1338
  if (!err) {
1355
1339
  req.flash("success", req.__("Language changed to %s", newlang));
@@ -1453,16 +1437,11 @@ router.post(
1453
1437
  return;
1454
1438
  }
1455
1439
 
1456
- const u = await User.findOne({ id: req.user.id });
1440
+ const u = await User.findForSession({ id: req.user.id });
1457
1441
  await u.update({ email: form.values.email });
1458
1442
  u.email = form.values.email;
1459
1443
  req.login(
1460
- {
1461
- email: u.email,
1462
- id: u.id,
1463
- role_id: u.role_id,
1464
- tenant: db.getTenantSchema(),
1465
- },
1444
+ u.session_object,
1466
1445
  function (err) {
1467
1446
  if (!err) {
1468
1447
  Trigger.emitEvent("Login", null, u);
@@ -1553,7 +1532,7 @@ router.all(
1553
1532
  return;
1554
1533
  }
1555
1534
  if (wfres.verified === true) {
1556
- const user = await User.findOne({ id: req.user.id });
1535
+ const user = await User.findForSession({ id: req.user.id });
1557
1536
  await user.set_to_verified();
1558
1537
  req.flash("success", req.__("User verified"));
1559
1538
  user.relogin(req);
@@ -1590,9 +1569,8 @@ router.get(
1590
1569
  // generate QR code for scanning into Google Authenticator
1591
1570
  // reference: https://code.google.com/p/google-authenticator/wiki/KeyUriFormat
1592
1571
  const site_name = getState().getConfig("site_name");
1593
- const otpUrl = `otpauth://totp/${
1594
- user.email
1595
- }?secret=${encodedKey}&period=30&issuer=${encodeURIComponent(site_name)}`;
1572
+ const otpUrl = `otpauth://totp/${user.email
1573
+ }?secret=${encodedKey}&period=30&issuer=${encodeURIComponent(site_name)}`;
1596
1574
  const image = await qrcode.toDataURL(otpUrl);
1597
1575
  res.sendWrap(req.__("Setup two-factor authentication"), {
1598
1576
  type: "card",
@@ -1763,7 +1741,7 @@ router.post(
1763
1741
  failureFlash: true,
1764
1742
  }),
1765
1743
  error_catcher(async (req, res) => {
1766
- const user = await User.findOne({ id: req.user.pending_user.id });
1744
+ const user = await User.findForSession({ id: req.user.pending_user.id });
1767
1745
  user.relogin(req);
1768
1746
  Trigger.emitEvent("Login", null, user);
1769
1747
  res.redirect("/");
package/locales/en.json CHANGED
@@ -948,5 +948,23 @@
948
948
  "Source of module for install. Few options:npm - download from npm repository,local - get from local file system,github - download from github,git - get from git": "Source of module for install. Few options:npm - download from npm repository,local - get from local file system,github - download from github,git - get from git",
949
949
  "Version of module, latest is default value": "Version of module, latest is default value",
950
950
  "For npm - name of npm package, e.g. @saltcorn/html or saltcorn-gantt, check at npmjs.com, for local - absolute path to module folder in file system, e.g. C:\\gitsrc\\any-bootstrap-theme\\, for github - name of github project.": "For npm - name of npm package, e.g. @saltcorn/html or saltcorn-gantt, check at npmjs.com, for local - absolute path to module folder in file system, e.g. C:\\gitsrc\\any-bootstrap-theme\\, for github - name of github project.",
951
- "Modules up-to-date": "Modules up-to-date"
952
- }
951
+ "Modules up-to-date": "Modules up-to-date",
952
+ "User must have this role or higher to read rows from the table, unless they are the owner": "User must have this role or higher to read rows from the table, unless they are the owner",
953
+ "User must have this role or higher to edit or create new rows in the table, unless they are the owner": "User must have this role or higher to edit or create new rows in the table, unless they are the owner",
954
+ "Tag": "Tag",
955
+ "Tagname": "Tagname",
956
+ "Create tag": "Create tag",
957
+ "Tags": "Tags",
958
+ "New tag": "New tag",
959
+ "Tag name": "Tag name",
960
+ "%s Tag": "%s Tag",
961
+ "Remove From Tag": "Remove From Tag",
962
+ "Add tables": "Add tables",
963
+ "Add views": "Add views",
964
+ "Add tages": "Add tages",
965
+ "Trigger": "Trigger",
966
+ "Add %s to tag": "Add %s to tag",
967
+ "Tag %s deleted": "Tag %s deleted",
968
+ "Tag %s created": "Tag %s created"
969
+
970
+ }
package/markup/admin.js CHANGED
@@ -245,6 +245,13 @@ const send_files_page = (args) => {
245
245
  });
246
246
  };
247
247
 
248
+ const send_tags_page = (args) => {
249
+ return send_settings_page({
250
+ main_section: "Tags",
251
+ ...args,
252
+ });
253
+ };
254
+
248
255
  /**
249
256
  * Send Events Page
250
257
  * @param {object} args
@@ -281,6 +288,7 @@ const send_admin_page = (args) => {
281
288
  { text: "Backup", href: "/admin/backup" },
282
289
  { text: "Email", href: "/admin/email" },
283
290
  { text: "System", href: "/admin/system" },
291
+ ...(isRoot ? [{ text: "Tag", href: "/tag" }] : []),
284
292
  ...(isRoot
285
293
  ? [{ text: "Mobile app", href: "/admin/build-mobile-app" }]
286
294
  : []),
@@ -345,7 +353,12 @@ const flash_restart = (req) => {
345
353
  * @param {*} opts.formArgs
346
354
  * @returns {Promise<Form>}
347
355
  */
348
- const config_fields_form = async ({ field_names, req, action, ...formArgs }) => {
356
+ const config_fields_form = async ({
357
+ field_names,
358
+ req,
359
+ action,
360
+ ...formArgs
361
+ }) => {
349
362
  const values = {};
350
363
  const state = getState();
351
364
  const fields = [];
@@ -512,4 +525,5 @@ module.exports = {
512
525
  save_config_from_form,
513
526
  flash_restart_if_required,
514
527
  flash_restart,
528
+ send_tags_page,
515
529
  };
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@saltcorn/server",
3
- "version": "0.7.4-beta.1",
3
+ "version": "0.7.4-beta.2",
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
- "@saltcorn/base-plugin": "0.7.4-beta.1",
10
- "@saltcorn/builder": "0.7.4-beta.1",
11
- "@saltcorn/data": "0.7.4-beta.1",
12
- "@saltcorn/admin-models": "0.7.4-beta.1",
13
- "@saltcorn/markup": "0.7.4-beta.1",
14
- "@saltcorn/sbadmin2": "0.7.4-beta.1",
9
+ "@saltcorn/base-plugin": "0.7.4-beta.2",
10
+ "@saltcorn/builder": "0.7.4-beta.2",
11
+ "@saltcorn/data": "0.7.4-beta.2",
12
+ "@saltcorn/admin-models": "0.7.4-beta.2",
13
+ "@saltcorn/markup": "0.7.4-beta.2",
14
+ "@saltcorn/sbadmin2": "0.7.4-beta.2",
15
15
  "@socket.io/cluster-adapter": "^0.1.0",
16
16
  "@socket.io/sticky": "^1.0.1",
17
17
  "aws-sdk": "^2.1037.0",
@@ -323,4 +323,27 @@ table.table-inner-grid, table.table-inner-grid th, table.table-inner-grid td {
323
323
 
324
324
  .CodeMirror {
325
325
  resize: vertical;
326
- }
326
+ }
327
+
328
+ /* copied from bootstrap and adjusted to show the arrow on the left */
329
+ .card .card-header-left-collapse[data-bs-toggle=collapse] {
330
+ text-decoration: none;
331
+ position: relative;
332
+ padding: 0.75rem 3.25rem 0.75rem 1.25rem;
333
+ }
334
+ .card .card-header-left-collapse[data-bs-toggle=collapse]::before {
335
+ position: absolute;
336
+ left: 0;
337
+ top: 0;
338
+ line-height: 51px;
339
+ font-weight: 900;
340
+ content: "\f107";
341
+ font-family: "Font Awesome 5 Free";
342
+ color: #d1d3e2;
343
+ }
344
+ .card .card-header-left-collapse[data-bs-toggle=collapse].collapsed {
345
+ border-radius: 0.35rem;
346
+ }
347
+ .card .card-header-left-collapse[data-bs-toggle=collapse].collapsed::before {
348
+ content: "\f105";
349
+ }
@@ -143,6 +143,8 @@ function view_post(viewname, route, data, onDone) {
143
143
  }).done(function (res) {
144
144
  if (onDone) onDone(res);
145
145
  ajax_done(res);
146
+ }).fail(function (res) {
147
+ notifyAlert({ type: "danger", text: res.responseText });
146
148
  });
147
149
  }
148
150
  var logged_errors = [];
@@ -210,9 +212,9 @@ function ajax_modal(url, opts = {}) {
210
212
  $("#scmodal .modal-body").html(res);
211
213
  new bootstrap.Modal($("#scmodal")).show();
212
214
  initialize_page();
213
- (opts.onOpen || function () {})(res);
215
+ (opts.onOpen || function () { })(res);
214
216
  $("#scmodal").on("hidden.bs.modal", function (e) {
215
- (opts.onClose || function () {})(res);
217
+ (opts.onClose || function () { })(res);
216
218
  $("body").css("overflow", "");
217
219
  });
218
220
  },
@@ -264,7 +266,7 @@ function applyViewConfig(e, url, k) {
264
266
  "CSRF-Token": _sc_globalCsrf,
265
267
  },
266
268
  data: JSON.stringify(cfg),
267
- error: function (request) {},
269
+ error: function (request) { },
268
270
  success: function (res) {
269
271
  k && k(res);
270
272
  },
@@ -444,16 +446,16 @@ Copyright (c) 2015 Jeff Green
444
446
  stateObject,
445
447
  document.title,
446
448
  window.location.pathname +
447
- window.location.search +
448
- $(this).attr("href")
449
+ window.location.search +
450
+ $(this).attr("href")
449
451
  );
450
452
  } else {
451
453
  window.history.replaceState(
452
454
  stateObject,
453
455
  document.title,
454
456
  window.location.pathname +
455
- window.location.search +
456
- $(this).attr("href")
457
+ window.location.search +
458
+ $(this).attr("href")
457
459
  );
458
460
  }
459
461
  });
package/routes/actions.js CHANGED
@@ -8,6 +8,7 @@ const Router = require("express-promise-router");
8
8
  const { isAdmin, error_catcher, get_base_url } = require("./utils.js");
9
9
  const { getState } = require("@saltcorn/data/db/state");
10
10
  const Trigger = require("@saltcorn/data/models/trigger");
11
+ const { getTriggerList } = require("./common_lists");
11
12
 
12
13
  /**
13
14
  * @type {object}
@@ -97,45 +98,7 @@ router.get(
97
98
  type: "card",
98
99
  title: req.__("Triggers"),
99
100
  contents: div(
100
- mkTable(
101
- [
102
- { label: req.__("Name"), key: "name" },
103
- { label: req.__("Action"), key: "action" },
104
- {
105
- label: req.__("Table or Channel"),
106
- key: (r) => r.table_name || r.channel,
107
- },
108
- {
109
- label: req.__("When"),
110
- key: (a) =>
111
- a.when_trigger === "API call"
112
- ? `API: ${base_url}api/action/${a.name}`
113
- : a.when_trigger,
114
- },
115
- {
116
- label: req.__("Test run"),
117
- key: (r) =>
118
- r.table_id
119
- ? ""
120
- : link(`/actions/testrun/${r.id}`, req.__("Test run")),
121
- },
122
- {
123
- label: req.__("Edit"),
124
- key: (r) => link(`/actions/edit/${r.id}`, req.__("Edit")),
125
- },
126
- {
127
- label: req.__("Configure"),
128
- key: (r) =>
129
- link(`/actions/configure/${r.id}`, req.__("Configure")),
130
- },
131
- {
132
- label: req.__("Delete"),
133
- key: (r) => post_delete_btn(`/actions/delete/${r.id}`, req),
134
- },
135
- ],
136
- triggers,
137
- { hover: true }
138
- ),
101
+ getTriggerList(triggers, req),
139
102
  link("/actions/new", req.__("Add trigger"))
140
103
  ),
141
104
  },