mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
hasEnoughRep can take an array
user follow uid checks
This commit is contained in:
@@ -123,7 +123,7 @@ function isGuestAllowedTo(privilege, cids, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
helpers.hasEnoughReputationFor = function(privilege, uid, callback) {
|
helpers.hasEnoughReputationFor = function(privilege, uid, callback) {
|
||||||
if (parseInt(meta.config['privileges:disabled'], 10)) {
|
if (parseInt(meta.config['privileges:disabled'], 10) || !parseInt(uid, 10)) {
|
||||||
return callback(null, false);
|
return callback(null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +131,18 @@ helpers.hasEnoughReputationFor = function(privilege, uid, callback) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(null, false);
|
return callback(null, false);
|
||||||
}
|
}
|
||||||
callback(null, parseInt(reputation, 10) >= parseInt(meta.config[privilege], 10));
|
|
||||||
|
reputation = parseInt(reputation, 10);
|
||||||
|
|
||||||
|
if (Array.isArray(privilege)) {
|
||||||
|
for(var i=0; i<privilege.length; ++i) {
|
||||||
|
if (reputation >= parseInt(meta.config[privilege[i]], 10)) {
|
||||||
|
return callback(null, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
callback(null, reputation >= parseInt(meta.config[privilege], 10));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,8 @@ module.exports = function(privileges) {
|
|||||||
return callback(null, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
async.parallel({
|
async.parallel({
|
||||||
manage_content: function(next) {
|
manage: function(next) {
|
||||||
helpers.hasEnoughReputationFor('privileges:manage_content', uid, next);
|
helpers.hasEnoughReputationFor(['privileges:manage_content', 'privileges:manage_topic'], uid, next);
|
||||||
},
|
|
||||||
manage_topic: function(next) {
|
|
||||||
helpers.hasEnoughReputationFor('privileges:manage_topic', uid, next);
|
|
||||||
},
|
},
|
||||||
isAdministrator: function(next) {
|
isAdministrator: function(next) {
|
||||||
user.isAdministrator(uid, next);
|
user.isAdministrator(uid, next);
|
||||||
@@ -34,7 +31,7 @@ module.exports = function(privileges) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var userPriv = userResults.isAdministrator || userResults.manage_topic || userResults.manage_content;
|
var userPriv = userResults.isAdministrator || userResults.manage;
|
||||||
|
|
||||||
async.parallel({
|
async.parallel({
|
||||||
isOwner: function(next) {
|
isOwner: function(next) {
|
||||||
@@ -120,10 +117,7 @@ module.exports = function(privileges) {
|
|||||||
posts.isOwner(pid, uid, next);
|
posts.isOwner(pid, uid, next);
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
helpers.hasEnoughReputationFor('privileges:manage_content', uid, next);
|
helpers.hasEnoughReputationFor(['privileges:manage_content', 'privileges:manage_topic'], uid, next);
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
helpers.hasEnoughReputationFor('privileges:manage_topic', uid, next);
|
|
||||||
}
|
}
|
||||||
], next);
|
], next);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,16 +33,20 @@ module.exports = function(User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
User.getFollowing = function(uid, callback) {
|
User.getFollowing = function(uid, callback) {
|
||||||
getFollow('following:' + uid, callback);
|
getFollow(uid, 'following:' + uid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
User.getFollowers = function(uid, callback) {
|
User.getFollowers = function(uid, callback) {
|
||||||
getFollow('followers:' + uid, callback);
|
getFollow(uid, 'followers:' + uid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getFollow(set, callback) {
|
function getFollow(uid, set, callback) {
|
||||||
|
if (!parseInt(uid, 10)) {
|
||||||
|
return callback(null, []);
|
||||||
|
}
|
||||||
|
|
||||||
db.getSetMembers(set, function(err, uids) {
|
db.getSetMembers(set, function(err, uids) {
|
||||||
if(err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,10 +55,16 @@ module.exports = function(User) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
User.getFollowingCount = function(uid, callback) {
|
User.getFollowingCount = function(uid, callback) {
|
||||||
|
if (!parseInt(uid, 10)) {
|
||||||
|
return callback(null, 0);
|
||||||
|
}
|
||||||
db.setCount('following:' + uid, callback);
|
db.setCount('following:' + uid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
User.getFollowerCount = function(uid, callback) {
|
User.getFollowerCount = function(uid, callback) {
|
||||||
|
if (!parseInt(uid, 10)) {
|
||||||
|
return callback(null, 0);
|
||||||
|
}
|
||||||
db.setCount('followers:' + uid, callback);
|
db.setCount('followers:' + uid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,6 +80,9 @@ module.exports = function(User) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
User.isFollowing = function(uid, theirid, callback) {
|
User.isFollowing = function(uid, theirid, callback) {
|
||||||
|
if (!parseInt(uid, 10) || !parseInt(theirid, 10)) {
|
||||||
|
return callback(null, false);
|
||||||
|
}
|
||||||
db.isSetMember('following:' + uid, theirid, callback);
|
db.isSetMember('following:' + uid, theirid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user