@manyos/smileconnect-api 1.28.0

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.
Files changed (141) hide show
  1. package/.github/workflows/nodejs.yml +26 -0
  2. package/CHANGELOG.md +75 -0
  3. package/Dockerfile +21 -0
  4. package/README.md +1 -0
  5. package/app.js +316 -0
  6. package/conf/clients.json +2491 -0
  7. package/conf/mapping.json +1048 -0
  8. package/conf/scripts/p1.js +11 -0
  9. package/conf/scripts/p2.js +1 -0
  10. package/conf/scripts/p3.js +1 -0
  11. package/conf/scripts/p4.js +2 -0
  12. package/conf/scripts/script1.js +2 -0
  13. package/conf/scripts/script2.js +2 -0
  14. package/conf/scripts/script3.js +2 -0
  15. package/controller/cmdbobjectController.js +291 -0
  16. package/controller/eventLogController.js +78 -0
  17. package/controller/orgdataController.js +440 -0
  18. package/controller/relatedObjectsController.js +194 -0
  19. package/controller/scriptController.js +213 -0
  20. package/controller/taskController.js +368 -0
  21. package/controller/templateController.js +97 -0
  22. package/controller/ticketCIRelationController.js +522 -0
  23. package/controller/ticketController.js +329 -0
  24. package/controller/ticketWorkLogController.js +195 -0
  25. package/docs/.gitattributes +48 -0
  26. package/docs/404.html +13 -0
  27. package/docs/CNAME +1 -0
  28. package/docs/Gemfile +7 -0
  29. package/docs/Gemfile.lock +249 -0
  30. package/docs/_config.yml +257 -0
  31. package/docs/_data/SocialNetworks.yml +92 -0
  32. package/docs/_data/ui-text.yml +494 -0
  33. package/docs/_includes/disqus.html +17 -0
  34. package/docs/_includes/ext-css.html +7 -0
  35. package/docs/_includes/ext-js.html +7 -0
  36. package/docs/_includes/fb-comment.html +14 -0
  37. package/docs/_includes/footer-minimal.html +16 -0
  38. package/docs/_includes/footer-scripts.html +32 -0
  39. package/docs/_includes/footer.html +51 -0
  40. package/docs/_includes/google_analytics.html +14 -0
  41. package/docs/_includes/gtag.html +11 -0
  42. package/docs/_includes/gtm_body.html +6 -0
  43. package/docs/_includes/gtm_head.html +9 -0
  44. package/docs/_includes/head.html +131 -0
  45. package/docs/_includes/header.html +76 -0
  46. package/docs/_includes/just_comments.html +4 -0
  47. package/docs/_includes/matomo.html +17 -0
  48. package/docs/_includes/nav.html +57 -0
  49. package/docs/_includes/social-share.html +42 -0
  50. package/docs/_includes/staticman-comment.html +22 -0
  51. package/docs/_includes/staticman-comments.html +81 -0
  52. package/docs/_layouts/base.html +35 -0
  53. package/docs/_layouts/default.html +9 -0
  54. package/docs/_layouts/minimal.html +26 -0
  55. package/docs/_layouts/page.html +26 -0
  56. package/docs/_layouts/post.html +82 -0
  57. package/docs/_posts/2015-02-28-test-markdown.md +77 -0
  58. package/docs/aboutme.md +18 -0
  59. package/docs/css/bootstrap-social.css +147 -0
  60. package/docs/css/bootstrap-theme.css +476 -0
  61. package/docs/css/bootstrap-theme.css.map +1 -0
  62. package/docs/css/bootstrap-theme.min.css +5 -0
  63. package/docs/css/bootstrap.css +6566 -0
  64. package/docs/css/bootstrap.css.map +1 -0
  65. package/docs/css/bootstrap.min.css +5 -0
  66. package/docs/css/main-minimal.css +13 -0
  67. package/docs/css/main.css +788 -0
  68. package/docs/css/normalize.css +427 -0
  69. package/docs/css/pygment_highlights.css +61 -0
  70. package/docs/css/staticman.css +180 -0
  71. package/docs/eventlog/events.md +65 -0
  72. package/docs/feed.xml +24 -0
  73. package/docs/general/architecture.md +10 -0
  74. package/docs/general/config.md +192 -0
  75. package/docs/general/field-management.md +119 -0
  76. package/docs/general/release-notes.md +9 -0
  77. package/docs/getting-started.md +19 -0
  78. package/docs/howto/cmdbobjects.md +339 -0
  79. package/docs/howto/incident-worklogs.md +186 -0
  80. package/docs/howto/incidents.md +244 -0
  81. package/docs/howto/sample-config.md +518 -0
  82. package/docs/howto/token.md +71 -0
  83. package/docs/howto/worklog-attachment.md +113 -0
  84. package/docs/img/404-southpark.jpg +0 -0
  85. package/docs/img/architecture.jpeg +0 -0
  86. package/docs/img/attachment-upload.png +0 -0
  87. package/docs/img/avatar-icon.png +0 -0
  88. package/docs/img/bgimage.png +0 -0
  89. package/docs/img/gb-isapi.jpg +0 -0
  90. package/docs/img/install-steps.gif +0 -0
  91. package/docs/img/workflow.png +0 -0
  92. package/docs/index.md +41 -0
  93. package/docs/installation.md +123 -0
  94. package/docs/js/bootstrap.js +2306 -0
  95. package/docs/js/bootstrap.min.js +7 -0
  96. package/docs/js/jquery-1.11.2.min.js +4 -0
  97. package/docs/js/main.js +140 -0
  98. package/docs/js/staticman.js +54 -0
  99. package/docs/openapi.json +15097 -0
  100. package/docs/postinstall.md +169 -0
  101. package/docs/preinstall.md +19 -0
  102. package/docs/spec/index.html +24 -0
  103. package/docs/staticman.yml +110 -0
  104. package/docs/tags.html +34 -0
  105. package/docs/workflow.md +127 -0
  106. package/nodemon.json +3 -0
  107. package/package.json +46 -0
  108. package/routes/appConfigRoutes.js +352 -0
  109. package/routes/ciRelationRoutes.js +38 -0
  110. package/routes/cmdbObjectRoutes.js +154 -0
  111. package/routes/organisationRoutes.js +121 -0
  112. package/routes/peopleRelationRoutes.js +38 -0
  113. package/routes/personRoutes.js +131 -0
  114. package/routes/supportgroupRoutes.js +122 -0
  115. package/routes/taskRoutes.js +306 -0
  116. package/routes/templateRoutes.js +67 -0
  117. package/routes/ticketRoutes.js +181 -0
  118. package/routes/ticketWorkLogRoutes.js +185 -0
  119. package/screwdriver.yaml +52 -0
  120. package/test/appTest.js +3 -0
  121. package/test/changeTest.js +541 -0
  122. package/test/cmdbobjectTest.js +167 -0
  123. package/test/files/logo.png +0 -0
  124. package/test/incidentTest.js +539 -0
  125. package/test/orgdataTest.js +156 -0
  126. package/test/problemTest.js +512 -0
  127. package/test/templateTest.js +80 -0
  128. package/test/testUtils.js +21 -0
  129. package/test/workorderTest.js +544 -0
  130. package/util/arquery.js +416 -0
  131. package/util/auth.js +37 -0
  132. package/util/cache.service.js +52 -0
  133. package/util/config.js +361 -0
  134. package/util/constants.js +73 -0
  135. package/util/mappingUtil.js +96 -0
  136. package/util/paramHelper.js +43 -0
  137. package/util/relationUtil.js +63 -0
  138. package/util/responsehandler.js +92 -0
  139. package/util/schemas/clientConfigSchema.js +180 -0
  140. package/util/schemas/fieldMappingSchema.js +211 -0
  141. package/util/searchUtil.js +148 -0
@@ -0,0 +1,352 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const {body, validationResult, oneOf, checkSchema} = require('express-validator/check');
4
+ const {setEventData} = require('../controller/eventLogController');
5
+ const CONSTANTS = require('../util/constants');
6
+ const config = require('../util/config');
7
+ const clientConfigSchema = require('../util/schemas/clientConfigSchema');
8
+ const fieldMappingSchemas = require('../util/schemas/fieldMappingSchema');
9
+ const {isAuthorizedAdmin} = require('../util/auth');
10
+
11
+ module.exports = (function() {
12
+ 'use strict';
13
+ const routes = require('express').Router();
14
+
15
+ const errorFormatter = ({location, msg, param, value, nestedErrors}) => {
16
+ // Build your resulting errors however you want! String, object, whatever - it works!
17
+ return `${location}[${param}]: ${msg}`;
18
+ };
19
+
20
+ routes.get('/mappings/fields/:id', isAuthorizedAdmin,
21
+ function (req, res, next) {
22
+ const id = req.params.id;
23
+ setEventData(
24
+ req,
25
+ CONSTANTS.EVENT_BASE_APC,
26
+ CONSTANTS.EVENT_ACTION_QUERY,
27
+ CONSTANTS.FORM_APC_MAPPING_FIELDS,
28
+ id
29
+ );
30
+
31
+ try {
32
+ const fieldMapping = config.getMapping(id);
33
+ log.debug('found mapping for', id, fieldMapping);
34
+ if (fieldMapping == null || fieldMapping == undefined) {
35
+ req.responseStatus = 404;
36
+ }
37
+ req.result = {
38
+ "data": fieldMapping
39
+ };
40
+ next();
41
+ } catch (error) {
42
+ next(error);
43
+ }
44
+ });
45
+
46
+ routes.get('/version', isAuthorizedAdmin,
47
+ function (req, res, next) {
48
+ setEventData(
49
+ req,
50
+ CONSTANTS.EVENT_BASE_APC,
51
+ CONSTANTS.EVENT_ACTION_QUERY,
52
+ CONSTANTS.FORM_APC_FORMS_META
53
+ );
54
+
55
+ const VERSION = process.env.version;
56
+
57
+ req.result = {
58
+ "apiVersion": VERSION
59
+ };
60
+ next();
61
+ });
62
+
63
+ routes.get('/mappings/fields', isAuthorizedAdmin,
64
+ function (req, res, next) {
65
+ const id = req.params.id;
66
+ setEventData(
67
+ req,
68
+ CONSTANTS.EVENT_BASE_APC,
69
+ CONSTANTS.EVENT_ACTION_QUERY,
70
+ CONSTANTS.FORM_APC_MAPPING_FIELDS
71
+ );
72
+
73
+ try {
74
+ const fieldMapping = config.getMappings();
75
+ log.debug('get all field mappings', fieldMapping);
76
+ if (fieldMapping == null || fieldMapping == undefined) {
77
+ next('Could not load mappings');
78
+ } else {
79
+ req.result = {
80
+ "data": fieldMapping
81
+ };
82
+ next();
83
+ }
84
+ } catch (error) {
85
+ next(error);
86
+ }
87
+ });
88
+
89
+ routes.put('/mappings/fields/:id', isAuthorizedAdmin,
90
+ checkSchema(fieldMappingSchemas.fieldMappingItemSchema),
91
+ function (req, res, next) {
92
+ const id = req.params.id;
93
+ setEventData(
94
+ req,
95
+ CONSTANTS.EVENT_BASE_APC,
96
+ CONSTANTS.EVENT_ACTION_MODIFY,
97
+ CONSTANTS.FORM_APC_MAPPING_FIELDS,
98
+ id,
99
+ req.body
100
+ );
101
+ log.debug('do');
102
+ const errors = validationResult(req);
103
+ if (!errors.isEmpty()) {
104
+ req.errorStatus = 422;
105
+ next(errors.array());
106
+ } else {
107
+ try {
108
+ const newMapping = [];
109
+ req.body.data.forEach(item => {
110
+ const newItem = {
111
+ oldName: item.oldName,
112
+ newName: item.newName
113
+ };
114
+ newMapping.push(newItem);
115
+ });
116
+ config.setMapping(id, newMapping);
117
+ const fieldMapping = config.getMapping(id);
118
+ if (fieldMapping == null || fieldMapping == undefined) {
119
+ req.responseStatus = 404;
120
+ }
121
+ req.result = {
122
+ "data": fieldMapping
123
+ };
124
+ next();
125
+ } catch (error) {
126
+ next(error);
127
+ }
128
+ }
129
+ });
130
+
131
+ routes.put('/mappings/fields', isAuthorizedAdmin,
132
+ checkSchema(fieldMappingSchemas.fieldMappingSchema),
133
+ function (req, res, next) {
134
+ const id = req.params.id;
135
+ setEventData(
136
+ req,
137
+ CONSTANTS.EVENT_BASE_APC,
138
+ CONSTANTS.EVENT_ACTION_MODIFY,
139
+ CONSTANTS.FORM_APC_MAPPING_FIELDS,
140
+ null,
141
+ req.body
142
+ );
143
+ log.debug('do');
144
+ const errors = validationResult(req);
145
+ if (!errors.isEmpty()) {
146
+ req.errorStatus = 422;
147
+ next(errors.array());
148
+ } else {
149
+ try {
150
+ //todo Allow only valid entries
151
+ const newMapping = req.body.data;
152
+ config.setMappings(newMapping);
153
+ const fieldMapping = config.getMappings();
154
+ if (fieldMapping == null || fieldMapping == undefined) {
155
+ req.responseStatus = 404;
156
+ }
157
+ req.result = {
158
+ "data": fieldMapping
159
+ };
160
+ next();
161
+ } catch (error) {
162
+ next(error);
163
+ }
164
+ }
165
+ });
166
+
167
+ routes.get('/clients/:id', isAuthorizedAdmin,
168
+ function (req, res, next) {
169
+ const id = req.params.id;
170
+ setEventData(
171
+ req,
172
+ CONSTANTS.EVENT_BASE_APC,
173
+ CONSTANTS.EVENT_ACTION_QUERY,
174
+ CONSTANTS.FORM_APC_CLIENTS,
175
+ id
176
+ );
177
+ try {
178
+ const clientConfig = config.getClient(id);
179
+ if (clientConfig == null || clientConfig == undefined) {
180
+ req.responseStatus = 404;
181
+ }
182
+ req.result = {
183
+ "data": clientConfig
184
+ };
185
+ next();
186
+ } catch (error) {
187
+ next(error);
188
+ }
189
+ });
190
+
191
+ routes.delete('/clients/:id', isAuthorizedAdmin,
192
+ function (req, res, next) {
193
+ const id = req.params.id;
194
+ setEventData(
195
+ req,
196
+ CONSTANTS.EVENT_BASE_APC,
197
+ CONSTANTS.EVENT_ACTION_MODIFY,
198
+ CONSTANTS.FORM_APC_CLIENTS,
199
+ id
200
+ );
201
+ try {
202
+ config.deleteClient(id);
203
+ req.result = {
204
+ "status": "success"
205
+ };
206
+ next();
207
+ } catch (error) {
208
+ next(error);
209
+ }
210
+ });
211
+
212
+ routes.post('/clients', isAuthorizedAdmin,
213
+ checkSchema(clientConfigSchema),
214
+ function (req, res, next) {
215
+ setEventData(
216
+ req,
217
+ CONSTANTS.EVENT_BASE_APC,
218
+ CONSTANTS.EVENT_ACTION_CREATE,
219
+ CONSTANTS.FORM_APC_CLIENTS,
220
+ null,
221
+ req.body
222
+ );
223
+ const errors = validationResult(req);
224
+ if (!errors.isEmpty()) {
225
+ req.errorStatus = 422;
226
+ next(errors.array());
227
+ } else {
228
+ log.debug('do');
229
+ try {
230
+ const clientConfig = req.body.data;
231
+ const clientName = clientConfig.name;
232
+ config.setClient(clientName, clientConfig)
233
+ const savedClientConfig = config.getClient(clientName);
234
+ req.result = {
235
+ "data": savedClientConfig
236
+ };
237
+ log.debug('next /clients', req.result);
238
+ next();
239
+ } catch (error) {
240
+ next(error);
241
+ }
242
+ }
243
+ });
244
+
245
+ routes.put('/clients/:id', isAuthorizedAdmin,
246
+ checkSchema(clientConfigSchema),
247
+ function (req, res, next) {
248
+ const id = req.params.id;
249
+ setEventData(
250
+ req,
251
+ CONSTANTS.EVENT_BASE_APC,
252
+ CONSTANTS.EVENT_ACTION_MODIFY,
253
+ CONSTANTS.FORM_APC_CLIENTS,
254
+ id,
255
+ req.body
256
+ );
257
+ const errors = validationResult(req);
258
+ if (!errors.isEmpty()) {
259
+ req.errorStatus = 422;
260
+ next(errors.array());
261
+ } else {
262
+ try {
263
+ const clientConfig = req.body.data;
264
+ const clientName = clientConfig.name;
265
+ config.setClient(id, clientConfig);
266
+ const savedClientConfig = config.getClient(clientName);
267
+ req.result = {
268
+ "data": savedClientConfig
269
+ };
270
+ log.debug('next /clients', req.result);
271
+ next();
272
+ } catch (error) {
273
+ next(error);
274
+ }
275
+ }
276
+ });
277
+
278
+ routes.get('/clients', isAuthorizedAdmin,
279
+ function (req, res, next) {
280
+ const id = req.params.id;
281
+ setEventData(
282
+ req,
283
+ CONSTANTS.EVENT_BASE_APC,
284
+ CONSTANTS.EVENT_ACTION_QUERY,
285
+ CONSTANTS.FORM_APC_CLIENTS,
286
+ id
287
+ );
288
+
289
+ try {
290
+ const clients = config.getClients();
291
+ req.result = {
292
+ "data": clients
293
+ };
294
+ next();
295
+ } catch (error) {
296
+ next(error);
297
+ }
298
+ });
299
+
300
+ routes.get('/forms', isAuthorizedAdmin,
301
+ async function (req, res, next) {
302
+ const id = req.params.id;
303
+ setEventData(
304
+ req,
305
+ CONSTANTS.EVENT_BASE_APC,
306
+ CONSTANTS.EVENT_ACTION_QUERY,
307
+ CONSTANTS.FORM_APC_FORMS,
308
+ id
309
+ );
310
+
311
+ try {
312
+ const forms = await config.getForms();
313
+ req.result = {
314
+ "data": forms
315
+ };
316
+ next();
317
+ } catch (error) {
318
+ next(error);
319
+ }
320
+ });
321
+
322
+ routes.get('/forms/:id/fields', isAuthorizedAdmin,
323
+ async function (req, res, next) {
324
+ const id = req.params.id;
325
+ const nameOnly = req.query.nameOnly;
326
+ setEventData(
327
+ req,
328
+ CONSTANTS.EVENT_BASE_APC,
329
+ CONSTANTS.EVENT_ACTION_QUERY,
330
+ CONSTANTS.FORM_APC_FORMS_FIELDS,
331
+ id
332
+ );
333
+
334
+ try {
335
+ let fields = await config.getFields(id);
336
+ if (nameOnly === 'true') {
337
+ fields = fields.map(x => x.name);
338
+ }
339
+ if (fields && Array.isArray(fields)) {
340
+ fields.sort();
341
+ }
342
+ req.result = {
343
+ "data": fields
344
+ };
345
+ next();
346
+ } catch (error) {
347
+ next(error);
348
+ }
349
+ });
350
+
351
+ return routes;
352
+ })();
@@ -0,0 +1,38 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog(path.basename(__filename));
3
+ const passport = require('passport');
4
+ const {body, validationResult, oneOf} = require('express-validator/check');
5
+ const cmdbobjects = require('../controller/cmdbobjectController');
6
+ const eventLog = require('../controller/eventLogController');
7
+
8
+ module.exports = (function () {
9
+ 'use strict';
10
+ const ciRelationRoutes = require('express').Router();
11
+
12
+ ciRelationRoutes.get('/:id', passport.authenticate('jwt', {session: false}),
13
+ function (req, res, next) {
14
+ const id = req.params.id;
15
+ cmdbobjects.getCIRelations(req.user.config, id).then(function (data) {
16
+ eventLog.createSuccessLog(
17
+ req.user.azp,
18
+ id,
19
+ 'BMC.CORE:BMC_BaseRelationship',
20
+ 'CMDB_RelationQuery',
21
+ req.method + ':' + req.url,
22
+ null);
23
+ res.status(200).json({"data": myObject});
24
+ }).catch(function (reason) {
25
+ eventLog.createErrorLog(
26
+ req.user.azp,
27
+ id,
28
+ 'BMC.CORE:BMC_BaseRelationship',
29
+ 'CMDB_RelationQuery',
30
+ req.method + ':' + req.url,
31
+ reason,
32
+ null);
33
+ res.status(500).json(reason);
34
+ })
35
+ });
36
+
37
+ return ciRelationRoutes;
38
+ })();
@@ -0,0 +1,154 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const passport = require('passport');
4
+ const {body, validationResult, checkSchema} = require('express-validator/check');
5
+ const cmdbobjects = require('../controller/cmdbobjectController');
6
+ const eventLog = require('../controller/eventLogController');
7
+ const CONSTANTS = require('../util/constants');
8
+ const {isAuthorizedAdmin} =require ('../util/auth');
9
+ const fieldMappingSchemas = require('../util/schemas/fieldMappingSchema');
10
+ const config = require('../util/config');
11
+ const searchUtil = require('../util/searchUtil');
12
+
13
+ module.exports = (function () {
14
+ 'use strict';
15
+ const cmdbObjectRoutes = require('express').Router();
16
+
17
+ const errorFormatter = ({location, msg, param, value, nestedErrors}) => {
18
+ // Build your resulting errors however you want! String, object, whatever - it works!
19
+ return `${location}[${param}]: ${msg}`;
20
+ };
21
+
22
+ cmdbObjectRoutes.post('/search', [
23
+ body('searchString').isLength({ min: 1})
24
+ ],
25
+ function (req, res, next) {
26
+ const origData = JSON.parse(JSON.stringify(req.body));
27
+ const includeString = req.query.include;
28
+ eventLog.setEventData(
29
+ req,
30
+ CONSTANTS.EVENT_BASE_AST,
31
+ CONSTANTS.EVENT_ACTION_SEARCH,
32
+ CONSTANTS.FORM_ASSET,
33
+ null,
34
+ origData
35
+ );
36
+ const options = {};
37
+ const offset = req.body.offset;
38
+ if (offset != null && offset != undefined && Number.isInteger(offset)) {
39
+ options.offset = offset;
40
+ }
41
+ const limit = req.body.limit;
42
+ if (limit != null && limit != undefined && Number.isInteger(limit)) {
43
+ options.limit = limit;
44
+ }
45
+ // check sorting
46
+ const sort = req.body.sort;
47
+ if (sort != null && sort != undefined) {
48
+ options.sort = sort;
49
+ }
50
+ const getRelations = req.body.getRelations;
51
+ if ((getRelations != null && getRelations != undefined) && (getRelations === true || getRelations === 'true')) {
52
+ options.getRelations = true;
53
+ } else {
54
+ options.getRelations = false;
55
+ }
56
+ log.debug('start asset search', req.body);
57
+ const valResult = validationResult(req).formatWith(errorFormatter);
58
+ log.debug('validationResult', valResult.array());
59
+ if (!valResult.isEmpty()) {
60
+ next(valResult.array());
61
+ } else {
62
+ cmdbobjects.searchCmdbObject(req.user.config, req.body.searchString, req.body.fields, options, includeString).then(function (result) {
63
+ log.debug('result', result);
64
+ req.includeObjectsList = result.included;
65
+ req.result = {data:result.data || []};
66
+ next();
67
+ }).catch(function (reason) {
68
+ next(reason);
69
+ });
70
+ }
71
+ });
72
+
73
+ cmdbObjectRoutes.get('/', function (req, res, next) {
74
+ eventLog.setEventData(
75
+ req,
76
+ CONSTANTS.EVENT_BASE_AST,
77
+ CONSTANTS.EVENT_ACTION_QUERY,
78
+ CONSTANTS.FORM_ASSET
79
+ );
80
+ const category = req.query.category;
81
+ let includeString = req.query.include;
82
+ let ciIds = req.query.ciIds;
83
+ if (typeof ciIds === 'string')
84
+ ciIds = ciIds.split(',');
85
+
86
+ cmdbobjects.getCmdbObjects(req.user.config, category, ciIds, includeString).then(function (result) {
87
+ log.debug('result', result);
88
+ req.includeObjectsList = result.included;
89
+ req.result = {data:result.data || []};
90
+ next();
91
+ }).catch(function (reason) {
92
+ next(reason);
93
+ })
94
+ });
95
+
96
+ cmdbObjectRoutes.get('/:id', passport.authenticate('jwt', {session: false}),
97
+ function (req, res, next) {
98
+ const id = req.params.id;
99
+ const includeString = req.query.include;
100
+ eventLog.setEventData(
101
+ req,
102
+ CONSTANTS.EVENT_BASE_AST,
103
+ CONSTANTS.EVENT_ACTION_QUERY,
104
+ CONSTANTS.FORM_ASSET,
105
+ id
106
+ );
107
+ cmdbobjects.getCmdbObject(req.user.config, id, includeString).then(function (result) {
108
+ log.debug('result', result);
109
+ req.includeObjectsList = result.included;
110
+ req.result = {data:result.data || {}};
111
+ if (!result.data) {
112
+ req.responseStatus = 404;
113
+ }
114
+ next();
115
+ }).catch(function (reason) {
116
+ next(reason);
117
+ })
118
+ });
119
+
120
+ cmdbObjectRoutes.post('/validateUpdateRequest/:clientId', isAuthorizedAdmin, checkSchema(fieldMappingSchemas.validateCMDBDataSchema), async function (req, res, next) {
121
+ const clientId = req.params.clientId;
122
+ eventLog.setEventData(
123
+ req,
124
+ CONSTANTS.EVENT_BASE_AST,
125
+ CONSTANTS.EVENT_ACTION_MODIFY,
126
+ CONSTANTS.FORM_ASSET,
127
+ clientId
128
+ );
129
+ const errors = validationResult(req);
130
+ if (!errors.isEmpty()) {
131
+ req.errorStatus = 422;
132
+ next(errors.array());
133
+ } else {
134
+ const clientConfig = config.getClientConfig(clientId);
135
+ const result = [];
136
+ try {
137
+ if (req.body && req.body.ciChanges && Array.isArray(req.body.ciChanges)) {
138
+ for (let x=0; x<req.body.ciChanges.length; x++) {
139
+ const ciDef = req.body.ciChanges[x];
140
+ const hasAccess = await cmdbobjects.hasAccess(clientConfig, ciDef.ciId);
141
+ const mappedEntry = await cmdbobjects.applyMapping(clientConfig, ciDef.attributes);
142
+ result.push({ciId:ciDef.ciId, access:hasAccess, attributes:mappedEntry});
143
+ };
144
+ }
145
+ req.result = {validationResult:result};
146
+ next();
147
+ } catch (e) {
148
+ next(e);
149
+ }
150
+ }
151
+ });
152
+
153
+ return cmdbObjectRoutes;
154
+ })();
@@ -0,0 +1,121 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+ const passport = require('passport');
4
+ const {body, validationResult, oneOf} = require('express-validator/check');
5
+ const orgdata = require('../controller/orgdataController');
6
+ const eventLog = require('../controller/eventLogController');
7
+ const CONSTANTS = require('../util/constants');
8
+
9
+ module.exports = (function() {
10
+ 'use strict';
11
+ const organisationRoutes = require('express').Router();
12
+
13
+ const errorFormatter = ({location, msg, param, value, nestedErrors}) => {
14
+ // Build your resulting errors however you want! String, object, whatever - it works!
15
+ return `${location}[${param}]: ${msg}`;
16
+ };
17
+
18
+
19
+ organisationRoutes.get('/:id', passport.authenticate('jwt', {session: false}),
20
+ function (req, res, next) {
21
+ const id = req.params.id;
22
+ const include = req.query.include;
23
+ eventLog.setEventData(
24
+ req,
25
+ CONSTANTS.EVENT_BASE_ORG_ORGANISATION,
26
+ CONSTANTS.EVENT_ACTION_QUERY,
27
+ CONSTANTS.FORM_ORGANISATION,
28
+ id
29
+ );
30
+
31
+ const options = {};
32
+ const limit = req.query.limit;
33
+ if (limit != null && limit != undefined) {
34
+ options.limit = Number.parseInt(limit);
35
+ }
36
+
37
+ const offset = req.query.offset;
38
+ if (offset != null && offset != undefined) {
39
+ options.offset = Number.parseInt(offset);
40
+ }
41
+
42
+ orgdata.getOrganisation(req.user.config, id, null, include, options).then(function (result) {
43
+ if (Object.keys(result.data).length === 0) {
44
+ req.responseStatus = 404;
45
+ req.result = {
46
+ data : {}
47
+ };
48
+ } else {
49
+ req.includeObjectsList = result.included;
50
+ req.result = {data:result.data || {}};
51
+ }
52
+ next();
53
+ }).catch(function (reason) {
54
+ next(reason);
55
+ })
56
+ });
57
+
58
+
59
+ organisationRoutes.post('/search', [
60
+ body('searchString').isLength({ min: 1})
61
+ ],
62
+ function (req, res, next) {
63
+ const origData = JSON.parse(JSON.stringify(req.body));
64
+ const include = req.query.include;
65
+ eventLog.setEventData(
66
+ req,
67
+ CONSTANTS.EVENT_BASE_ORG_ORGANISATION,
68
+ CONSTANTS.EVENT_ACTION_SEARCH,
69
+ CONSTANTS.FORM_ORGANISATION,
70
+ null,
71
+ origData
72
+ );
73
+ const options = {};
74
+ const offset = req.body.offset;
75
+ if (offset != null && offset != undefined && Number.isInteger(offset)) {
76
+ options.offset = offset;
77
+ }
78
+ const limit = req.body.limit;
79
+ if (limit != null && limit != undefined && Number.isInteger(limit)) {
80
+ options.limit = limit;
81
+ }
82
+ // check sorting
83
+ const sort = req.body.sort;
84
+ if (sort != null && sort != undefined) {
85
+ options.sort = sort;
86
+ }
87
+ log.debug('start organisation search', req.body);
88
+ const valResult = validationResult(req).formatWith(errorFormatter);
89
+ log.debug('validationResult', valResult.array());
90
+ if (!valResult.isEmpty()) {
91
+ next(valResult.array());
92
+ } else {
93
+ orgdata.searchOrganisations(req.user.config, req.body.searchString, req.body.fields, options, include).then(function (result) {
94
+ req.includeObjectsList = result.included;
95
+ req.result = {data:result.data || {}};
96
+ next();
97
+ }).catch(function (reason) {
98
+ next(reason);
99
+ });
100
+ }
101
+ });
102
+
103
+ organisationRoutes.get('/', function (req, res, next) {
104
+ const include = req.query.include;
105
+ eventLog.setEventData(
106
+ req,
107
+ CONSTANTS.EVENT_BASE_ORG_ORGANISATION,
108
+ CONSTANTS.EVENT_ACTION_QUERY,
109
+ CONSTANTS.FORM_ORGANISATION
110
+ );
111
+ orgdata.getOrganisations(req.user.config, null, include).then(function (result) {
112
+ req.includeObjectsList = result.included;
113
+ req.result = {data:result.data || {}};
114
+ next();
115
+ }).catch(function (reason) {
116
+ next(reason);
117
+ })
118
+ });
119
+
120
+ return organisationRoutes;
121
+ })();