@saltcorn/server 0.8.6-beta.2 → 0.8.6-beta.3
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/app.js +3 -3
- package/auth/admin.js +4 -0
- package/auth/roleadmin.js +7 -4
- package/auth/routes.js +1 -1
- package/errors.js +1 -1
- package/locales/en.json +16 -3
- package/locales/pl.json +1 -1
- package/locales/ru.json +38 -2
- package/locales/uk.json +1170 -0
- package/package.json +8 -8
- package/public/dayjs.min.js +1 -0
- package/public/saltcorn-common.js +37 -29
- package/routes/admin.js +23 -0
- package/routes/api.js +21 -20
- package/routes/common_lists.js +4 -1
- package/routes/delete.js +3 -3
- package/routes/edit.js +1 -1
- package/routes/fields.js +8 -1
- package/routes/files.js +7 -7
- package/routes/homepage.js +3 -3
- package/routes/index.js +4 -41
- package/routes/menu.js +1 -1
- package/routes/page.js +2 -2
- package/routes/pageedit.js +2 -2
- package/routes/scapi.js +1 -1
- package/routes/search.js +4 -5
- package/routes/sync.js +170 -0
- package/routes/tables.js +4 -0
- package/routes/tenant.js +74 -27
- package/routes/view.js +3 -3
- package/routes/viewedit.js +24 -11
- package/tests/admin.test.js +8 -8
- package/tests/auth.test.js +13 -13
- package/tests/crud.test.js +2 -2
- package/tests/files.test.js +6 -6
- package/tests/kittens.test.js +11 -11
- package/tests/page.test.js +4 -5
- package/tests/sync.test.js +187 -0
- package/tests/table.test.js +6 -6
- package/tests/tenant.test.js +3 -3
- package/tests/view.test.js +128 -1
- package/tests/viewedit.test.js +4 -4
- package/wrapper.js +3 -2
package/tests/crud.test.js
CHANGED
|
@@ -61,7 +61,7 @@ describe("notifications", () => {
|
|
|
61
61
|
.expect(succeedJsonWith((n) => n === 0));
|
|
62
62
|
});
|
|
63
63
|
it("add notification", async () => {
|
|
64
|
-
const user = await User.findOne({ role_id:
|
|
64
|
+
const user = await User.findOne({ role_id: 40 });
|
|
65
65
|
await Notification.create({
|
|
66
66
|
user_id: user.id,
|
|
67
67
|
title: "This is a staff announcement",
|
|
@@ -170,7 +170,7 @@ describe("homepage", () => {
|
|
|
170
170
|
name: "anewview",
|
|
171
171
|
viewtemplate: "List",
|
|
172
172
|
configuration: { columns: [], default_state: { foo: "bar" } },
|
|
173
|
-
min_role:
|
|
173
|
+
min_role: 100,
|
|
174
174
|
});
|
|
175
175
|
const loginCookie = await getAdminLoginCookie();
|
|
176
176
|
|
package/tests/files.test.js
CHANGED
|
@@ -33,7 +33,7 @@ beforeAll(async () => {
|
|
|
33
33
|
size: 245752,
|
|
34
34
|
},
|
|
35
35
|
1,
|
|
36
|
-
|
|
36
|
+
40
|
|
37
37
|
);
|
|
38
38
|
await File.from_req_files(
|
|
39
39
|
{
|
|
@@ -45,7 +45,7 @@ beforeAll(async () => {
|
|
|
45
45
|
size: 219422,
|
|
46
46
|
},
|
|
47
47
|
1,
|
|
48
|
-
|
|
48
|
+
100
|
|
49
49
|
);
|
|
50
50
|
});
|
|
51
51
|
afterAll(db.close);
|
|
@@ -121,7 +121,7 @@ describe("files admin", () => {
|
|
|
121
121
|
await request(app)
|
|
122
122
|
.post("/files/setrole/rick.png")
|
|
123
123
|
.set("Cookie", loginCookie)
|
|
124
|
-
.send("role=
|
|
124
|
+
.send("role=100")
|
|
125
125
|
.expect(toRedirect("/files?dir=."));
|
|
126
126
|
});
|
|
127
127
|
it("serve file to public after role change", async () => {
|
|
@@ -150,7 +150,7 @@ describe("files admin", () => {
|
|
|
150
150
|
describe("files edit", () => {
|
|
151
151
|
it("creates table and view", async () => {
|
|
152
152
|
const table = await Table.create("thefiletable");
|
|
153
|
-
await table.update({ min_role_read:
|
|
153
|
+
await table.update({ min_role_read: 80, min_role_write: 80 });
|
|
154
154
|
await Field.create({
|
|
155
155
|
table,
|
|
156
156
|
name: "first_name",
|
|
@@ -171,7 +171,7 @@ describe("files edit", () => {
|
|
|
171
171
|
columns: [
|
|
172
172
|
{ type: "Field", field_name: "mugshot", fieldview: "upload" },
|
|
173
173
|
{ type: "Field", field_name: "first_name", fieldview: "edit" },
|
|
174
|
-
{ type: "Action", action_name: "Save", minRole:
|
|
174
|
+
{ type: "Action", action_name: "Save", minRole: 100 },
|
|
175
175
|
],
|
|
176
176
|
layout: {
|
|
177
177
|
above: [
|
|
@@ -188,7 +188,7 @@ describe("files edit", () => {
|
|
|
188
188
|
],
|
|
189
189
|
},
|
|
190
190
|
},
|
|
191
|
-
min_role:
|
|
191
|
+
min_role: 100,
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
194
|
it("shows edit view", async () => {
|
package/tests/kittens.test.js
CHANGED
|
@@ -24,8 +24,8 @@ const pack = {
|
|
|
24
24
|
tables: [
|
|
25
25
|
{
|
|
26
26
|
name: "cats",
|
|
27
|
-
min_role_read:
|
|
28
|
-
min_role_write:
|
|
27
|
+
min_role_read: 100,
|
|
28
|
+
min_role_write: 100,
|
|
29
29
|
versioned: false,
|
|
30
30
|
fields: [
|
|
31
31
|
{
|
|
@@ -75,7 +75,7 @@ const pack = {
|
|
|
75
75
|
latitude_field: "lat",
|
|
76
76
|
longtitude_field: "long",
|
|
77
77
|
},
|
|
78
|
-
min_role:
|
|
78
|
+
min_role: 100,
|
|
79
79
|
table: "cats",
|
|
80
80
|
},
|
|
81
81
|
{
|
|
@@ -100,7 +100,7 @@ const pack = {
|
|
|
100
100
|
],
|
|
101
101
|
viewname: "ShowName",
|
|
102
102
|
},
|
|
103
|
-
min_role:
|
|
103
|
+
min_role: 100,
|
|
104
104
|
table: "cats",
|
|
105
105
|
},
|
|
106
106
|
{
|
|
@@ -115,7 +115,7 @@ const pack = {
|
|
|
115
115
|
reload_on_drag: false,
|
|
116
116
|
view_to_create: "",
|
|
117
117
|
},
|
|
118
|
-
min_role:
|
|
118
|
+
min_role: 100,
|
|
119
119
|
table: "cats",
|
|
120
120
|
},
|
|
121
121
|
{
|
|
@@ -130,7 +130,7 @@ const pack = {
|
|
|
130
130
|
reload_on_drag: false,
|
|
131
131
|
view_to_create: "",
|
|
132
132
|
},
|
|
133
|
-
min_role:
|
|
133
|
+
min_role: 100,
|
|
134
134
|
table: "cats",
|
|
135
135
|
},
|
|
136
136
|
{
|
|
@@ -151,7 +151,7 @@ const pack = {
|
|
|
151
151
|
columns: [],
|
|
152
152
|
viewname: "NestedShow",
|
|
153
153
|
},
|
|
154
|
-
min_role:
|
|
154
|
+
min_role: 100,
|
|
155
155
|
table: "cats",
|
|
156
156
|
},
|
|
157
157
|
{
|
|
@@ -165,7 +165,7 @@ const pack = {
|
|
|
165
165
|
latitude_field: "lat",
|
|
166
166
|
longtitude_field: "long",
|
|
167
167
|
},
|
|
168
|
-
min_role:
|
|
168
|
+
min_role: 100,
|
|
169
169
|
table: "cats",
|
|
170
170
|
},
|
|
171
171
|
{
|
|
@@ -180,7 +180,7 @@ const pack = {
|
|
|
180
180
|
reload_on_drag: false,
|
|
181
181
|
view_to_create: "",
|
|
182
182
|
},
|
|
183
|
-
min_role:
|
|
183
|
+
min_role: 100,
|
|
184
184
|
table: "cats",
|
|
185
185
|
},
|
|
186
186
|
{
|
|
@@ -201,7 +201,7 @@ const pack = {
|
|
|
201
201
|
columns: [],
|
|
202
202
|
viewname: "NestedShowNoPop",
|
|
203
203
|
},
|
|
204
|
-
min_role:
|
|
204
|
+
min_role: 100,
|
|
205
205
|
table: "cats",
|
|
206
206
|
},
|
|
207
207
|
{
|
|
@@ -216,7 +216,7 @@ const pack = {
|
|
|
216
216
|
reload_on_drag: false,
|
|
217
217
|
view_to_create: "",
|
|
218
218
|
},
|
|
219
|
-
min_role:
|
|
219
|
+
min_role: 100,
|
|
220
220
|
table: "cats",
|
|
221
221
|
},
|
|
222
222
|
],
|
package/tests/page.test.js
CHANGED
|
@@ -44,7 +44,7 @@ describe("page create", () => {
|
|
|
44
44
|
const loginCookie = await getAdminLoginCookie();
|
|
45
45
|
await request(app)
|
|
46
46
|
.post("/pageedit/edit-properties")
|
|
47
|
-
.send("name=whales&title=Whales&description=about+whales&min_role=
|
|
47
|
+
.send("name=whales&title=Whales&description=about+whales&min_role=100")
|
|
48
48
|
.set("Cookie", loginCookie)
|
|
49
49
|
.expect(toRedirect("/pageedit/edit/whales"));
|
|
50
50
|
});
|
|
@@ -76,7 +76,7 @@ describe("page action", () => {
|
|
|
76
76
|
name: "pagewithaction",
|
|
77
77
|
title: "",
|
|
78
78
|
description: "",
|
|
79
|
-
min_role:
|
|
79
|
+
min_role: 100,
|
|
80
80
|
id: 2,
|
|
81
81
|
layout: {
|
|
82
82
|
widths: [6, 6],
|
|
@@ -85,7 +85,7 @@ describe("page action", () => {
|
|
|
85
85
|
{
|
|
86
86
|
type: "action",
|
|
87
87
|
rndid: "56f3ac",
|
|
88
|
-
minRole:
|
|
88
|
+
minRole: 100,
|
|
89
89
|
isFormula: {},
|
|
90
90
|
action_icon: "far fa-angry",
|
|
91
91
|
action_name: "run_js_code",
|
|
@@ -142,7 +142,7 @@ describe("pageedit", () => {
|
|
|
142
142
|
.send("name=a_page")
|
|
143
143
|
.send("title=mytitle")
|
|
144
144
|
.send("description=mydescript")
|
|
145
|
-
.send("min_role=
|
|
145
|
+
.send("min_role=80")
|
|
146
146
|
.send("id=1")
|
|
147
147
|
.expect(toRedirect("/pageedit/"));
|
|
148
148
|
});
|
|
@@ -153,7 +153,6 @@ describe("pageedit", () => {
|
|
|
153
153
|
.get("/pageedit/edit/a_page")
|
|
154
154
|
.set("Cookie", loginCookie)
|
|
155
155
|
.expect(toInclude("<script>builder.renderBuilder"));
|
|
156
|
-
|
|
157
156
|
});
|
|
158
157
|
|
|
159
158
|
it("sets root page", async () => {
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
const request = require("supertest");
|
|
2
|
+
const getApp = require("../app");
|
|
3
|
+
const {
|
|
4
|
+
getUserLoginCookie,
|
|
5
|
+
getStaffLoginCookie,
|
|
6
|
+
getAdminLoginCookie,
|
|
7
|
+
resetToFixtures,
|
|
8
|
+
} = require("../auth/testhelp");
|
|
9
|
+
const db = require("@saltcorn/data/db");
|
|
10
|
+
|
|
11
|
+
const Table = require("@saltcorn/data/models/table");
|
|
12
|
+
|
|
13
|
+
beforeAll(async () => {
|
|
14
|
+
await resetToFixtures();
|
|
15
|
+
});
|
|
16
|
+
afterAll(db.close);
|
|
17
|
+
|
|
18
|
+
describe("Load offline data", () => {
|
|
19
|
+
it("public request", async () => {
|
|
20
|
+
const app = await getApp({ disableCsrf: true });
|
|
21
|
+
const resp = await request(app).get("/sync/table_data");
|
|
22
|
+
for (const [k, v] of Object.entries(resp._body)) {
|
|
23
|
+
expect(v.rows.length).toBe(k === "books" ? 2 : 0);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("user request", async () => {
|
|
28
|
+
const app = await getApp({ disableCsrf: true });
|
|
29
|
+
const loginCookie = await getUserLoginCookie();
|
|
30
|
+
const resp = await request(app)
|
|
31
|
+
.get("/sync/table_data")
|
|
32
|
+
.set("Cookie", loginCookie);
|
|
33
|
+
const data = resp._body;
|
|
34
|
+
expect(data.patients.rows.length).toBe(0);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("admin request", async () => {
|
|
38
|
+
const app = await getApp({ disableCsrf: true });
|
|
39
|
+
const loginCookie = await getAdminLoginCookie();
|
|
40
|
+
const resp = await request(app)
|
|
41
|
+
.get("/sync/table_data")
|
|
42
|
+
.set("Cookie", loginCookie);
|
|
43
|
+
const data = resp._body;
|
|
44
|
+
expect(data.patients.rows.length).toBe(2);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("Synchronise with mobile offline data", () => {
|
|
49
|
+
if (!db.isSQLite) {
|
|
50
|
+
it("not permitted", async () => {
|
|
51
|
+
const app = await getApp({ disableCsrf: true });
|
|
52
|
+
const loginCookie = await getUserLoginCookie();
|
|
53
|
+
const uploadResp = await request(app)
|
|
54
|
+
.post("/sync/table_data")
|
|
55
|
+
.set("Cookie", loginCookie)
|
|
56
|
+
.send({
|
|
57
|
+
data: {
|
|
58
|
+
patients: [
|
|
59
|
+
{
|
|
60
|
+
name: "Brad Pitt",
|
|
61
|
+
favbook: 2,
|
|
62
|
+
parent: 1,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 84,
|
|
66
|
+
name: "Pitt Brad",
|
|
67
|
+
favbook: 2,
|
|
68
|
+
parent: 1,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
const translateIds = uploadResp._body.translateIds;
|
|
74
|
+
expect(translateIds).toBeDefined();
|
|
75
|
+
expect(Object.keys(translateIds).length).toBe(0);
|
|
76
|
+
|
|
77
|
+
const adminCookie = await getAdminLoginCookie();
|
|
78
|
+
const downloadResp = await request(app)
|
|
79
|
+
.get("/sync/table_data")
|
|
80
|
+
.set("Cookie", adminCookie);
|
|
81
|
+
const data = downloadResp._body;
|
|
82
|
+
expect(data.patients.rows.length).toBe(2);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("upload patients and books", async () => {
|
|
86
|
+
const app = await getApp({ disableCsrf: true });
|
|
87
|
+
const adminCookie = await getAdminLoginCookie();
|
|
88
|
+
const uploadResp = await request(app)
|
|
89
|
+
.post("/sync/table_data")
|
|
90
|
+
.set("Cookie", adminCookie)
|
|
91
|
+
.send({
|
|
92
|
+
data: {
|
|
93
|
+
patients: [
|
|
94
|
+
{
|
|
95
|
+
name: "Brad Pitt",
|
|
96
|
+
favbook: 2,
|
|
97
|
+
parent: 1,
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
id: 84, // will be translated to 3
|
|
101
|
+
name: "Pitt Brad",
|
|
102
|
+
favbook: 2,
|
|
103
|
+
parent: 1,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
books: [
|
|
107
|
+
{
|
|
108
|
+
id: 3, // stays at 3
|
|
109
|
+
author: "foo",
|
|
110
|
+
pages: 20,
|
|
111
|
+
publisher: 1,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
const translateIds = uploadResp._body.translateIds;
|
|
117
|
+
expect(translateIds).toBeDefined();
|
|
118
|
+
expect(Object.keys(translateIds).length).toBe(1);
|
|
119
|
+
expect(translateIds.patients.length).toBe(1);
|
|
120
|
+
expect(translateIds.patients[0]).toEqual({ from: 84, to: 3 });
|
|
121
|
+
|
|
122
|
+
const staffCookie = await getStaffLoginCookie();
|
|
123
|
+
const downloadResp = await request(app)
|
|
124
|
+
.get("/sync/table_data")
|
|
125
|
+
.set("Cookie", staffCookie);
|
|
126
|
+
const data = downloadResp._body;
|
|
127
|
+
expect(data.patients.rows.length).toBe(3);
|
|
128
|
+
expect(data.books.rows.length).toBe(3);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("upload with ownership_field", async () => {
|
|
132
|
+
const messagesTbl = Table.findOne({ name: "messages" });
|
|
133
|
+
const userField = messagesTbl
|
|
134
|
+
.getFields()
|
|
135
|
+
.find((field) => field.name === "user");
|
|
136
|
+
await messagesTbl.update({
|
|
137
|
+
min_role_read: 1,
|
|
138
|
+
min_role_write: 1,
|
|
139
|
+
ownership_field_id: userField.id,
|
|
140
|
+
});
|
|
141
|
+
const staffMsgId = await db.insert("messages", {
|
|
142
|
+
content: "message from staff",
|
|
143
|
+
user: 2,
|
|
144
|
+
room: 1,
|
|
145
|
+
});
|
|
146
|
+
const userMsgId = await db.insert("messages", {
|
|
147
|
+
content: "message from user",
|
|
148
|
+
user: 3,
|
|
149
|
+
room: 1,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const app = await getApp({ disableCsrf: true });
|
|
153
|
+
const userCookie = await getUserLoginCookie();
|
|
154
|
+
const uploadResp = await request(app)
|
|
155
|
+
.post("/sync/table_data")
|
|
156
|
+
.set("Cookie", userCookie)
|
|
157
|
+
.send({
|
|
158
|
+
data: {
|
|
159
|
+
messages: [
|
|
160
|
+
{
|
|
161
|
+
id: staffMsgId, // will be skipped
|
|
162
|
+
user: 3,
|
|
163
|
+
room: 1,
|
|
164
|
+
content: "offline change",
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: userMsgId, // will be updated because user is the owner
|
|
168
|
+
user: 2,
|
|
169
|
+
room: 1,
|
|
170
|
+
content: "offline change",
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
const translateIds = uploadResp._body.translateIds;
|
|
176
|
+
expect(translateIds).toBeDefined();
|
|
177
|
+
expect(Object.keys(translateIds).length).toBe(0);
|
|
178
|
+
// load the admin data
|
|
179
|
+
const adminCookie = await getAdminLoginCookie();
|
|
180
|
+
const resp = await request(app)
|
|
181
|
+
.get("/sync/table_data")
|
|
182
|
+
.set("Cookie", adminCookie);
|
|
183
|
+
const data = resp._body;
|
|
184
|
+
expect(data.messages.rows.length).toBe(4);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
});
|
package/tests/table.test.js
CHANGED
|
@@ -35,7 +35,7 @@ describe("Table Endpoints", () => {
|
|
|
35
35
|
.post("/table/")
|
|
36
36
|
.send("name=mypostedtable")
|
|
37
37
|
.set("Cookie", loginCookie)
|
|
38
|
-
.expect(toRedirect("/table/
|
|
38
|
+
.expect(toRedirect("/table/16"));
|
|
39
39
|
await request(app)
|
|
40
40
|
.get("/table/10")
|
|
41
41
|
.set("Cookie", loginCookie)
|
|
@@ -98,19 +98,19 @@ describe("Table Endpoints", () => {
|
|
|
98
98
|
await request(app)
|
|
99
99
|
.post(`/table`)
|
|
100
100
|
.set("Cookie", loginCookie)
|
|
101
|
-
.send("min_role_read=
|
|
101
|
+
.send("min_role_read=100&min_role_write=1&id=" + tbl.id)
|
|
102
102
|
.expect(toRedirect(`/table/${tbl.id}`));
|
|
103
103
|
await request(app).get(`/table/${tbl.id}`).set("Cookie", loginCookie);
|
|
104
104
|
await request(app)
|
|
105
105
|
.post(`/table`)
|
|
106
106
|
.set("Cookie", loginCookie)
|
|
107
|
-
.send("min_role_read=
|
|
107
|
+
.send("min_role_read=100&min_role_write=1&id=" + tbl.id)
|
|
108
108
|
.expect(toRedirect(`/table/${tbl.id}`));
|
|
109
109
|
await request(app).get(`/table/${tbl.id}`).set("Cookie", loginCookie);
|
|
110
110
|
await request(app)
|
|
111
111
|
.post(`/table`)
|
|
112
112
|
.set("Cookie", loginCookie)
|
|
113
|
-
.send("min_role_read=
|
|
113
|
+
.send("min_role_read=100&min_role_write=1&id=" + tbl.id)
|
|
114
114
|
.expect(toRedirect(`/table/${tbl.id}`));
|
|
115
115
|
await request(app).get(`/table/${tbl.id}`).set("Cookie", loginCookie);
|
|
116
116
|
});
|
|
@@ -121,7 +121,7 @@ describe("Table Endpoints", () => {
|
|
|
121
121
|
await request(app)
|
|
122
122
|
.post(`/table`)
|
|
123
123
|
.set("Cookie", loginCookie)
|
|
124
|
-
.send("min_role_read=
|
|
124
|
+
.send("min_role_read=80&name=exttab&external=on")
|
|
125
125
|
.expect(toRedirect(`/table/exttab`));
|
|
126
126
|
});
|
|
127
127
|
it("should download csv ", async () => {
|
|
@@ -151,7 +151,7 @@ Pencil, 0.5,2, t`;
|
|
|
151
151
|
.set("Cookie", loginCookie)
|
|
152
152
|
.field("name", "expenses")
|
|
153
153
|
.attach("file", Buffer.from(csv, "utf-8"))
|
|
154
|
-
.expect(toRedirect("/table/
|
|
154
|
+
.expect(toRedirect("/table/17"));
|
|
155
155
|
});
|
|
156
156
|
it("should upload csv to existing table", async () => {
|
|
157
157
|
const csv = `author,Pages
|
package/tests/tenant.test.js
CHANGED
|
@@ -27,7 +27,7 @@ describe("tenant routes", () => {
|
|
|
27
27
|
if (!db.isSQLite) {
|
|
28
28
|
it("shows create form", async () => {
|
|
29
29
|
db.enable_multi_tenant();
|
|
30
|
-
await getState().setConfig("role_to_create_tenant", "
|
|
30
|
+
await getState().setConfig("role_to_create_tenant", "100");
|
|
31
31
|
|
|
32
32
|
const app = await getApp({ disableCsrf: true });
|
|
33
33
|
await request(app).get("/tenant/create").expect(toInclude("subdomain"));
|
|
@@ -43,7 +43,7 @@ describe("tenant routes", () => {
|
|
|
43
43
|
|
|
44
44
|
it("creates tenant with capital letter", async () => {
|
|
45
45
|
db.enable_multi_tenant();
|
|
46
|
-
await getState().setConfig("role_to_create_tenant", "
|
|
46
|
+
await getState().setConfig("role_to_create_tenant", "100");
|
|
47
47
|
|
|
48
48
|
const app = await getApp({ disableCsrf: true });
|
|
49
49
|
await request(app)
|
|
@@ -55,7 +55,7 @@ describe("tenant routes", () => {
|
|
|
55
55
|
|
|
56
56
|
it("rejects existing tenant", async () => {
|
|
57
57
|
db.enable_multi_tenant();
|
|
58
|
-
await getState().setConfig("role_to_create_tenant", "
|
|
58
|
+
await getState().setConfig("role_to_create_tenant", "100");
|
|
59
59
|
const app = await getApp({ disableCsrf: true });
|
|
60
60
|
await request(app)
|
|
61
61
|
.post("/tenant/create")
|
package/tests/view.test.js
CHANGED
|
@@ -99,7 +99,7 @@ describe("view with routes", () => {
|
|
|
99
99
|
name: "aviewwithroutes",
|
|
100
100
|
viewtemplate: "ViewWithRoutes",
|
|
101
101
|
configuration: {},
|
|
102
|
-
min_role:
|
|
102
|
+
min_role: 80,
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
105
|
it("should redirect if not auth", async () => {
|
|
@@ -177,3 +177,130 @@ describe("render view with slug", () => {
|
|
|
177
177
|
.expect(toInclude(`Herman Melville`));
|
|
178
178
|
});
|
|
179
179
|
});
|
|
180
|
+
|
|
181
|
+
describe("inbound relations", () => {
|
|
182
|
+
it("view with inbound relation", async () => {
|
|
183
|
+
const app = await getApp({ disableCsrf: true });
|
|
184
|
+
const loginCookie = await getAdminLoginCookie();
|
|
185
|
+
await request(app)
|
|
186
|
+
.get("/view/show_user_with_blog_posts_feed?id=1")
|
|
187
|
+
.set("Cookie", loginCookie)
|
|
188
|
+
.expect(toInclude("Content of post APost A"))
|
|
189
|
+
.expect(toInclude("Content of post BPost B"))
|
|
190
|
+
.expect(toInclude("Content of post CPost C"));
|
|
191
|
+
|
|
192
|
+
await request(app)
|
|
193
|
+
.get("/view/show_user_with_blog_posts_feed?id=2")
|
|
194
|
+
.set("Cookie", loginCookie)
|
|
195
|
+
.expect(toNotInclude("Content of post APost A"))
|
|
196
|
+
.expect(toInclude("Content of post BPost B"))
|
|
197
|
+
.expect(toNotInclude("Content of post CPost C"));
|
|
198
|
+
|
|
199
|
+
await request(app)
|
|
200
|
+
.get("/view/show_user_with_blog_posts_feed?id=3")
|
|
201
|
+
.set("Cookie", loginCookie)
|
|
202
|
+
.expect(toInclude("Content of post APost A"))
|
|
203
|
+
.expect(toInclude("Content of post BPost B"))
|
|
204
|
+
.expect(toInclude("Content of post CPost C"));
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("view without inbound relation", async () => {
|
|
208
|
+
const app = await getApp({ disableCsrf: true });
|
|
209
|
+
const loginCookie = await getAdminLoginCookie();
|
|
210
|
+
await request(app)
|
|
211
|
+
.get("/view/show_user_with_independent_feed?id=1")
|
|
212
|
+
.set("Cookie", loginCookie)
|
|
213
|
+
.expect(toInclude("Content of post APost A"))
|
|
214
|
+
.expect(toInclude("Content of post BPost B"))
|
|
215
|
+
.expect(toInclude("Content of post CPost C"));
|
|
216
|
+
await request(app)
|
|
217
|
+
.get("/view/show_user_with_independent_feed?id=2")
|
|
218
|
+
.set("Cookie", loginCookie)
|
|
219
|
+
.expect(toInclude("Content of post APost A"))
|
|
220
|
+
.expect(toInclude("Content of post BPost B"))
|
|
221
|
+
.expect(toInclude("Content of post CPost C"));
|
|
222
|
+
await request(app)
|
|
223
|
+
.get("/view/show_user_with_independent_feed?id=3")
|
|
224
|
+
.set("Cookie", loginCookie)
|
|
225
|
+
.expect(toInclude("Content of post APost A"))
|
|
226
|
+
.expect(toInclude("Content of post BPost B"))
|
|
227
|
+
.expect(toInclude("Content of post CPost C"));
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("inbound relation from query", async () => {
|
|
231
|
+
const queryObj = {
|
|
232
|
+
relation:
|
|
233
|
+
".users.user_interested_in_topic$user.topic.blog_in_topic$topic.post",
|
|
234
|
+
srcId: 1,
|
|
235
|
+
};
|
|
236
|
+
const app = await getApp({ disableCsrf: true });
|
|
237
|
+
const loginCookie = await getAdminLoginCookie();
|
|
238
|
+
|
|
239
|
+
await request(app)
|
|
240
|
+
.get(
|
|
241
|
+
`/view/blog_posts_feed?_inbound_relation_path_=${encodeURIComponent(
|
|
242
|
+
JSON.stringify(queryObj)
|
|
243
|
+
)}`
|
|
244
|
+
)
|
|
245
|
+
.set("Cookie", loginCookie)
|
|
246
|
+
.expect(toInclude("Content of post APost A"))
|
|
247
|
+
.expect(toInclude("Content of post BPost B"))
|
|
248
|
+
.expect(toInclude("Content of post CPost C"));
|
|
249
|
+
|
|
250
|
+
queryObj.srcId = 2;
|
|
251
|
+
await request(app)
|
|
252
|
+
.get(
|
|
253
|
+
`/view/blog_posts_feed?_inbound_relation_path_=${encodeURIComponent(
|
|
254
|
+
JSON.stringify(queryObj)
|
|
255
|
+
)}`
|
|
256
|
+
)
|
|
257
|
+
.set("Cookie", loginCookie)
|
|
258
|
+
.expect(toNotInclude("Content of post APost A"))
|
|
259
|
+
.expect(toInclude("Content of post BPost B"))
|
|
260
|
+
.expect(toNotInclude("Content of post CPost C"));
|
|
261
|
+
|
|
262
|
+
queryObj.srcId = 3;
|
|
263
|
+
await request(app)
|
|
264
|
+
.get(
|
|
265
|
+
`/view/blog_posts_feed?_inbound_relation_path_=${encodeURIComponent(
|
|
266
|
+
JSON.stringify(queryObj)
|
|
267
|
+
)}`
|
|
268
|
+
)
|
|
269
|
+
.set("Cookie", loginCookie)
|
|
270
|
+
.expect(toInclude("Content of post APost A"))
|
|
271
|
+
.expect(toInclude("Content of post BPost B"))
|
|
272
|
+
.expect(toInclude("Content of post CPost C"));
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("inbound relation with levels from query", async () => {
|
|
276
|
+
const queryObj = {
|
|
277
|
+
relation:
|
|
278
|
+
".users.user_interested_in_topic$user.topic.inbound_inbound$topic.bp_inbound.post",
|
|
279
|
+
srcId: 1,
|
|
280
|
+
};
|
|
281
|
+
const app = await getApp({ disableCsrf: true });
|
|
282
|
+
const loginCookie = await getAdminLoginCookie();
|
|
283
|
+
await request(app)
|
|
284
|
+
.get(
|
|
285
|
+
`/view/blog_posts_feed?_inbound_relation_path_=${encodeURIComponent(
|
|
286
|
+
JSON.stringify(queryObj)
|
|
287
|
+
)}`
|
|
288
|
+
)
|
|
289
|
+
.set("Cookie", loginCookie)
|
|
290
|
+
.expect(toInclude("Content of post APost A"))
|
|
291
|
+
.expect(toNotInclude("Content of post BPost B"))
|
|
292
|
+
.expect(toInclude("Content of post CPost C"));
|
|
293
|
+
|
|
294
|
+
queryObj.srcId = 2;
|
|
295
|
+
await request(app)
|
|
296
|
+
.get(
|
|
297
|
+
`/view/blog_posts_feed?_inbound_relation_path_=${encodeURIComponent(
|
|
298
|
+
JSON.stringify(queryObj)
|
|
299
|
+
)}`
|
|
300
|
+
)
|
|
301
|
+
.set("Cookie", loginCookie)
|
|
302
|
+
.expect(toNotInclude("Content of post APost A"))
|
|
303
|
+
.expect(toNotInclude("Content of post BPost B"))
|
|
304
|
+
.expect(toNotInclude("Content of post CPost C"));
|
|
305
|
+
});
|
|
306
|
+
});
|
package/tests/viewedit.test.js
CHANGED
|
@@ -53,7 +53,7 @@ describe("viewedit edit endpoint", () => {
|
|
|
53
53
|
.send("table_name=books")
|
|
54
54
|
.send("id=" + v.id)
|
|
55
55
|
.send("name=authorlist")
|
|
56
|
-
.send("min_role=
|
|
56
|
+
.send("min_role=100")
|
|
57
57
|
.set("Cookie", loginCookie)
|
|
58
58
|
.expect(toRedirect("/viewedit/config/authorlist"));
|
|
59
59
|
});
|
|
@@ -95,7 +95,7 @@ describe("viewedit new List", () => {
|
|
|
95
95
|
.send("viewtemplate=List")
|
|
96
96
|
.send("table_name=books")
|
|
97
97
|
.send("name=mybooklist")
|
|
98
|
-
.send("min_role=
|
|
98
|
+
.send("min_role=80")
|
|
99
99
|
.set("Cookie", loginCookie)
|
|
100
100
|
.expect(toRedirect("/viewedit/config/mybooklist"));
|
|
101
101
|
//expect(res.text.includes("View configuration")).toBe(true);
|
|
@@ -212,7 +212,7 @@ describe("viewedit new List with one field", () => {
|
|
|
212
212
|
.send("viewtemplate=List")
|
|
213
213
|
.send("table_name=books")
|
|
214
214
|
.send("name=mybooklist1")
|
|
215
|
-
.send("min_role=
|
|
215
|
+
.send("min_role=80")
|
|
216
216
|
.set("Cookie", loginCookie)
|
|
217
217
|
.expect(toRedirect("/viewedit/config/mybooklist1"));
|
|
218
218
|
//expect(res.text.includes("View configuration")).toBe(true);
|
|
@@ -334,7 +334,7 @@ describe("viewedit new Show", () => {
|
|
|
334
334
|
.send("viewtemplate=Show")
|
|
335
335
|
.send("table_name=books")
|
|
336
336
|
.send("name=mybook")
|
|
337
|
-
.send("min_role=
|
|
337
|
+
.send("min_role=80")
|
|
338
338
|
.set("Cookie", loginCookie)
|
|
339
339
|
.expect(toRedirect("/viewedit/config/mybook"));
|
|
340
340
|
//expect(res.text.includes("View configuration")).toBe(true);
|
package/wrapper.js
CHANGED
|
@@ -27,7 +27,7 @@ const getFlashes = (req) =>
|
|
|
27
27
|
const get_menu = (req) => {
|
|
28
28
|
const isAuth = req.user && req.user.id;
|
|
29
29
|
const state = getState();
|
|
30
|
-
const role = (req.user || {}).role_id ||
|
|
30
|
+
const role = (req.user || {}).role_id || 100;
|
|
31
31
|
|
|
32
32
|
const allow_signup = state.getConfig("allow_signup");
|
|
33
33
|
const notification_in_menu = state.getConfig("notification_in_menu");
|
|
@@ -192,6 +192,7 @@ const get_headers = (req, version_tag, description, extras = []) => {
|
|
|
192
192
|
{ css: `/static_assets/${version_tag}/saltcorn.css` },
|
|
193
193
|
{ script: `/static_assets/${version_tag}/saltcorn-common.js` },
|
|
194
194
|
{ script: `/static_assets/${version_tag}/saltcorn.js` },
|
|
195
|
+
{ script: `/static_assets/${version_tag}/dayjs.min.js` },
|
|
195
196
|
];
|
|
196
197
|
let from_cfg = [];
|
|
197
198
|
if (state.getConfig("page_custom_css", ""))
|
|
@@ -245,7 +246,7 @@ module.exports = (version_tag) =>
|
|
|
245
246
|
* @param next
|
|
246
247
|
*/
|
|
247
248
|
function (req, res, next) {
|
|
248
|
-
const role = (req.user || {}).role_id ||
|
|
249
|
+
const role = (req.user || {}).role_id || 100;
|
|
249
250
|
|
|
250
251
|
res.sendAuthWrap = function (title, form, authLinks, ...html) {
|
|
251
252
|
const state = getState();
|