corefwnode 3.0.2 → 3.0.4

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/index.js CHANGED
@@ -1,240 +1,240 @@
1
- // globals
2
- const ObjClasses = require('./objects')();
3
- const Language = require('./lib/Language.js');
4
- const MySQL = require('./lib/MySql');
5
- const ErrorCodes = require('./lib/ErrorCodes');
6
- const Observer = require(('./lib/Observer'));
7
- const CoreError = require('./lib/errors/CoreError');
8
- const SQLError = require('./lib/errors/SQLError');
9
- const CfwObject = require('./lib/CfwObject');
10
- const GeneralHandling = require('./lib/GeneralHandling');
11
-
12
- class Library
13
- {
14
- constructor(config)
15
- {
16
- const me = this;
17
-
18
- global.lib = me;
19
-
20
- me.config = config;
21
-
22
- me.observer = new Observer();
23
-
24
- (async () =>
25
- {
26
- // init db
27
- me.db = await MySQL.init(config.mysql);
28
- await me.init();
29
- await me.start();
30
- })();
31
- }
32
-
33
- async init()
34
- {
35
- const me = this;
36
-
37
- try
38
- {
39
- await me.setProps();
40
- await me.setAclGroups();
41
-
42
- // init language
43
- if (me.lang === undefined)
44
- {
45
- me.lang = new Language();
46
- }
47
-
48
- await me.lang.fillTrans();
49
-
50
- if (me.unregisteredSession === undefined)
51
- {
52
- me.unregisteredSession = new ObjClasses.session.class();
53
- }
54
-
55
- me.afterinit();
56
- }
57
- catch (error)
58
- {
59
- console.error(error.message);
60
- }
61
- }
62
-
63
- afterinit()
64
- {
65
- return this;
66
- }
67
-
68
- start()
69
- {
70
- return this;
71
- }
72
-
73
- async setProps()
74
- {
75
- const me = this;
76
-
77
- try
78
- {
79
- const results = await me.db.query('SELECT * FROM site_props');
80
-
81
- me.props = {};
82
- for (let i = 0; i < results.length; i += 1)
83
- {
84
- const row = results[i];
85
- me.props[row.key] = row.value;
86
- }
87
- }
88
- catch (error)
89
- {
90
- console.error(error);
91
- }
92
- }
93
-
94
- async setAclGroups()
95
- {
96
- try
97
- {
98
- const me = this;
99
- const acl = {};
100
- const objects = [];
101
- const groups = [];
102
-
103
- let results = await me.db.query('SELECT * FROM acl_objects o');
104
-
105
- for (let i = 0; i < results.length; i += 1)
106
- {
107
- objects.push(results[i]);
108
- }
109
-
110
- results = await me.db.query('SELECT * FROM acl_groups p');
111
-
112
- for (let i = 0; i < results.length; i += 1)
113
- {
114
- groups.push(results[i]);
115
- }
116
-
117
- const promises = [];
118
- for (let x = 0; x < groups.length; x += 1)
119
- {
120
- const group = groups[x];
121
- const { groupId } = group;
122
-
123
- if (typeof acl[groupId] === 'undefined')
124
- {
125
- acl[groupId] = {};
126
- }
127
-
128
- promises.push(me.setPrivilagesByGroup(groupId, acl, objects));
129
- }
130
-
131
- await Promise.all(promises);
132
-
133
- me.acl = acl;
134
-
135
- return acl;
136
- }
137
- catch (error)
138
- {
139
- return {
140
- error: true,
141
- notice: error.toString(),
142
- };
143
- }
144
- }
145
-
146
- async setPrivilagesByGroup(groupId, acl, objects)
147
- {
148
- const me = this;
149
- try
150
- {
151
- const privilages = {};
152
-
153
- const results = await me.db.query('SELECT * FROM acl_privilages p WHERE p.groupId=?', [groupId]);
154
-
155
- for (let i = 0; i < results.length; i += 1)
156
- {
157
- const row = results[i];
158
- privilages[row.objectId] = row;
159
- }
160
-
161
- for (let i = 0; i < objects.length; i += 1)
162
- {
163
- const value = objects[i];
164
- value.objectName = value.objectName.toLowerCase();
165
- if (typeof value.objectFunction !== 'undefined' && value.objectFunction !== '')
166
- {
167
- value.objectFunction = value.objectFunction.toLowerCase();
168
- }
169
- if (typeof acl[groupId][value.objectName] === 'undefined')
170
- {
171
- // eslint-disable-next-line no-param-reassign
172
- acl[groupId][value.objectName] = {};
173
- }
174
- if (typeof privilages[value.objectId] !== 'undefined')
175
- {
176
- if (typeof value.objectFunction !== 'undefined' && value.objectFunction !== '')
177
- {
178
- acl[groupId][value.objectName][value.objectFunction] = {
179
- insertAction: privilages[value.objectId].insertPrivilage,
180
- updateAction: privilages[value.objectId].updatePrivilage,
181
- deleteAction: privilages[value.objectId].deletePrivilage,
182
- instantiate: privilages[value.objectId].instantiate,
183
- ownerAction: privilages[value.objectId].ownerAction,
184
- companyAction: privilages[value.objectId].companyAction,
185
- };
186
- }
187
- else
188
- {
189
- acl[groupId][value.objectName].insertAction = privilages[value.objectId].insertPrivilage;
190
- acl[groupId][value.objectName].updateAction = privilages[value.objectId].updatePrivilage;
191
- acl[groupId][value.objectName].deleteAction = privilages[value.objectId].deletePrivilage;
192
- acl[groupId][value.objectName].instantiate = privilages[value.objectId].instantiate;
193
- acl[groupId][value.objectName].ownerAction = privilages[value.objectId].ownerAction;
194
- acl[groupId][value.objectName].companyAction = privilages[value.objectId].companyAction;
195
- }
196
- }
197
- else
198
- if (typeof value.objectFunction !== 'undefined' && value.objectFunction !== '')
199
- {
200
- acl[groupId][value.objectName][value.objectFunction] = {
201
- insertAction: 0,
202
- updateAction: 0,
203
- deleteAction: 0,
204
- instantiate: 0,
205
- ownerAction: 0,
206
- companyAction: 0,
207
- };
208
- }
209
- else
210
- {
211
- acl[groupId][value.objectName].insertAction = 0;
212
- acl[groupId][value.objectName].updateAction = 0;
213
- acl[groupId][value.objectName].deleteAction = 0;
214
- acl[groupId][value.objectName].instantiate = 0;
215
- acl[groupId][value.objectName].ownerAction = 0;
216
- acl[groupId][value.objectName].companyAction = 0;
217
- }
218
- }
219
-
220
- return acl;
221
- }
222
- catch (error)
223
- {
224
- return {
225
- error: true,
226
- notice: error.toString(),
227
- };
228
- }
229
- }
230
- }
231
-
232
- module.exports = {
233
- Library,
234
- ErrorCodes,
235
- Errors: { CoreError, SQLError },
236
- ObjClasses,
237
- MySQL,
238
- CfwObject,
239
- GeneralHandling,
240
- };
1
+ // globals
2
+ const ObjClasses = require('./objects')();
3
+ const Language = require('./lib/Language.js');
4
+ const MySQL = require('./lib/MySql');
5
+ const ErrorCodes = require('./lib/ErrorCodes');
6
+ const Observer = require(('./lib/Observer'));
7
+ const CoreError = require('./lib/errors/CoreError');
8
+ const SQLError = require('./lib/errors/SQLError');
9
+ const CfwObject = require('./lib/CfwObject');
10
+ const GeneralHandling = require('./lib/GeneralHandling');
11
+
12
+ class Library
13
+ {
14
+ constructor(config)
15
+ {
16
+ const me = this;
17
+
18
+ global.lib = me;
19
+
20
+ me.config = config;
21
+
22
+ me.observer = new Observer();
23
+
24
+ (async () =>
25
+ {
26
+ // init db
27
+ me.db = await MySQL.init(config.mysql);
28
+ await me.init();
29
+ await me.start();
30
+ })();
31
+ }
32
+
33
+ async init()
34
+ {
35
+ const me = this;
36
+
37
+ try
38
+ {
39
+ await me.setProps();
40
+ await me.setAclGroups();
41
+
42
+ // init language
43
+ if (me.lang === undefined)
44
+ {
45
+ me.lang = new Language();
46
+ }
47
+
48
+ await me.lang.fillTrans();
49
+
50
+ if (me.unregisteredSession === undefined)
51
+ {
52
+ me.unregisteredSession = new ObjClasses.session.class();
53
+ }
54
+
55
+ me.afterinit();
56
+ }
57
+ catch (error)
58
+ {
59
+ console.error(error.message);
60
+ }
61
+ }
62
+
63
+ afterinit()
64
+ {
65
+ return this;
66
+ }
67
+
68
+ start()
69
+ {
70
+ return this;
71
+ }
72
+
73
+ async setProps()
74
+ {
75
+ const me = this;
76
+
77
+ try
78
+ {
79
+ const results = await me.db.query('SELECT * FROM site_props');
80
+
81
+ me.props = {};
82
+ for (let i = 0; i < results.length; i += 1)
83
+ {
84
+ const row = results[i];
85
+ me.props[row.key] = row.value;
86
+ }
87
+ }
88
+ catch (error)
89
+ {
90
+ console.error(error);
91
+ }
92
+ }
93
+
94
+ async setAclGroups()
95
+ {
96
+ try
97
+ {
98
+ const me = this;
99
+ const acl = {};
100
+ const objects = [];
101
+ const groups = [];
102
+
103
+ let results = await me.db.query('SELECT * FROM acl_objects o');
104
+
105
+ for (let i = 0; i < results.length; i += 1)
106
+ {
107
+ objects.push(results[i]);
108
+ }
109
+
110
+ results = await me.db.query('SELECT * FROM acl_groups p');
111
+
112
+ for (let i = 0; i < results.length; i += 1)
113
+ {
114
+ groups.push(results[i]);
115
+ }
116
+
117
+ const promises = [];
118
+ for (let x = 0; x < groups.length; x += 1)
119
+ {
120
+ const group = groups[x];
121
+ const { groupId } = group;
122
+
123
+ if (typeof acl[groupId] === 'undefined')
124
+ {
125
+ acl[groupId] = {};
126
+ }
127
+
128
+ promises.push(me.setPrivilagesByGroup(groupId, acl, objects));
129
+ }
130
+
131
+ await Promise.all(promises);
132
+
133
+ me.acl = acl;
134
+
135
+ return acl;
136
+ }
137
+ catch (error)
138
+ {
139
+ return {
140
+ error: true,
141
+ notice: error.toString(),
142
+ };
143
+ }
144
+ }
145
+
146
+ async setPrivilagesByGroup(groupId, acl, objects)
147
+ {
148
+ const me = this;
149
+ try
150
+ {
151
+ const privilages = {};
152
+
153
+ const results = await me.db.query('SELECT * FROM acl_privilages p WHERE p.groupId=?', [groupId]);
154
+
155
+ for (let i = 0; i < results.length; i += 1)
156
+ {
157
+ const row = results[i];
158
+ privilages[row.objectId] = row;
159
+ }
160
+
161
+ for (let i = 0; i < objects.length; i += 1)
162
+ {
163
+ const value = objects[i];
164
+ value.objectName = value.objectName.toLowerCase();
165
+ if (typeof value.objectFunction !== 'undefined' && value.objectFunction !== '')
166
+ {
167
+ value.objectFunction = value.objectFunction.toLowerCase();
168
+ }
169
+ if (typeof acl[groupId][value.objectName] === 'undefined')
170
+ {
171
+ // eslint-disable-next-line no-param-reassign
172
+ acl[groupId][value.objectName] = {};
173
+ }
174
+ if (typeof privilages[value.objectId] !== 'undefined')
175
+ {
176
+ if (typeof value.objectFunction !== 'undefined' && value.objectFunction !== '')
177
+ {
178
+ acl[groupId][value.objectName][value.objectFunction] = {
179
+ insertAction: privilages[value.objectId].insertPrivilage,
180
+ updateAction: privilages[value.objectId].updatePrivilage,
181
+ deleteAction: privilages[value.objectId].deletePrivilage,
182
+ instantiate: privilages[value.objectId].instantiate,
183
+ ownerAction: privilages[value.objectId].ownerAction,
184
+ companyAction: privilages[value.objectId].companyAction,
185
+ };
186
+ }
187
+ else
188
+ {
189
+ acl[groupId][value.objectName].insertAction = privilages[value.objectId].insertPrivilage;
190
+ acl[groupId][value.objectName].updateAction = privilages[value.objectId].updatePrivilage;
191
+ acl[groupId][value.objectName].deleteAction = privilages[value.objectId].deletePrivilage;
192
+ acl[groupId][value.objectName].instantiate = privilages[value.objectId].instantiate;
193
+ acl[groupId][value.objectName].ownerAction = privilages[value.objectId].ownerAction;
194
+ acl[groupId][value.objectName].companyAction = privilages[value.objectId].companyAction;
195
+ }
196
+ }
197
+ else
198
+ if (typeof value.objectFunction !== 'undefined' && value.objectFunction !== '')
199
+ {
200
+ acl[groupId][value.objectName][value.objectFunction] = {
201
+ insertAction: 0,
202
+ updateAction: 0,
203
+ deleteAction: 0,
204
+ instantiate: 0,
205
+ ownerAction: 0,
206
+ companyAction: 0,
207
+ };
208
+ }
209
+ else
210
+ {
211
+ acl[groupId][value.objectName].insertAction = 0;
212
+ acl[groupId][value.objectName].updateAction = 0;
213
+ acl[groupId][value.objectName].deleteAction = 0;
214
+ acl[groupId][value.objectName].instantiate = 0;
215
+ acl[groupId][value.objectName].ownerAction = 0;
216
+ acl[groupId][value.objectName].companyAction = 0;
217
+ }
218
+ }
219
+
220
+ return acl;
221
+ }
222
+ catch (error)
223
+ {
224
+ return {
225
+ error: true,
226
+ notice: error.toString(),
227
+ };
228
+ }
229
+ }
230
+ }
231
+
232
+ module.exports = {
233
+ Library,
234
+ ErrorCodes,
235
+ Errors: { CoreError, SQLError },
236
+ ObjClasses,
237
+ MySQL,
238
+ CfwObject,
239
+ GeneralHandling,
240
+ };