not-node 6.3.96 → 6.3.99

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,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.3.96",
3
+ "version": "6.3.99",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/auth/rules.js CHANGED
@@ -94,7 +94,7 @@ function compareAuthStatus(rule, auth) {
94
94
  * Check rule against presented credentials
95
95
  * @param {import('../types').notRouteRule} rule action rule
96
96
  * @param {boolean} auth user state of auth
97
- * @param {Array<string>} role user state of role
97
+ * @param {string|Array<string>} role user state of role
98
98
  * @param {boolean} root user state of root
99
99
  * @return {boolean} pass or not
100
100
  */
@@ -103,21 +103,30 @@ function checkCredentials(rule, auth, role, root) {
103
103
  if (typeof rule === "undefined" || rule === null) {
104
104
  return false;
105
105
  } else {
106
+ let directivesUsed = 0;
106
107
  //posting message about obsolete options keys if found
107
108
  postWarning.obsoleteRuleFields(rule);
108
- //start comparing from top tier flags
109
- //if we have root/admin(obsolete) field field in rule compare only it
109
+ //compare all three auth directives types
110
+ //if any presented not equal - return false
111
+ //if none of directives presented in rule - return false
112
+ //root
110
113
  if (ruleHasRootDirective(rule)) {
111
- return compareWithRoot(rule, root);
112
- } else {
113
- //if we have roles in rule, then using role based aproach
114
- if (objHas(rule, "role")) {
115
- return compareRuleRoles(rule, role, auth);
116
- } else {
117
- //if no then just
118
- return compareAuthStatus(rule, auth);
114
+ directivesUsed++;
115
+ if (!compareWithRoot(rule, root)) {
116
+ return false;
119
117
  }
120
118
  }
119
+ //role checks auth too, so straight return
120
+ if (objHas(rule, "role")) {
121
+ return compareRuleRoles(rule, role, auth);
122
+ }
123
+ //auth, last one, so straight return. if got to here and auth presented, it rules everything
124
+ //have to check this and root to have rules like {root:false, auth: true} - every user but root
125
+ if (objHas(rule, "auth")) {
126
+ return compareAuthStatus(rule, auth);
127
+ }
128
+ //if no directives in rule - no user authentication
129
+ return !!directivesUsed;
121
130
  }
122
131
  }
123
132
 
@@ -1,3 +1,3 @@
1
1
  module.exports = (input) => {
2
- return input === "__CLEAR__" ? undefined : input;
2
+ return input === "__CLEAR__" ? null : input;
3
3
  };
package/test/auth.js CHANGED
@@ -91,27 +91,27 @@ describe("Auth", function () {
91
91
  role: "root",
92
92
  auth: true,
93
93
  };
94
- it("rule (admin, root, authentificated), auth - true, role - root, admin - true ", function () {
94
+ it("rule (admin, root, authentificated), auth - true, role - root, root - true ", function () {
95
95
  const res = auth.checkCredentials(rule, true, "root", true);
96
96
  expect(res).to.deep.equal(true);
97
97
  });
98
98
 
99
- it("rule (admin, root, authentificated), auth - true, role - root, admin - false ", function () {
99
+ it("rule (admin, root, authentificated), auth - true, role - root, root - false ", function () {
100
100
  const res = auth.checkCredentials(rule, true, "root", false);
101
101
  expect(res).to.deep.equal(false);
102
102
  });
103
103
 
104
- it("rule - empty, auth - true, role - root, admin - false ", function () {
104
+ it("rule - empty, auth - true, role - root, root - false ", function () {
105
105
  const res = auth.checkCredentials({}, true, "root", false);
106
- expect(res).to.deep.equal(true);
106
+ expect(res).to.deep.equal(false);
107
107
  });
108
108
 
109
- it("rule - null, auth - true, role - root, admin - false ", function () {
109
+ it("rule - null, auth - true, role - root, root - false ", function () {
110
110
  const res = auth.checkCredentials(null, true, "root", false);
111
111
  expect(res).to.deep.equal(false);
112
112
  });
113
113
 
114
- it("rule - (auth), auth - true, role - root, admin - false ", function () {
114
+ it("rule - (auth), auth - true, role - root, root - false ", function () {
115
115
  const res = auth.checkCredentials(
116
116
  { auth: true },
117
117
  true,
@@ -121,7 +121,7 @@ describe("Auth", function () {
121
121
  expect(res).to.deep.equal(true);
122
122
  });
123
123
 
124
- it("rule - (role: 'notActivated'), auth - true, role - root, admin - false ", function () {
124
+ it("rule - (role: 'notActivated'), auth - true, role - root, root - false ", function () {
125
125
  const res = auth.checkCredentials(
126
126
  { role: "notActivated" },
127
127
  true,
@@ -131,7 +131,7 @@ describe("Auth", function () {
131
131
  expect(res).to.deep.equal(false);
132
132
  });
133
133
 
134
- it("rule - (role: 'user', auth), auth - true, role - user, admin - false ", function () {
134
+ it("rule - (role: 'user', auth), auth - true, role - user, root - false ", function () {
135
135
  const res = auth.checkCredentials(
136
136
  { role: "user", auth: true },
137
137
  true,
@@ -141,7 +141,7 @@ describe("Auth", function () {
141
141
  expect(res).to.deep.equal(true);
142
142
  });
143
143
 
144
- it("rule - (role: 'user', !auth), auth - false, role - user, admin - false ", function () {
144
+ it("rule - (role: 'user', !auth), auth - false, role - user, root - false ", function () {
145
145
  const res = auth.checkCredentials(
146
146
  { role: "user", auth: false },
147
147
  false,
@@ -151,7 +151,7 @@ describe("Auth", function () {
151
151
  expect(res).to.deep.equal(true);
152
152
  });
153
153
 
154
- it("rule - (role: 'user'), auth - false, role - user, admin - false ", function () {
154
+ it("rule - (role: 'user'), auth - false, role - user, root - false ", function () {
155
155
  const res = auth.checkCredentials(
156
156
  { role: "user" },
157
157
  false,
@@ -161,7 +161,7 @@ describe("Auth", function () {
161
161
  expect(res).to.deep.equal(true);
162
162
  });
163
163
 
164
- it("rule - (auth), auth - true, role - user, admin - false ", function () {
164
+ it("rule - (auth), auth - true, role - user, root - false ", function () {
165
165
  const res = auth.checkCredentials(
166
166
  { auth: true },
167
167
  true,
@@ -171,7 +171,7 @@ describe("Auth", function () {
171
171
  expect(res).to.deep.equal(true);
172
172
  });
173
173
 
174
- it("rule - (!auth), auth - false, role - user, admin - false ", function () {
174
+ it("rule - (!auth), auth - false, role - user, root - false ", function () {
175
175
  const res = auth.checkCredentials(
176
176
  { auth: false },
177
177
  false,
@@ -181,7 +181,7 @@ describe("Auth", function () {
181
181
  expect(res).to.deep.equal(true);
182
182
  });
183
183
 
184
- it("rule - (auth), auth - false, role - user, admin - false ", function () {
184
+ it("rule - (auth), auth - false, role - user, root - false ", function () {
185
185
  const res = auth.checkCredentials(
186
186
  { auth: true },
187
187
  false,
@@ -191,7 +191,7 @@ describe("Auth", function () {
191
191
  expect(res).to.deep.equal(false);
192
192
  });
193
193
 
194
- it("rule - (!auth), auth - false, role - user, admin - true ", function () {
194
+ it("rule - (!auth), auth - false, role - user, root - true ", function () {
195
195
  const res = auth.checkCredentials(
196
196
  { auth: false },
197
197
  false,
@@ -201,7 +201,7 @@ describe("Auth", function () {
201
201
  expect(res).to.deep.equal(true);
202
202
  });
203
203
 
204
- it("rule - (admin), auth - false, role - user, admin - true ", function () {
204
+ it("rule - (admin), auth - false, role - user, root - true ", function () {
205
205
  const res = auth.checkCredentials(
206
206
  { admin: true },
207
207
  false,
@@ -211,7 +211,7 @@ describe("Auth", function () {
211
211
  expect(res).to.deep.equal(true);
212
212
  });
213
213
 
214
- it("rule - (!auth, 'notActivated', false), auth - false, role - notActivated, admin - false ", function () {
214
+ it("rule - (!auth, 'notActivated', false), auth - false, role - notActivated, root - false ", function () {
215
215
  const res = auth.checkCredentials(
216
216
  { auth: false, role: "notActivated" },
217
217
  false,
@@ -221,7 +221,7 @@ describe("Auth", function () {
221
221
  expect(res).to.deep.equal(true);
222
222
  });
223
223
 
224
- it("rule - (!auth, 'notActivated', undefined), auth - false, role - false, admin - false ", function () {
224
+ it("rule - (!auth, 'notActivated', undefined), auth - false, role - false, root - false ", function () {
225
225
  const res = auth.checkCredentials(
226
226
  { auth: false, role: "notActivated" },
227
227
  false,
@@ -231,7 +231,7 @@ describe("Auth", function () {
231
231
  expect(res).to.deep.equal(false);
232
232
  });
233
233
 
234
- it("rule - (admin), auth - false, role - false, admin - true ", function () {
234
+ it("rule - (admin), auth - false, role - false, root - true ", function () {
235
235
  const res = auth.checkCredentials(
236
236
  { admin: true },
237
237
  false,
@@ -18,4 +18,16 @@ describe("Form//Transformers", () => {
18
18
  field3: [1, "string", false],
19
19
  });
20
20
  });
21
+
22
+ it("__CLEAR__ presented in input", () => {
23
+ const input = "__CLEAR__";
24
+ const result = transformers.__CLEAR__(input);
25
+ expect(result).to.be.null;
26
+ });
27
+
28
+ it("__CLEAR__ not presented in input", () => {
29
+ const input = "";
30
+ const result = transformers.__CLEAR__(input);
31
+ expect(result).to.be.not.null;
32
+ });
21
33
  });
@@ -32,12 +32,10 @@ module.exports = {
32
32
  description: "not-node:crud_create_action_form_description",
33
33
  rules: [
34
34
  {
35
- auth: true,
36
35
  role: "admin",
37
36
  fields: [<%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,<% if (ownage){ %>"owner",<% } %>],
38
37
  },
39
38
  {
40
- auth: true,
41
39
  role: ["client", "confirmed"],
42
40
  fields: [<%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>],
43
41
  },
@@ -54,7 +52,6 @@ module.exports = {
54
52
  description: "not-node:crud_read_action_form_description",
55
53
  rules: [
56
54
  {
57
- auth: true,
58
55
  role: "admin",
59
56
  fields: [
60
57
  "_id",
@@ -65,7 +62,6 @@ module.exports = {
65
62
  ],
66
63
  },
67
64
  {
68
- auth: true,
69
65
  role: ["client", "confirmed"],
70
66
  fields: [
71
67
  "_id",
@@ -86,7 +82,6 @@ module.exports = {
86
82
  description: "not-node:crud_read_action_form_description",
87
83
  rules: [
88
84
  {
89
- auth: true,
90
85
  role: "admin",
91
86
  fields: [
92
87
  "_id",
@@ -97,7 +92,6 @@ module.exports = {
97
92
  ],
98
93
  },
99
94
  {
100
- auth: true,
101
95
  role: ["client", "confirmed"],
102
96
  fields: [
103
97
  <% if (increment){ %>"<%- modelName %>ID",<% } %>
@@ -117,7 +111,6 @@ module.exports = {
117
111
  method: "post",
118
112
  rules: [
119
113
  {
120
- auth: true,
121
114
  role: ["admin"],
122
115
  fields: [
123
116
  <%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,
@@ -125,7 +118,6 @@ module.exports = {
125
118
  ],
126
119
  },
127
120
  {
128
- auth: true,
129
121
  role: ["client", "confirmed"],
130
122
  fields: [<%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>],
131
123
  },
@@ -142,11 +134,9 @@ module.exports = {
142
134
  method: "delete",
143
135
  rules: [
144
136
  {
145
- auth: true,
146
137
  role: ["admin"],
147
138
  },
148
139
  {
149
- auth: true,
150
140
  role: ["client", "confirmed"],
151
141
  },
152
142
  ],
@@ -163,7 +153,6 @@ module.exports = {
163
153
  data: ["pager", "sorter", "filter", "search"],
164
154
  rules: [
165
155
  {
166
- auth: true,
167
156
  role: ["admin"],
168
157
  },
169
158
  {
@@ -187,8 +176,7 @@ module.exports = {
187
176
  postFix: actionNamePath,
188
177
  rules: [
189
178
  {
190
- auth: true,
191
- role: ["manager"],
179
+ role: ["admin"],
192
180
  },
193
181
  {
194
182
  auth: true,