@@ -49,11 +49,11 @@ export class ApiRouting {
49
49
configBasicRoutes ( ) {
50
50
51
51
this . router . get ( '/users' , this . addResponseHeaders , this . getUsers . bind ( this ) ) ;
52
- this . router . post ( '/roles/:roleName/members' , this . addResponseHeaders ,
52
+ this . router . post ( '/roles/:roleName/members' ,
53
53
this . secureApiHandler , this . addResponseHeaders , this . addRoleMembers . bind ( this ) ) ;
54
54
this . router . get ( '/roles/:roleName/members' , this . addResponseHeaders , this . getRoleMembers . bind ( this ) ) ;
55
55
this . router . get ( '/roles' , this . addResponseHeaders , this . getRoles . bind ( this ) ) ;
56
- this . router . post ( '/roles' , this . addResponseHeaders , this . secureApiHandler ,
56
+ this . router . post ( '/roles' , this . secureApiHandler ,
57
57
this . addResponseHeaders , this . addRole . bind ( this ) ) ;
58
58
this . router . post ( '/users/register' , this . addResponseHeaders , this . registerUser . bind ( this ) ) ;
59
59
this . router . post ( '/login/token' , this . addResponseHeaders , this . tokenLogin . bind ( this ) ) ;
@@ -62,10 +62,10 @@ export class ApiRouting {
62
62
this . router . get ( '/animals/questions/:questionId' , this . addResponseHeaders , this . getQuestion . bind ( this ) ) ;
63
63
this . router . get ( '/animals/questions' , this . addResponseHeaders , this . getAllQuestions . bind ( this ) ) ;
64
64
this . router . post ( '/animals' , this . addResponseHeaders , this . saveNewAnimal . bind ( this ) ) ;
65
- this . router . delete ( '/animals/:animalId' , this . addResponseHeaders , this . secureApiHandler ,
65
+ this . router . delete ( '/animals/:animalId' , this . secureApiHandler ,
66
66
this . addResponseHeaders , this . deleteAnimal . bind ( this ) ) ;
67
- this . router . get ( '/celldata/people' , this . addResponseHeaders , this . getPeople . bind ( this ) ) ;
68
- this . router . post ( '/celldata/people' , this . addResponseHeaders , this . secureApiHandler ,
67
+ this . router . get ( '/celldata/people' , this . auditCall . bind ( this ) , this . addResponseHeaders , this . getPeople . bind ( this ) ) ;
68
+ this . router . post ( '/celldata/people' , this . secureApiHandler , this . auditCall . bind ( this ) ,
69
69
this . addResponseHeaders , this . addPerson . bind ( this ) ) ;
70
70
this . router . get ( '/celldata/cycles' , this . addResponseHeaders , this . getCycles . bind ( this ) ) ;
71
71
this . router . post ( '/celldata/cycles' , this . addResponseHeaders , this . addCycle . bind ( this ) ) ;
@@ -74,22 +74,22 @@ export class ApiRouting {
74
74
this . router . get ( '/celldata/periodusage' , this . addResponseHeaders , this . getPeriodUsage . bind ( this ) ) ;
75
75
76
76
this . router . get ( '/quiz/questions' , this . addResponseHeaders , this . getQuizQuestions . bind ( this ) ) ;
77
- this . router . post ( '/quiz/questions' , this . addResponseHeaders , this . secureApiHandler ,
77
+ this . router . post ( '/quiz/questions' , this . secureApiHandler ,
78
78
this . addResponseHeaders , this . saveNewQuizQuestion . bind ( this ) ) ;
79
79
this . router . get ( '/quiz/questions/:questionId' , this . addResponseHeaders , this . getQuizQuestion . bind ( this ) ) ;
80
- this . router . put ( '/quiz/questions/:questionId' , this . addResponseHeaders , this . secureApiHandler ,
80
+ this . router . put ( '/quiz/questions/:questionId' , this . secureApiHandler ,
81
81
this . addResponseHeaders , this . updateQuestion . bind ( this ) ) ;
82
82
this . router . get ( '/quiz/categories' , this . addResponseHeaders , this . getQuizCategories . bind ( this ) ) ;
83
83
this . router . get ( '/quiz/answercategories' , this . addResponseHeaders , this . getQuizAnswerCategories . bind ( this ) ) ;
84
84
this . router . get ( '/quiz/test/user/:username' , this . addResponseHeaders , this . getUserTests . bind ( this ) ) ;
85
- this . router . post ( '/quiz/test/:testId/score' , this . addResponseHeaders , this . secureApiHandler ,
85
+ this . router . post ( '/quiz/test/:testId/score' , this . secureApiHandler ,
86
86
this . addResponseHeaders , this . scoreTest . bind ( this ) ) ;
87
- this . router . post ( '/quiz/test/:testId/answer/:questionNumber' , this . addResponseHeaders ,
87
+ this . router . post ( '/quiz/test/:testId/answer/:questionNumber' ,
88
88
this . secureApiHandler , this . addResponseHeaders , this . recordTestAnswer . bind ( this ) ) ;
89
89
this . router . get ( '/quiz/test/:testId' , this . addResponseHeaders , this . getTest . bind ( this ) ) ;
90
- this . router . post ( '/quiz/test' , this . addResponseHeaders , this . secureApiHandler ,
90
+ this . router . post ( '/quiz/test' , this . secureApiHandler ,
91
91
this . addResponseHeaders , this . createTest . bind ( this ) ) ;
92
- this . router . post ( '/quiz' , this . addResponseHeaders , this . secureApiHandler ,
92
+ this . router . post ( '/quiz' , this . secureApiHandler ,
93
93
this . addResponseHeaders , this . createQuiz . bind ( this ) ) ;
94
94
this . router . get ( '/quiz/:quizId' , this . addResponseHeaders , this . getQuiz . bind ( this ) ) ;
95
95
@@ -106,6 +106,19 @@ export class ApiRouting {
106
106
res . set ( 'Access-Control-Allow-Origin' , '*' ) ;
107
107
next ( ) ;
108
108
}
109
+
110
+ auditCall ( req :express . Request , res :express . Response , next :express . NextFunction ) {
111
+ let user :IUser = req . user ;
112
+ let username :string = user ? user . username : 'unauthenticated' ;
113
+ let url = req . url ;
114
+ let verb = req . method ;
115
+
116
+ this . securityService . saveAuditRecord ( username , 'request' , { verb : verb , url : url } )
117
+ . then ( rec => {
118
+ next ( ) ;
119
+ } ) ;
120
+ }
121
+
109
122
getUsers ( req , res , next ) {
110
123
this . securityService . getUsers ( )
111
124
. then ( users => res . send ( users ) )
@@ -244,6 +257,9 @@ export class ApiRouting {
244
257
245
258
addPerson ( req , res , next ) {
246
259
var person :IPerson = req . body ;
260
+ var user :IUser = req . user ;
261
+ console . log ( 'Adding person by user: ' , user . username ) ;
262
+
247
263
this . cellDataPersistenceService . addPerson ( person )
248
264
. then ( p => res . send ( p ) )
249
265
. catch ( err => next ( err ) ) ;
0 commit comments