@saltcorn/server 0.8.3-alpha.1 → 0.8.3-alpha.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/admin.js +1 -0
- package/auth/routes.js +0 -1
- package/auth/testhelp.js +24 -0
- package/load_plugins.js +6 -2
- package/locales/da.json +122 -1
- package/locales/en.json +8 -1
- package/locales/ru.json +6 -1
- package/package.json +13 -13
- package/routes/api.js +1 -1
- package/routes/edit.js +11 -6
- package/routes/fields.js +12 -5
- package/routes/search.js +30 -11
- package/tests/assets/large-image.png +0 -0
- package/tests/files.test.js +45 -4
package/auth/admin.js
CHANGED
package/auth/routes.js
CHANGED
|
@@ -1129,7 +1129,6 @@ router.post(
|
|
|
1129
1129
|
error_catcher(async (req, res, next) => {
|
|
1130
1130
|
const { method } = req.params;
|
|
1131
1131
|
const auth = getState().auth_methods[method];
|
|
1132
|
-
console.log(method, auth);
|
|
1133
1132
|
if (auth) {
|
|
1134
1133
|
passport.authenticate(method, auth.parameters)(
|
|
1135
1134
|
req,
|
package/auth/testhelp.js
CHANGED
|
@@ -65,6 +65,29 @@ const toSucceed =
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* @param {number} expCode
|
|
71
|
+
* @returns {void}
|
|
72
|
+
* @throws {Error}
|
|
73
|
+
*/
|
|
74
|
+
const toSucceedWithImage =
|
|
75
|
+
({ expCode = 200, lengthIs }) =>
|
|
76
|
+
(res) => {
|
|
77
|
+
if (res.statusCode !== expCode) {
|
|
78
|
+
console.log(res.text);
|
|
79
|
+
throw new Error(`Expected status ${expCode}, received ${res.statusCode}`);
|
|
80
|
+
}
|
|
81
|
+
if (res.type.split("/")[0] !== "image") {
|
|
82
|
+
throw new Error(`Expected response type image/*, received ${res.type}`);
|
|
83
|
+
}
|
|
84
|
+
if (lengthIs && !lengthIs(res.body.length)) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`Image response not accepted. Length not satisfied. Received ${res.body.length} bytes`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
68
91
|
/**
|
|
69
92
|
*
|
|
70
93
|
* @param {number} txt
|
|
@@ -209,4 +232,5 @@ module.exports = {
|
|
|
209
232
|
succeedJsonWith,
|
|
210
233
|
notAuthorized,
|
|
211
234
|
respondJsonWith,
|
|
235
|
+
toSucceedWithImage,
|
|
212
236
|
};
|
package/load_plugins.js
CHANGED
|
@@ -56,13 +56,17 @@ const defaultManager = new PluginManager({
|
|
|
56
56
|
* @param force - force flag
|
|
57
57
|
*/
|
|
58
58
|
const loadPlugin = async (plugin, force) => {
|
|
59
|
-
// load
|
|
59
|
+
// load plugin
|
|
60
60
|
const res = await requirePlugin(plugin, force);
|
|
61
|
+
const configuration =
|
|
62
|
+
typeof plugin.configuration === "string"
|
|
63
|
+
? JSON.parse(plugin.configuration)
|
|
64
|
+
: plugin.configuration;
|
|
61
65
|
// register plugin
|
|
62
66
|
getState().registerPlugin(
|
|
63
67
|
res.plugin_module.plugin_name || plugin.name,
|
|
64
68
|
res.plugin_module,
|
|
65
|
-
|
|
69
|
+
configuration,
|
|
66
70
|
res.location,
|
|
67
71
|
res.name
|
|
68
72
|
);
|
package/locales/da.json
CHANGED
|
@@ -558,5 +558,126 @@
|
|
|
558
558
|
"List options": "List options",
|
|
559
559
|
"Modules": "Modules",
|
|
560
560
|
"File not found": "File not found",
|
|
561
|
-
"Welcome, %s!": "Welcome, %s!"
|
|
561
|
+
"Welcome, %s!": "Welcome, %s!",
|
|
562
|
+
"CSV upload": "CSV upload",
|
|
563
|
+
"Upload file(s)": "Upload file(s)",
|
|
564
|
+
"API token": "API token",
|
|
565
|
+
"No API token issued": "No API token issued",
|
|
566
|
+
"Generate": "Generate",
|
|
567
|
+
"Two-factor authentication": "Two-factor authentication",
|
|
568
|
+
"Two-factor authentication is disabled": "Two-factor authentication is disabled",
|
|
569
|
+
"Enable TWA": "Enable TWA",
|
|
570
|
+
"Pattern": "Pattern",
|
|
571
|
+
"You have views with a role to access lower than the table role to read, with no table ownership. This may cause a denial of access. Users need to have table read access to any data displayed.": "You have views with a role to access lower than the table role to read, with no table ownership. This may cause a denial of access. Users need to have table read access to any data displayed.",
|
|
572
|
+
"Views potentially affected": "Views potentially affected",
|
|
573
|
+
"History": "History",
|
|
574
|
+
"External": "External",
|
|
575
|
+
"Discover tables that are already in the Database, but not known to Saltcorn": "Discover tables that are already in the Database, but not known to Saltcorn",
|
|
576
|
+
"Forget table": "Forget table",
|
|
577
|
+
"Ownership field": "Ownership field",
|
|
578
|
+
"The user referred to in this field will be the owner of the row": "The user referred to in this field will be the owner of the row",
|
|
579
|
+
"None": "None",
|
|
580
|
+
"Ownership formula": "Ownership formula",
|
|
581
|
+
"User is treated as owner if true. In scope: ": "User is treated as owner if true. In scope: ",
|
|
582
|
+
"User group": "User group",
|
|
583
|
+
"Add relations to this table in dropdown options for ownership field": "Add relations to this table in dropdown options for ownership field",
|
|
584
|
+
"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",
|
|
585
|
+
"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",
|
|
586
|
+
"Edit properties": "Edit properties",
|
|
587
|
+
"Preset %s": "Preset %s",
|
|
588
|
+
"%s configuration": "%s configuration",
|
|
589
|
+
"Module Store endpoint": "Module Store endpoint",
|
|
590
|
+
"The endpoint of plugins store.": "The endpoint of plugins store.",
|
|
591
|
+
"Packs Store endpoint": "Packs Store endpoint",
|
|
592
|
+
"The endpoint of packs store.": "The endpoint of packs store.",
|
|
593
|
+
"Mobile app": "Mobile app",
|
|
594
|
+
"Backup now": "Backup now",
|
|
595
|
+
"Frequency": "Frequency",
|
|
596
|
+
"Destination": "Destination",
|
|
597
|
+
"Directory": "Directory",
|
|
598
|
+
"Expiration in days": "Expiration in days",
|
|
599
|
+
"Delete old backup files in this directory after the set number of days": "Delete old backup files in this directory after the set number of days",
|
|
600
|
+
"Snapshot now": "Snapshot now",
|
|
601
|
+
"Periodic snapshots enabled": "Periodic snapshots enabled",
|
|
602
|
+
"Snapshot will be made every hour if there are changes": "Snapshot will be made every hour if there are changes",
|
|
603
|
+
"Manual backup": "Manual backup",
|
|
604
|
+
"Automated backup": "Automated backup",
|
|
605
|
+
"Restore/download automated backups »": "Restore/download automated backups »",
|
|
606
|
+
"Snapshots": "Snapshots",
|
|
607
|
+
"Snapshots store your application structure and definition, without the table data. Individual views and pages can be restored from snapshots from the <a href='/viewedit'>view</a> or <a href='/pageedit'>pages</a> overviews (\"Restore\" from individual page or view dropdowns).": "Snapshots store your application structure and definition, without the table data. Individual views and pages can be restored from snapshots from the <a href='/viewedit'>view</a> or <a href='/pageedit'>pages</a> overviews (\"Restore\" from individual page or view dropdowns).",
|
|
608
|
+
"List/download snapshots »": "List/download snapshots »",
|
|
609
|
+
"Configuration check": "Configuration check",
|
|
610
|
+
"Check for updates": "Check for updates",
|
|
611
|
+
"Database type": "Database type",
|
|
612
|
+
"Database host": "Database host",
|
|
613
|
+
"Database port": "Database port",
|
|
614
|
+
"Database name": "Database name",
|
|
615
|
+
"Database user": "Database user",
|
|
616
|
+
"Database schema": "Database schema",
|
|
617
|
+
"Build mobile app": "Build mobile app",
|
|
618
|
+
"Entry point": "Entry point",
|
|
619
|
+
"Platform": "Platform",
|
|
620
|
+
"docker": "docker",
|
|
621
|
+
"android": "android",
|
|
622
|
+
"iOS": "iOS",
|
|
623
|
+
"App file": "App file",
|
|
624
|
+
"Server URL": "Server URL",
|
|
625
|
+
"Log client errors": "Log client errors",
|
|
626
|
+
"Record all client errors in the crash log": "Record all client errors in the crash log",
|
|
627
|
+
"System logging verbosity": "System logging verbosity",
|
|
628
|
+
"NPM packages in code": "NPM packages in code",
|
|
629
|
+
"Comma-separated list of packages which will be available in JavaScript actions": "Comma-separated list of packages which will be available in JavaScript actions",
|
|
630
|
+
"Development settings": "Development settings",
|
|
631
|
+
"Module store": "Module store",
|
|
632
|
+
"Upgrading modules...": "Upgrading modules...",
|
|
633
|
+
"Upgrade installed modules": "Upgrade installed modules",
|
|
634
|
+
"Add another module": "Add another module",
|
|
635
|
+
"Module": "Module",
|
|
636
|
+
"Become user": "Become user",
|
|
637
|
+
"Send password reset email": "Send password reset email",
|
|
638
|
+
"Login and Signup": "Login and Signup",
|
|
639
|
+
"Table access": "Table access",
|
|
640
|
+
"HTTP": "HTTP",
|
|
641
|
+
"Permissions": "Permissions",
|
|
642
|
+
"2FA policy": "2FA policy",
|
|
643
|
+
"Cookie duration (hours)": "Cookie duration (hours)",
|
|
644
|
+
"Set to 0 for expiration at the end of browser session": "Set to 0 for expiration at the end of browser session",
|
|
645
|
+
"Cookie duration (hours) when remember ticked": "Cookie duration (hours) when remember ticked",
|
|
646
|
+
"Public cache TTL (minutes)": "Public cache TTL (minutes)",
|
|
647
|
+
"Cache-control max-age for public views and pages. 0 to disable": "Cache-control max-age for public views and pages. 0 to disable",
|
|
648
|
+
"HTTP settings": "HTTP settings",
|
|
649
|
+
"Role to generate API keys": "Role to generate API keys",
|
|
650
|
+
"User should have this role or higher to generate API keys in their user settings": "User should have this role or higher to generate API keys in their user settings",
|
|
651
|
+
"Role for search": "Role for search",
|
|
652
|
+
"Min role to access search page": "Min role to access search page",
|
|
653
|
+
"Permissions settings": "Permissions settings",
|
|
654
|
+
"Update": "Update",
|
|
655
|
+
"Add": "Add",
|
|
656
|
+
"Recalculate dynamic": "Recalculate dynamic",
|
|
657
|
+
"Order field": "Order field",
|
|
658
|
+
"Section field": "Section field",
|
|
659
|
+
"Optional. String type with options, each of which will become a menu section": "Optional. String type with options, each of which will become a menu section",
|
|
660
|
+
"Label formula": "Label formula",
|
|
661
|
+
"URL formula": "URL formula",
|
|
662
|
+
"Include formula": "Include formula",
|
|
663
|
+
"If specified, only include in menu rows that evaluate to true": "If specified, only include in menu rows that evaluate to true",
|
|
664
|
+
"Location": "Location",
|
|
665
|
+
"Not all themes support all locations": "Not all themes support all locations",
|
|
666
|
+
"Library": "Library",
|
|
667
|
+
"Tags": "Tags",
|
|
668
|
+
"Diagram": "Diagram",
|
|
669
|
+
"Library: component assemblies that can be used in the builder": "Library: component assemblies that can be used in the builder",
|
|
670
|
+
"Creator email": "Creator email",
|
|
671
|
+
"Created": "Created",
|
|
672
|
+
"Create tenant warning text": "Create tenant warning text",
|
|
673
|
+
"Provide your own create warning text if need": "Provide your own create warning text if need",
|
|
674
|
+
"New tenant template": "New tenant template",
|
|
675
|
+
"Copy site structure for new tenants from this tenant": "Copy site structure for new tenants from this tenant",
|
|
676
|
+
"Tagname": "Tagname",
|
|
677
|
+
"Create tag": "Create tag",
|
|
678
|
+
"Application diagram": "Application diagram",
|
|
679
|
+
"Trigger": "Trigger",
|
|
680
|
+
"All entities": "All entities",
|
|
681
|
+
"no tags": "no tags",
|
|
682
|
+
"Add tag": "Add tag"
|
|
562
683
|
}
|
package/locales/en.json
CHANGED
|
@@ -1086,5 +1086,12 @@
|
|
|
1086
1086
|
"Views potentially affected": "Views potentially affected",
|
|
1087
1087
|
"Empty view": "Empty view",
|
|
1088
1088
|
"A view that will be shown only if there are no tables rows to show": "A view that will be shown only if there are no tables rows to show",
|
|
1089
|
-
"Calculated field will be stored in Database": "Calculated field will be stored in Database"
|
|
1089
|
+
"Calculated field will be stored in Database": "Calculated field will be stored in Database",
|
|
1090
|
+
"Set Email": "Set Email",
|
|
1091
|
+
"Please enter your email address": "Please enter your email address",
|
|
1092
|
+
"Role for search": "Role for search",
|
|
1093
|
+
"Min role to access search page": "Min role to access search page",
|
|
1094
|
+
"Update": "Update",
|
|
1095
|
+
"Add": "Add",
|
|
1096
|
+
"Recalculate dynamic": "Recalculate dynamic"
|
|
1090
1097
|
}
|
package/locales/ru.json
CHANGED
|
@@ -968,5 +968,10 @@
|
|
|
968
968
|
"Defines how long to wait for data before aborting file upload. Set to 0 if you want to turn off timeout checks. ": "Определяет максимальный допустимый интервал времени ожидания загрузки данных файла. 0 отключает проверку. ",
|
|
969
969
|
"User group": "Группа пользователей",
|
|
970
970
|
"Add relations to this table in dropdown options for ownership field": "Добавить связь с этой таблицей в выбор опций для поля Владельца ",
|
|
971
|
-
"Calculated field will be stored in Database": "Вычисляемое будет сохранено в базе данных"
|
|
971
|
+
"Calculated field will be stored in Database": "Вычисляемое будет сохранено в базе данных",
|
|
972
|
+
"Save indicator": "Индикатор сохранения",
|
|
973
|
+
"%s configuration": "%s конфигурация",
|
|
974
|
+
"Show only matches in table:": "Показывать только совпадения в таблице:",
|
|
975
|
+
"Role for search": "Роль для поиска",
|
|
976
|
+
"Min role to access search page": "Минимальная роль для доступа к странице поиска"
|
|
972
977
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/server",
|
|
3
|
-
"version": "0.8.3-alpha.
|
|
3
|
+
"version": "0.8.3-alpha.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.8.3-alpha.
|
|
10
|
-
"@saltcorn/builder": "0.8.3-alpha.
|
|
11
|
-
"@saltcorn/data": "0.8.3-alpha.
|
|
12
|
-
"@saltcorn/admin-models": "0.8.3-alpha.
|
|
13
|
-
"@saltcorn/filemanager": "0.8.3-alpha.
|
|
14
|
-
"@saltcorn/markup": "0.8.3-alpha.
|
|
15
|
-
"@saltcorn/sbadmin2": "0.8.3-alpha.
|
|
9
|
+
"@saltcorn/base-plugin": "0.8.3-alpha.2",
|
|
10
|
+
"@saltcorn/builder": "0.8.3-alpha.2",
|
|
11
|
+
"@saltcorn/data": "0.8.3-alpha.2",
|
|
12
|
+
"@saltcorn/admin-models": "0.8.3-alpha.2",
|
|
13
|
+
"@saltcorn/filemanager": "0.8.3-alpha.2",
|
|
14
|
+
"@saltcorn/markup": "0.8.3-alpha.2",
|
|
15
|
+
"@saltcorn/sbadmin2": "0.8.3-alpha.2",
|
|
16
16
|
"@socket.io/cluster-adapter": "^0.1.0",
|
|
17
17
|
"@socket.io/sticky": "^1.0.1",
|
|
18
18
|
"aws-sdk": "^2.1037.0",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"i18n": "^0.14.0",
|
|
36
36
|
"jsonwebtoken": "^9.0.0",
|
|
37
37
|
"live-plugin-manager": "^0.16.0",
|
|
38
|
-
"moment": "^2.
|
|
39
|
-
"multer": "
|
|
38
|
+
"moment": "^2.29.4",
|
|
39
|
+
"multer": "1.4.5-lts.1",
|
|
40
40
|
"multer-s3": "^2.10.0",
|
|
41
|
-
"node-fetch": "2.6.
|
|
41
|
+
"node-fetch": "2.6.9",
|
|
42
42
|
"node-watch": "^0.7.2",
|
|
43
43
|
"notp": "2.0.3",
|
|
44
44
|
"passport": "^0.4.1",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"pg": "^8.2.1",
|
|
50
50
|
"pluralize": "^8.0.0",
|
|
51
51
|
"qrcode": "1.5.0",
|
|
52
|
-
"resize-with-sharp-or-jimp": "0.1.
|
|
52
|
+
"resize-with-sharp-or-jimp": "0.1.6",
|
|
53
53
|
"socket.io": "4.2.0",
|
|
54
54
|
"thirty-two": "1.0.2",
|
|
55
55
|
"tmp-promise": "^3.0.2",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"jest": "26.6.3",
|
|
66
66
|
"jest-environment-jsdom": "^26.6.2",
|
|
67
|
-
"supertest": "^
|
|
67
|
+
"supertest": "^6.3.3"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"dev": "nodemon index.js",
|
package/routes/api.js
CHANGED
|
@@ -147,7 +147,7 @@ router.post(
|
|
|
147
147
|
(await view.authorise_get({ req, ...view })) // TODO set query to state
|
|
148
148
|
) {
|
|
149
149
|
const queries = view.queries(false, req);
|
|
150
|
-
if (queries
|
|
150
|
+
if (Object.prototype.hasOwnProperty.call(queries, queryName)) {
|
|
151
151
|
const { args } = req.body;
|
|
152
152
|
const resp = await queries[queryName](...args, true);
|
|
153
153
|
res.json({ success: resp, alerts: getFlashes(req) });
|
package/routes/edit.js
CHANGED
|
@@ -32,13 +32,18 @@ router.post(
|
|
|
32
32
|
const { redirect } = req.query;
|
|
33
33
|
// todo check that works after where change
|
|
34
34
|
const table = await Table.findOne({ name: tableName });
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
req.
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
|
|
36
|
+
const row = await table.getRow(
|
|
37
|
+
{ [table.pk_name]: id },
|
|
38
|
+
{ forUser: req.user, forPublic: !req.user }
|
|
39
|
+
);
|
|
40
|
+
if (row)
|
|
41
|
+
await table.updateRow(
|
|
42
|
+
{ [field_name]: !row[field_name] },
|
|
43
|
+
id,
|
|
44
|
+
req.user || { role_id: 10 }
|
|
41
45
|
);
|
|
46
|
+
|
|
42
47
|
if (req.xhr) res.send("OK");
|
|
43
48
|
else if (req.get("referer")) res.redirect(req.get("referer"));
|
|
44
49
|
else res.redirect(redirect || `/list/${table.name}`);
|
package/routes/fields.js
CHANGED
|
@@ -137,9 +137,7 @@ const fieldForm = async (req, fkey_opts, existing_names, id, hasData) => {
|
|
|
137
137
|
new Field({
|
|
138
138
|
label: req.__("Stored"),
|
|
139
139
|
name: "stored",
|
|
140
|
-
sublabel: req.__(
|
|
141
|
-
"Calculated field will be stored in Database"
|
|
142
|
-
),
|
|
140
|
+
sublabel: req.__("Calculated field will be stored in Database"),
|
|
143
141
|
type: "Bool",
|
|
144
142
|
disabled: !!id,
|
|
145
143
|
showIf: { calculated: true },
|
|
@@ -927,16 +925,25 @@ router.post(
|
|
|
927
925
|
res.send("");
|
|
928
926
|
return;
|
|
929
927
|
}
|
|
928
|
+
const firefox = /firefox/i.test(req.headers["user-agent"]);
|
|
930
929
|
const fv = fieldviews[fieldview];
|
|
931
930
|
if (!fv && field.type === "Key" && fieldview === "select")
|
|
932
|
-
res.send(
|
|
931
|
+
res.send(
|
|
932
|
+
`<input ${
|
|
933
|
+
firefox ? "readonly" : "disabled"
|
|
934
|
+
} class="form-control form-select"></input>`
|
|
935
|
+
);
|
|
933
936
|
else if (!fv) res.send("");
|
|
934
937
|
else if (fv.isEdit || fv.isFilter)
|
|
935
938
|
res.send(
|
|
936
939
|
fv.run(
|
|
937
940
|
field.name,
|
|
938
941
|
undefined,
|
|
939
|
-
{
|
|
942
|
+
{
|
|
943
|
+
...(firefox ? { readonly: true } : { disabled: true }),
|
|
944
|
+
...configuration,
|
|
945
|
+
...(field.attributes || {}),
|
|
946
|
+
},
|
|
940
947
|
"",
|
|
941
948
|
false,
|
|
942
949
|
field
|
package/routes/search.js
CHANGED
|
@@ -28,16 +28,17 @@ const router = new Router();
|
|
|
28
28
|
module.exports = router;
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
+
* Search Configuration form
|
|
31
32
|
* @param {object[]} tables
|
|
32
33
|
* @param {object[]} views
|
|
33
34
|
* @param {object} req
|
|
34
35
|
* @returns {Forms}
|
|
35
36
|
*/
|
|
36
37
|
const searchConfigForm = (tables, views, req) => {
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
let fields = [];
|
|
39
|
+
let tbls_noviews = [];
|
|
39
40
|
for (const t of tables) {
|
|
40
|
-
|
|
41
|
+
const ok_views = views.filter(
|
|
41
42
|
(v) =>
|
|
42
43
|
v.table_id === t.id && v.viewtemplateObj && v.viewtemplateObj.runMany
|
|
43
44
|
);
|
|
@@ -70,6 +71,7 @@ const searchConfigForm = (tables, views, req) => {
|
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
/**
|
|
74
|
+
* Show config on GET
|
|
73
75
|
* @name get/config
|
|
74
76
|
* @function
|
|
75
77
|
* @memberof module:routes/search~searchRouter
|
|
@@ -79,7 +81,7 @@ router.get(
|
|
|
79
81
|
"/config",
|
|
80
82
|
isAdmin,
|
|
81
83
|
error_catcher(async (req, res) => {
|
|
82
|
-
|
|
84
|
+
const views = await View.find({}, { orderBy: "name" });
|
|
83
85
|
const tables = await Table.find();
|
|
84
86
|
const form = searchConfigForm(tables, views, req);
|
|
85
87
|
form.values = getState().getConfig("globalSearch");
|
|
@@ -98,6 +100,7 @@ router.get(
|
|
|
98
100
|
);
|
|
99
101
|
|
|
100
102
|
/**
|
|
103
|
+
* Execute config update
|
|
101
104
|
* @name post/config
|
|
102
105
|
* @function
|
|
103
106
|
* @memberof module:routes/search~searchRouter
|
|
@@ -107,7 +110,7 @@ router.post(
|
|
|
107
110
|
"/config",
|
|
108
111
|
isAdmin,
|
|
109
112
|
error_catcher(async (req, res) => {
|
|
110
|
-
|
|
113
|
+
const views = await View.find({}, { orderBy: "name" });
|
|
111
114
|
const tables = await Table.find();
|
|
112
115
|
const form = searchConfigForm(tables, views, req);
|
|
113
116
|
const result = form.validate(req.body);
|
|
@@ -132,6 +135,7 @@ router.post(
|
|
|
132
135
|
);
|
|
133
136
|
|
|
134
137
|
/**
|
|
138
|
+
* Search form
|
|
135
139
|
* @returns {Form}
|
|
136
140
|
*/
|
|
137
141
|
const searchForm = () =>
|
|
@@ -150,6 +154,7 @@ const searchForm = () =>
|
|
|
150
154
|
});
|
|
151
155
|
|
|
152
156
|
/**
|
|
157
|
+
* Run search
|
|
153
158
|
* @param {object} opts
|
|
154
159
|
* @param {*} opts.q
|
|
155
160
|
* @param {*} opts._page
|
|
@@ -161,7 +166,9 @@ const searchForm = () =>
|
|
|
161
166
|
*/
|
|
162
167
|
const runSearch = async ({ q, _page, table }, req, res) => {
|
|
163
168
|
const role = (req.user || {}).role_id || 10;
|
|
169
|
+
// globalSearch contains list of pairs: table, view
|
|
164
170
|
const cfg = getState().getConfig("globalSearch");
|
|
171
|
+
const page_size = getState().getConfig("search_page_size");
|
|
165
172
|
|
|
166
173
|
if (!cfg) {
|
|
167
174
|
req.flash("warning", req.__("Search not configured"));
|
|
@@ -169,7 +176,7 @@ const runSearch = async ({ q, _page, table }, req, res) => {
|
|
|
169
176
|
return;
|
|
170
177
|
}
|
|
171
178
|
const current_page = parseInt(_page) || 1;
|
|
172
|
-
const offset = (current_page - 1) *
|
|
179
|
+
const offset = (current_page - 1) * page_size;
|
|
173
180
|
let resp = [];
|
|
174
181
|
let tablesWithResults = [];
|
|
175
182
|
let tablesConfigured = 0;
|
|
@@ -182,18 +189,19 @@ const runSearch = async ({ q, _page, table }, req, res) => {
|
|
|
182
189
|
throw new InvalidConfiguration(
|
|
183
190
|
`View ${viewName} selected as search results for ${tableName}: view not found`
|
|
184
191
|
);
|
|
192
|
+
// search table using view
|
|
185
193
|
const vresps = await view.runMany(
|
|
186
194
|
{ _fts: q },
|
|
187
|
-
{ res, req, limit:
|
|
195
|
+
{ res, req, limit: page_size, offset }
|
|
188
196
|
);
|
|
189
197
|
let paginate = "";
|
|
190
|
-
if (vresps.length ===
|
|
198
|
+
if (vresps.length === page_size || current_page > 1) {
|
|
191
199
|
paginate = pagination({
|
|
192
200
|
current_page,
|
|
193
|
-
pages: current_page + (vresps.length ===
|
|
194
|
-
trailing_ellipsis: vresps.length ===
|
|
201
|
+
pages: current_page + (vresps.length === page_size ? 1 : 0),
|
|
202
|
+
trailing_ellipsis: vresps.length === page_size,
|
|
195
203
|
get_page_link: (n) =>
|
|
196
|
-
`javascript:gopage(${n},
|
|
204
|
+
`javascript:gopage(${n}, ${page_size}, undefined, {table:'${tableName}'})`,
|
|
197
205
|
});
|
|
198
206
|
}
|
|
199
207
|
|
|
@@ -207,9 +215,11 @@ const runSearch = async ({ q, _page, table }, req, res) => {
|
|
|
207
215
|
}
|
|
208
216
|
}
|
|
209
217
|
|
|
218
|
+
// Prepare search form
|
|
210
219
|
const form = searchForm();
|
|
211
220
|
form.validate({ q });
|
|
212
221
|
|
|
222
|
+
// Prepare search result visualization
|
|
213
223
|
const searchResult =
|
|
214
224
|
resp.length === 0
|
|
215
225
|
? [{ type: "card", contents: req.__("Not found") }]
|
|
@@ -250,6 +260,7 @@ const runSearch = async ({ q, _page, table }, req, res) => {
|
|
|
250
260
|
};
|
|
251
261
|
|
|
252
262
|
/**
|
|
263
|
+
* Execute search or only show search form
|
|
253
264
|
* @name get
|
|
254
265
|
* @function
|
|
255
266
|
* @memberof module:routes/search~searchRouter
|
|
@@ -258,6 +269,14 @@ const runSearch = async ({ q, _page, table }, req, res) => {
|
|
|
258
269
|
router.get(
|
|
259
270
|
"/",
|
|
260
271
|
error_catcher(async (req, res) => {
|
|
272
|
+
|
|
273
|
+
const min_role = getState().getConfig("min_role_search");
|
|
274
|
+
const role = (req.user || {}).role_id || 10;
|
|
275
|
+
if(role>min_role){
|
|
276
|
+
res.redirect("/"); // silent redirect to home page
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
261
280
|
if (req.query && req.query.q) {
|
|
262
281
|
await runSearch(req.query, req, res);
|
|
263
282
|
} else {
|
|
Binary file
|
package/tests/files.test.js
CHANGED
|
@@ -9,9 +9,11 @@ const {
|
|
|
9
9
|
toSucceed,
|
|
10
10
|
toNotInclude,
|
|
11
11
|
resetToFixtures,
|
|
12
|
+
toSucceedWithImage,
|
|
12
13
|
} = require("../auth/testhelp");
|
|
13
14
|
const db = require("@saltcorn/data/db");
|
|
14
15
|
const fs = require("fs").promises;
|
|
16
|
+
const path = require("path");
|
|
15
17
|
const File = require("@saltcorn/data/models/file");
|
|
16
18
|
const Field = require("@saltcorn/data/models/field");
|
|
17
19
|
const Table = require("@saltcorn/data/models/table");
|
|
@@ -20,14 +22,31 @@ const { table } = require("console");
|
|
|
20
22
|
|
|
21
23
|
beforeAll(async () => {
|
|
22
24
|
await resetToFixtures();
|
|
23
|
-
|
|
24
|
-
await fs.writeFile(fnm, "nevergonnagiveyouup");
|
|
25
|
-
};
|
|
25
|
+
await File.ensure_file_store();
|
|
26
26
|
await File.from_req_files(
|
|
27
|
-
{
|
|
27
|
+
{
|
|
28
|
+
mimetype: "image/png",
|
|
29
|
+
name: "rick.png",
|
|
30
|
+
mv: async (fnm) => {
|
|
31
|
+
await fs.writeFile(fnm, "nevergonnagiveyouup");
|
|
32
|
+
},
|
|
33
|
+
size: 245752,
|
|
34
|
+
},
|
|
28
35
|
1,
|
|
29
36
|
4
|
|
30
37
|
);
|
|
38
|
+
await File.from_req_files(
|
|
39
|
+
{
|
|
40
|
+
mimetype: "image/png",
|
|
41
|
+
name: "large-image.png",
|
|
42
|
+
mv: async (fnm) => {
|
|
43
|
+
await fs.copyFile(path.join(__dirname, "assets/large-image.png"), fnm);
|
|
44
|
+
},
|
|
45
|
+
size: 219422,
|
|
46
|
+
},
|
|
47
|
+
1,
|
|
48
|
+
10
|
|
49
|
+
);
|
|
31
50
|
});
|
|
32
51
|
afterAll(db.close);
|
|
33
52
|
|
|
@@ -70,6 +89,28 @@ describe("files admin", () => {
|
|
|
70
89
|
const app = await getApp({ disableCsrf: true });
|
|
71
90
|
await request(app).get("/files/serve/rick.png").expect(404);
|
|
72
91
|
});
|
|
92
|
+
it("serve public file", async () => {
|
|
93
|
+
const app = await getApp({ disableCsrf: true });
|
|
94
|
+
await request(app)
|
|
95
|
+
.get("/files/serve/large-image.png")
|
|
96
|
+
.expect(toSucceedWithImage({ lengthIs: (bs) => bs === 219422 }));
|
|
97
|
+
});
|
|
98
|
+
it("serve resized file", async () => {
|
|
99
|
+
const app = await getApp({ disableCsrf: true });
|
|
100
|
+
await request(app)
|
|
101
|
+
.get("/files/resize/200/100/large-image.png")
|
|
102
|
+
.expect(
|
|
103
|
+
toSucceedWithImage({ lengthIs: (bs) => bs < 100000 && bs > 2000 })
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
it("serve resized file without height", async () => {
|
|
107
|
+
const app = await getApp({ disableCsrf: true });
|
|
108
|
+
await request(app)
|
|
109
|
+
.get("/files/resize/200/0/large-image.png")
|
|
110
|
+
.expect(
|
|
111
|
+
toSucceedWithImage({ lengthIs: (bs) => bs < 100000 && bs > 2000 })
|
|
112
|
+
);
|
|
113
|
+
});
|
|
73
114
|
it("not download file to public", async () => {
|
|
74
115
|
const app = await getApp({ disableCsrf: true });
|
|
75
116
|
await request(app).get("/files/download/rick.png").expect(404);
|