Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 343d0e2

Browse files
WardormeurDanielBrierton
authored andcommitted
Bugfix/add logs to failed perms (#231)
* Add logs to monitor permissions issues * Remove rogue console * Renaming logger->logFormatter
1 parent 67c7507 commit 343d0e2

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

lib/custom-validator-log-formatter.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
module.exports = function customValidatorLogFormatter (ms, cmd, err, args) {
3+
return JSON.stringify({
4+
src: {
5+
ms: ms,
6+
cmd: cmd
7+
},
8+
err: err,
9+
args: args
10+
});
11+
};

lib/profiles/is-own-profile.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ function isOwnProfile (args, cb) {
88
var plugin = args.role;
99
var userId = args.user.id;
1010
var refProfileId = args.params.profileId || args.params.id ;
11-
seneca.act({role: 'cd-profiles', cmd: 'load_user_profile', userId: userId}, function(err, profile){
12-
if (err) return done(null, {'allowed': false});
11+
seneca.act({role: 'cd-profiles', cmd: 'load_user_profile', userId: userId}, function (err, profile) {
12+
if (err) {
13+
seneca.log.error(seneca.customValidatorLogFormatter('cd-profiles', 'isOwnProfile', err, {userId: userId, refProfileId: refProfileId}));
14+
return cb(null, {'allowed': false});
15+
}
1316
var isSelf = false;
1417
// Could check upon profile, but seems like an overkill to me
15-
if( profile.id === refProfileId ){
18+
if (profile.id === refProfileId) {
1619
isSelf = true;
1720
}
1821
return cb(null, {'allowed': isSelf});

lib/users/is-parent-of.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ function isParentOf (args, cb) {
77
var seneca = this;
88
var plugin = args.role;
99
var userId = args.user.id;
10-
var childrenId = args.params.userId
10+
var childrenId = args.params.userId;
1111
if(_.isUndefined(childrenId) && args.params.profile) childrenId = args.params.profile.userId;
1212
if(_.isUndefined(childrenId) && args.params.query) childrenId = args.params.query.userId;
1313
var isParent = false;
1414
// Could also check the opposite way, from child to Parent
1515
seneca.act({role: 'cd-profiles', cmd: 'load_user_profile', userId: userId},
16-
function(err, user){
17-
if(err) return cb(null, {'allowed': false});
18-
if(_.includes(user.children, childrenId )) isParent = true;
16+
function (err, user) {
17+
if (err) {
18+
seneca.log.error(seneca.customValidatorLogFormatter('cd-profiles', 'isParentOf', err, {userId: userId, childrenId: childrenId}));
19+
return cb(null, {'allowed': false});
20+
}
21+
22+
if (_.includes(user.children, childrenId )) isParent = true;
1923
return cb(null, {'allowed': isParent});
2024
});
2125
}

service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var dgram = require('dgram');
1717
seneca.log.info('using config', JSON.stringify(config, null, 4));
1818

1919
seneca.options(config);
20-
20+
seneca.decorate('customValidatorLogFormatter', require('./lib/custom-validator-log-formatter'));
2121
seneca.use(store, config['postgresql-store']);
2222
if (process.env.MAILTRAP_ENABLED === 'true') {
2323
seneca.use('mail', config.mailtrap);

0 commit comments

Comments
 (0)