corefwnode 3.0.2 → 3.0.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.
@@ -1,202 +1,202 @@
1
- const ErrorCodes = require('../lib/ErrorCodes');
2
-
3
- const CfwObject = require('../lib/CfwObject.js');
4
- /**
5
- * AclPrivilages object
6
- *
7
- * @version $Id$
8
- * @copyright 2008
9
- */
10
-
11
- module.exports = class AclPrivilages extends CfwObject
12
- {
13
- constructor(session)
14
- {
15
- const proxy = super(session);
16
-
17
- return proxy;
18
- }
19
-
20
- // eslint-disable-next-line class-methods-use-this
21
- tableConf()
22
- {
23
- return {
24
- tableName: 'acl_privilages',
25
- id: {
26
- privlageId: {
27
- fieldType: 'int',
28
- maxlength: 30,
29
- req: 0,
30
- },
31
- },
32
- fields: {
33
- objectId: {
34
- fieldType: 'int',
35
- maxlength: 20,
36
- minlength: 1,
37
- req: 1,
38
- },
39
- groupId: {
40
- fieldType: 'int',
41
- maxlength: 20,
42
- minlength: 1,
43
- req: 1,
44
- },
45
- insertPrivilage: {
46
- fieldType: 'int',
47
- maxlength: 1,
48
- minlength: 1,
49
- req: 0,
50
- },
51
- updatePrivilage: {
52
- fieldType: 'int',
53
- maxlength: 1,
54
- minlength: 1,
55
- req: 0,
56
- },
57
- deletePrivilage: {
58
- fieldType: 'int',
59
- maxlength: 1,
60
- minlength: 1,
61
- req: 0,
62
- },
63
- instantiate: {
64
- fieldType: 'int',
65
- maxlength: 1,
66
- minlength: 1,
67
- req: 0,
68
- },
69
- ownerAction: {
70
- fieldType: 'int',
71
- maxlength: 1,
72
- minlength: 1,
73
- req: 0,
74
- },
75
- companyAction: {
76
- fieldType: 'int',
77
- maxlength: 1,
78
- minlength: 1,
79
- req: 0,
80
- },
81
- },
82
- };
83
- }
84
-
85
- async afterUpdate()
86
- {
87
- const me = this;
88
-
89
- me.lib.init();
90
- return { error: false, notice: 'success' };
91
- }
92
-
93
- async afterInsert()
94
- {
95
- const me = this;
96
-
97
- me.lib.init();
98
- return { error: false, notice: 'success' };
99
- }
100
-
101
- async updatePrivilageByGroupId(param)
102
- {
103
- const me = this;
104
-
105
- const results = await me.db.query(
106
- 'SELECT privlageId FROM acl_privilages WHERE objectId=? AND groupId=?',
107
- [param.objectId, param.groupId],
108
- );
109
- const row = results[0];
110
- if (typeof row !== 'undefined' && typeof row.privlageId !== 'undefined')
111
- {
112
- me.id = row.privlageId;
113
-
114
- me.insertPrivilage = param.insertPrivilage;
115
- me.updatePrivilage = param.updatePrivilage;
116
- me.deletePrivilage = param.deletePrivilage;
117
- me.instantiate = param.instantiate;
118
- me.ownerAction = param.ownerAction;
119
- me.companyAction = param.companyAction;
120
-
121
- const val = await me.update();
122
- return val;
123
- }
124
-
125
- me.objectId = param.objectId;
126
- me.groupId = param.groupId;
127
- me.insertPrivilage = param.insertPrivilage;
128
- me.updatePrivilage = param.updatePrivilage;
129
- me.deletePrivilage = param.deletePrivilage;
130
- me.instantiate = param.instantiate;
131
- me.ownerAction = param.ownerAction;
132
- me.companyAction = param.companyAction;
133
-
134
- const val = await me.insert();
135
- return val;
136
- }
137
-
138
- async getPrivilagesByGroupId(param)
139
- {
140
- const me = this;
141
-
142
- let limit = '';
143
- if (typeof param.start !== 'undefined' && typeof param.limit !== 'undefined')
144
- {
145
- const start = me.db.escape(parseInt(param.start, 10));
146
- const end = me.db.escape(parseInt(param.limit, 10));
147
- limit = ` LIMIT ${start}, ${end} `;
148
- }
149
-
150
- let whereSearch = '';
151
- if (typeof param.query !== 'undefined' && param.query !== '')
152
- {
153
- whereSearch = ' AND objectName LIKE :query OR objectFunction LIKE :query ';
154
- param.query = `%${param.query}%`;
155
- }
156
-
157
- const results = await me.db.query(
158
- `SELECT * FROM acl_objects WHERE 1=1 ${whereSearch} ORDER BY objectId DESC ${limit}`,
159
- param,
160
- );
161
-
162
- const promises = [];
163
-
164
- for (const result of results)
165
- {
166
- promises.push(me.getSingleObjectPrivilageByGroupId(param.groupId, result.objectId));
167
- }
168
-
169
- const data = await Promise.all(promises);
170
-
171
- const resultsCnt = await me.db.query(`SELECT COUNT(*) AS cnt FROM acl_objects WHERE 1=1 ${whereSearch}`, param);
172
- return { root: data, totalCount: resultsCnt[0].cnt };
173
- }
174
-
175
- async getSingleObjectPrivilageByGroupId(groupId, objectId)
176
- {
177
- const me = this;
178
-
179
- const results = await me.db.query(`SELECT
180
- ap.*, ao.*
181
- FROM acl_objects ao
182
- LEFT JOIN acl_privilages ap ON ao.objectId=ap.objectId AND ap.groupId=?
183
- WHERE ao.objectId=?`, [groupId, objectId]);
184
-
185
- if (typeof results[0] !== 'undefined')
186
- {
187
- return {
188
- objectId: results[0].objectId,
189
- objectName: results[0].objectName.toLowerCase(),
190
- objectFunction: results[0].objectFunction.toLowerCase(),
191
- insertPrivilage: (results[0].insertPrivilage) ? results[0].insertPrivilage : 0,
192
- updatePrivilage: (results[0].updatePrivilage) ? results[0].updatePrivilage : 0,
193
- deletePrivilage: (results[0].deletePrivilage) ? results[0].deletePrivilage : 0,
194
- instantiate: (results[0].instantiate) ? results[0].instantiate : 0,
195
- ownerAction: (results[0].ownerAction) ? results[0].ownerAction : 0,
196
- companyAction: (results[0].companyAction) ? results[0].companyAction : 0,
197
- };
198
- }
199
-
200
- throw (ErrorCodes.error('object_not_found'));
201
- }
202
- };
1
+ const ErrorCodes = require('../lib/ErrorCodes');
2
+
3
+ const CfwObject = require('../lib/CfwObject.js');
4
+ /**
5
+ * AclPrivilages object
6
+ *
7
+ * @version $Id$
8
+ * @copyright 2008
9
+ */
10
+
11
+ module.exports = class AclPrivilages extends CfwObject
12
+ {
13
+ constructor(session)
14
+ {
15
+ const proxy = super(session);
16
+
17
+ return proxy;
18
+ }
19
+
20
+ // eslint-disable-next-line class-methods-use-this
21
+ tableConf()
22
+ {
23
+ return {
24
+ tableName: 'acl_privilages',
25
+ id: {
26
+ privlageId: {
27
+ fieldType: 'int',
28
+ maxlength: 30,
29
+ req: 0,
30
+ },
31
+ },
32
+ fields: {
33
+ objectId: {
34
+ fieldType: 'int',
35
+ maxlength: 20,
36
+ minlength: 1,
37
+ req: 1,
38
+ },
39
+ groupId: {
40
+ fieldType: 'int',
41
+ maxlength: 20,
42
+ minlength: 1,
43
+ req: 1,
44
+ },
45
+ insertPrivilage: {
46
+ fieldType: 'int',
47
+ maxlength: 1,
48
+ minlength: 1,
49
+ req: 0,
50
+ },
51
+ updatePrivilage: {
52
+ fieldType: 'int',
53
+ maxlength: 1,
54
+ minlength: 1,
55
+ req: 0,
56
+ },
57
+ deletePrivilage: {
58
+ fieldType: 'int',
59
+ maxlength: 1,
60
+ minlength: 1,
61
+ req: 0,
62
+ },
63
+ instantiate: {
64
+ fieldType: 'int',
65
+ maxlength: 1,
66
+ minlength: 1,
67
+ req: 0,
68
+ },
69
+ ownerAction: {
70
+ fieldType: 'int',
71
+ maxlength: 1,
72
+ minlength: 1,
73
+ req: 0,
74
+ },
75
+ companyAction: {
76
+ fieldType: 'int',
77
+ maxlength: 1,
78
+ minlength: 1,
79
+ req: 0,
80
+ },
81
+ },
82
+ };
83
+ }
84
+
85
+ async afterUpdate()
86
+ {
87
+ const me = this;
88
+
89
+ me.lib.init();
90
+ return { error: false, notice: 'success' };
91
+ }
92
+
93
+ async afterInsert()
94
+ {
95
+ const me = this;
96
+
97
+ me.lib.init();
98
+ return { error: false, notice: 'success' };
99
+ }
100
+
101
+ async updatePrivilageByGroupId(param)
102
+ {
103
+ const me = this;
104
+
105
+ const results = await me.db.query(
106
+ 'SELECT privlageId FROM acl_privilages WHERE objectId=? AND groupId=?',
107
+ [param.objectId, param.groupId],
108
+ );
109
+ const row = results[0];
110
+ if (typeof row !== 'undefined' && typeof row.privlageId !== 'undefined')
111
+ {
112
+ me.id = row.privlageId;
113
+
114
+ me.insertPrivilage = param.insertPrivilage;
115
+ me.updatePrivilage = param.updatePrivilage;
116
+ me.deletePrivilage = param.deletePrivilage;
117
+ me.instantiate = param.instantiate;
118
+ me.ownerAction = param.ownerAction;
119
+ me.companyAction = param.companyAction;
120
+
121
+ const val = await me.update();
122
+ return val;
123
+ }
124
+
125
+ me.objectId = param.objectId;
126
+ me.groupId = param.groupId;
127
+ me.insertPrivilage = param.insertPrivilage;
128
+ me.updatePrivilage = param.updatePrivilage;
129
+ me.deletePrivilage = param.deletePrivilage;
130
+ me.instantiate = param.instantiate;
131
+ me.ownerAction = param.ownerAction;
132
+ me.companyAction = param.companyAction;
133
+
134
+ const val = await me.insert();
135
+ return val;
136
+ }
137
+
138
+ async getPrivilagesByGroupId(param)
139
+ {
140
+ const me = this;
141
+
142
+ let limit = '';
143
+ if (typeof param.start !== 'undefined' && typeof param.limit !== 'undefined')
144
+ {
145
+ const start = me.db.escape(parseInt(param.start, 10));
146
+ const end = me.db.escape(parseInt(param.limit, 10));
147
+ limit = ` LIMIT ${start}, ${end} `;
148
+ }
149
+
150
+ let whereSearch = '';
151
+ if (typeof param.query !== 'undefined' && param.query !== '')
152
+ {
153
+ whereSearch = ' AND objectName LIKE :query OR objectFunction LIKE :query ';
154
+ param.query = `%${param.query}%`;
155
+ }
156
+
157
+ const results = await me.db.query(
158
+ `SELECT * FROM acl_objects WHERE 1=1 ${whereSearch} ORDER BY objectId DESC ${limit}`,
159
+ param,
160
+ );
161
+
162
+ const promises = [];
163
+
164
+ for (const result of results)
165
+ {
166
+ promises.push(me.getSingleObjectPrivilageByGroupId(param.groupId, result.objectId));
167
+ }
168
+
169
+ const data = await Promise.all(promises);
170
+
171
+ const resultsCnt = await me.db.query(`SELECT COUNT(*) AS cnt FROM acl_objects WHERE 1=1 ${whereSearch}`, param);
172
+ return { root: data, totalCount: resultsCnt[0].cnt };
173
+ }
174
+
175
+ async getSingleObjectPrivilageByGroupId(groupId, objectId)
176
+ {
177
+ const me = this;
178
+
179
+ const results = await me.db.query(`SELECT
180
+ ap.*, ao.*
181
+ FROM acl_objects ao
182
+ LEFT JOIN acl_privilages ap ON ao.objectId=ap.objectId AND ap.groupId=?
183
+ WHERE ao.objectId=?`, [groupId, objectId]);
184
+
185
+ if (typeof results[0] !== 'undefined')
186
+ {
187
+ return {
188
+ objectId: results[0].objectId,
189
+ objectName: results[0].objectName.toLowerCase(),
190
+ objectFunction: results[0].objectFunction.toLowerCase(),
191
+ insertPrivilage: (results[0].insertPrivilage) ? results[0].insertPrivilage : 0,
192
+ updatePrivilage: (results[0].updatePrivilage) ? results[0].updatePrivilage : 0,
193
+ deletePrivilage: (results[0].deletePrivilage) ? results[0].deletePrivilage : 0,
194
+ instantiate: (results[0].instantiate) ? results[0].instantiate : 0,
195
+ ownerAction: (results[0].ownerAction) ? results[0].ownerAction : 0,
196
+ companyAction: (results[0].companyAction) ? results[0].companyAction : 0,
197
+ };
198
+ }
199
+
200
+ throw (ErrorCodes.error('object_not_found'));
201
+ }
202
+ };
@@ -1,108 +1,108 @@
1
- const CfwObject = require('../lib/CfwObject.js');
2
- /**
3
- * EmailTemplates_Base object
4
- *
5
- * @version $Id$
6
- * @copyright 2008
7
- */
8
-
9
- module.exports = class EmailTemplates extends CfwObject
10
- {
11
- constructor(session)
12
- {
13
- const proxy = super(session);
14
-
15
- return proxy;
16
- }
17
-
18
- // eslint-disable-next-line class-methods-use-this
19
- tableConf()
20
- {
21
- return {
22
- tableName: 'email_templates',
23
- id: {
24
- templateId: {
25
- fieldType: 'int',
26
- maxlength: 20,
27
- req: 0,
28
- },
29
- },
30
- fields:
31
- {
32
- name: {
33
- fieldType: 'text',
34
- maxlength: 255,
35
- req: 1,
36
- },
37
- description: {
38
- fieldType: 'text',
39
- decorators: ['leaveuntouched'],
40
- maxlength: 255,
41
- req: 1,
42
- },
43
- template: {
44
- fieldType: 'text',
45
- decorators: ['leaveuntouched'],
46
- req: 1,
47
- },
48
- },
49
- };
50
- }
51
-
52
- async returnEmailText(id, params, message = '')
53
- {
54
- const me = this;
55
-
56
- let results = await me.db.query('SELECT name, template FROM email_templates WHERE templateId=?', [id]);
57
- if (typeof results[0] !== 'undefined')
58
- {
59
- results = await me.db.query('SELECT name, template FROM email_templates WHERE templateId=1');
60
-
61
- const row = results[0];
62
-
63
- let { template } = row;
64
- template = template.replace(/::p0::/g, me.config.siteUrl);
65
- template = template.replace(/::p1::/g, me.config.siteName);
66
- template = template.replace(/::p2::/g, message);
67
-
68
- return { template, name: row.name };
69
- }
70
-
71
- const row = results[0];
72
- let { template } = row;
73
- let { name } = row;
74
-
75
- let n = 0;
76
- for (let i = 0; i < params.length; i += 1)
77
- {
78
- const value = params[i];
79
- let re = new RegExp(`::p${n}::`);
80
- template = template.replace(re, value);
81
- re = new RegExp(`xxp${n}xx`);
82
- name = name.replace(re, value);
83
- n += 1;
84
- }
85
-
86
- const vars = [];
87
- const dats = template.split('{#');
88
- if (typeof dats[0] !== 'undefined')
89
- {
90
- dats.splice(0, 1);
91
- }
92
- for (let i = 0; i < dats.length; i += 1)
93
- {
94
- const value = dats[i];
95
- const dat = value.split('}');
96
- vars.push(dat[0]);
97
- }
98
-
99
- for (let i = 0; i < vars.length; i += 1)
100
- {
101
- const value = vars[i];
102
- const re = new RegExp(`{#${value}}`);
103
- template = template.replace(re, me.translate(value));
104
- }
105
-
106
- return { template, name: row.name };
107
- }
108
- };
1
+ const CfwObject = require('../lib/CfwObject.js');
2
+ /**
3
+ * EmailTemplates_Base object
4
+ *
5
+ * @version $Id$
6
+ * @copyright 2008
7
+ */
8
+
9
+ module.exports = class EmailTemplates extends CfwObject
10
+ {
11
+ constructor(session)
12
+ {
13
+ const proxy = super(session);
14
+
15
+ return proxy;
16
+ }
17
+
18
+ // eslint-disable-next-line class-methods-use-this
19
+ tableConf()
20
+ {
21
+ return {
22
+ tableName: 'email_templates',
23
+ id: {
24
+ templateId: {
25
+ fieldType: 'int',
26
+ maxlength: 20,
27
+ req: 0,
28
+ },
29
+ },
30
+ fields:
31
+ {
32
+ name: {
33
+ fieldType: 'text',
34
+ maxlength: 255,
35
+ req: 1,
36
+ },
37
+ description: {
38
+ fieldType: 'text',
39
+ decorators: ['leaveuntouched'],
40
+ maxlength: 255,
41
+ req: 1,
42
+ },
43
+ template: {
44
+ fieldType: 'text',
45
+ decorators: ['leaveuntouched'],
46
+ req: 1,
47
+ },
48
+ },
49
+ };
50
+ }
51
+
52
+ async returnEmailText(id, params, message = '')
53
+ {
54
+ const me = this;
55
+
56
+ let results = await me.db.query('SELECT name, template FROM email_templates WHERE templateId=?', [id]);
57
+ if (typeof results[0] !== 'undefined')
58
+ {
59
+ results = await me.db.query('SELECT name, template FROM email_templates WHERE templateId=1');
60
+
61
+ const row = results[0];
62
+
63
+ let { template } = row;
64
+ template = template.replace(/::p0::/g, me.config.siteUrl);
65
+ template = template.replace(/::p1::/g, me.config.siteName);
66
+ template = template.replace(/::p2::/g, message);
67
+
68
+ return { template, name: row.name };
69
+ }
70
+
71
+ const row = results[0];
72
+ let { template } = row;
73
+ let { name } = row;
74
+
75
+ let n = 0;
76
+ for (let i = 0; i < params.length; i += 1)
77
+ {
78
+ const value = params[i];
79
+ let re = new RegExp(`::p${n}::`);
80
+ template = template.replace(re, value);
81
+ re = new RegExp(`xxp${n}xx`);
82
+ name = name.replace(re, value);
83
+ n += 1;
84
+ }
85
+
86
+ const vars = [];
87
+ const dats = template.split('{#');
88
+ if (typeof dats[0] !== 'undefined')
89
+ {
90
+ dats.splice(0, 1);
91
+ }
92
+ for (let i = 0; i < dats.length; i += 1)
93
+ {
94
+ const value = dats[i];
95
+ const dat = value.split('}');
96
+ vars.push(dat[0]);
97
+ }
98
+
99
+ for (let i = 0; i < vars.length; i += 1)
100
+ {
101
+ const value = vars[i];
102
+ const re = new RegExp(`{#${value}}`);
103
+ template = template.replace(re, me.translate(value));
104
+ }
105
+
106
+ return { template, name: row.name };
107
+ }
108
+ };