mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-31 19:15:58 +01:00
fixed #744
This commit is contained in:
@@ -26,43 +26,35 @@ var winston = require('winston'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
PostTools.privileges = function(pid, uid, callback) {
|
PostTools.privileges = function(pid, uid, callback) {
|
||||||
if(parseInt(uid, 10) === 0) {
|
async.parallel({
|
||||||
callback({
|
topicPrivs: function(next) {
|
||||||
editable: false,
|
posts.getPostField(pid, 'tid', function(err, tid) {
|
||||||
view_deleted: false
|
threadTools.privileges(tid, uid, next);
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getThreadPrivileges(next) {
|
|
||||||
posts.getPostField(pid, 'tid', function(err, tid) {
|
|
||||||
threadTools.privileges(tid, uid, next);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function isOwnPost(next) {
|
|
||||||
posts.getPostField(pid, 'uid', function(err, author) {
|
|
||||||
next(null, parseInt(author, 10) === parseInt(uid, 10));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasEnoughRep(next) {
|
|
||||||
if (parseInt(meta.config['privileges:disabled'], 10)) {
|
|
||||||
return next(null, false);
|
|
||||||
} else {
|
|
||||||
user.getUserField(uid, 'reputation', function(err, reputation) {
|
|
||||||
if (err) {
|
|
||||||
return next(null, false);
|
|
||||||
}
|
|
||||||
next(null, parseInt(reputation, 10) >= parseInt(meta.config['privileges:manage_content'], 10));
|
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
isOwner: function(next) {
|
||||||
|
posts.getPostField(pid, 'uid', function(err, author) {
|
||||||
|
next(null, parseInt(author, 10) === parseInt(uid, 10));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
hasEnoughRep: function(next) {
|
||||||
|
if (parseInt(meta.config['privileges:disabled'], 10)) {
|
||||||
|
return next(null, false);
|
||||||
|
} else {
|
||||||
|
user.getUserField(uid, 'reputation', function(err, reputation) {
|
||||||
|
if (err) {
|
||||||
|
return next(null, false);
|
||||||
|
}
|
||||||
|
next(null, parseInt(reputation, 10) >= parseInt(meta.config['privileges:manage_content'], 10));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// [getThreadPrivileges, isOwnPost, hasEnoughRep]
|
||||||
|
}, function(err, results) {
|
||||||
async.parallel([getThreadPrivileges, isOwnPost, hasEnoughRep], function(err, results) {
|
|
||||||
callback({
|
callback({
|
||||||
editable: results[0].editable || results[1] || results[2],
|
read: results.topicPrivs.read,
|
||||||
view_deleted: results[0].view_deleted || results[1] || results[2]
|
editable: results.topicPrivs.editable || results.isOwner || results.hasEnoughRep,
|
||||||
|
view_deleted: results.topicPrivs.view_deleted || results.isOwner || results.hasEnoughRep
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
40
src/posts.js
40
src/posts.js
@@ -426,24 +426,30 @@ var db = require('./database'),
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pids && pids.length) {
|
async.filter(pids, function(pid, next) {
|
||||||
plugins.fireHook('filter:post.getTopic', pids, function(err, posts) {
|
postTools.privileges(pid, 0, function(privileges) {
|
||||||
if(err) {
|
next(privileges.read);
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (posts && posts.length) {
|
|
||||||
Posts.getPostsByPids(pids, function(err, posts) {
|
|
||||||
plugins.fireHook('action:post.gotTopic', posts);
|
|
||||||
callback(null, posts);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
callback(null, []);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
}, function(pids) {
|
||||||
callback(null, []);
|
if (pids && pids.length) {
|
||||||
}
|
plugins.fireHook('filter:post.getTopic', pids, function(err, posts) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (posts && posts.length) {
|
||||||
|
Posts.getPostsByPids(pids, function(err, posts) {
|
||||||
|
plugins.fireHook('action:post.gotTopic', posts);
|
||||||
|
callback(null, posts);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(null, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback(null, []);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user