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

Commit e7efc73

Browse files
WardormeurDanielBrierton
authored andcommitted
Add new perm to check upon profile instead of userId (#197)
1 parent 837765c commit e7efc73

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

config/perm/profiles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ module.exports = function(){
108108
'change_avatar': [{
109109
role: 'basic-user',
110110
customValidator: [{
111-
role: 'cd-users',
112-
cmd: 'is_self'
111+
role: 'cd-profiles',
112+
cmd: 'is_own_profile'
113113
}]}],
114114
'get_avatar': [{
115115
role: 'none',

lib/profiles/is-own-profile.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
var async = require('async');
3+
var _ = require('lodash');
4+
5+
6+
function isOwnProfile (args, cb) {
7+
var seneca = this;
8+
var plugin = args.role;
9+
var userId = args.user.id;
10+
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});
13+
var isSelf = false;
14+
// Could check upon profile, but seems like an overkill to me
15+
if( profile.id === refProfileId ){
16+
isSelf = true;
17+
}
18+
return cb(null, {'allowed': isSelf});
19+
});
20+
}
21+
22+
module.exports = isOwnProfile;

profiles.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ module.exports = function (options) {
122122
seneca.add({role: plugin, cmd: 'invite_ninja'}, cmd_invite_ninja);
123123
seneca.add({role: plugin, cmd: 'approve_invite_ninja'}, cmd_approve_invite_ninja);
124124
seneca.add({role: plugin, cmd: 'ninjas_for_user'}, cmd_ninjas_for_user);
125+
// Perms
126+
seneca.add({role: plugin, cmd: 'is_own_profile'}, require('./lib/profiles/is-own-profile'));
125127

126128
function cmd_search (args, done) {
127129
if (!args.query) {

0 commit comments

Comments
 (0)