mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-13 08:00:43 +01:00
closes #1731
This commit is contained in:
@@ -472,10 +472,7 @@ var async = require('async'),
|
||||
|
||||
Posts.isOwner = function(pid, uid, callback) {
|
||||
Posts.getPostField(pid, 'uid', function(err, author) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, parseInt(author, 10) === parseInt(uid, 10));
|
||||
callback(err, parseInt(author, 10) === parseInt(uid, 10));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -73,20 +73,16 @@ module.exports = function(privileges) {
|
||||
helpers.hasEnoughReputationFor('privileges:manage_topic', uid, next);
|
||||
},
|
||||
function(next) {
|
||||
posts.getCidByPid(pid, function(err, cid) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
user.isModerator(uid, cid, next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
user.isAdministrator(uid, next);
|
||||
isAdminOrMod(pid, uid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
privileges.posts.canMove = function(pid, uid, callback) {
|
||||
isAdminOrMod(pid, uid, callback);
|
||||
};
|
||||
|
||||
function isAdminOrMod(pid, uid, callback) {
|
||||
helpers.some([
|
||||
function(next) {
|
||||
posts.getCidByPid(pid, function(err, cid) {
|
||||
@@ -100,5 +96,5 @@ module.exports = function(privileges) {
|
||||
user.isAdministrator(uid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,6 +27,9 @@ module.exports = function(privileges) {
|
||||
read: function(next) {
|
||||
helpers.allowedTo('read', uid, cid, next);
|
||||
},
|
||||
isOwner: function(next) {
|
||||
topics.isOwner(tid, uid, next);
|
||||
},
|
||||
manage_topic: function(next) {
|
||||
helpers.hasEnoughReputationFor('privileges:manage_topic', uid, next);
|
||||
},
|
||||
@@ -40,14 +43,17 @@ module.exports = function(privileges) {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var editable = results.isAdministrator || results.isModerator || results.manage_topic;
|
||||
var isAdminOrMod = results.isAdministrator || results.isModerator;
|
||||
var editable = isAdminOrMod || results.manage_topic;
|
||||
var deletable = isAdminOrMod || results.isOwner;
|
||||
|
||||
callback(null, {
|
||||
'topics:reply': results['topics:reply'],
|
||||
read: results.read,
|
||||
view_thread_tools: editable || deletable,
|
||||
editable: editable,
|
||||
view_deleted: editable,
|
||||
read: results.read
|
||||
deletable: deletable,
|
||||
view_deleted: isAdminOrMod || results.manage_topic || results.isOwner
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -65,24 +71,23 @@ module.exports = function(privileges) {
|
||||
|
||||
privileges.topics.canEdit = function(tid, uid, callback) {
|
||||
helpers.some([
|
||||
function(next) {
|
||||
topics.isOwner(tid, uid, next);
|
||||
},
|
||||
function(next) {
|
||||
helpers.hasEnoughReputationFor('privileges:manage_topic', uid, next);
|
||||
},
|
||||
function(next) {
|
||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
user.isModerator(uid, cid, next);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
user.isAdministrator(uid, next);
|
||||
isAdminOrMod(tid, uid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
|
||||
privileges.topics.canMove = function(tid, uid, callback) {
|
||||
isAdminOrMod(tid, uid, callback);
|
||||
};
|
||||
|
||||
function isAdminOrMod(tid, uid, callback) {
|
||||
helpers.some([
|
||||
function(next) {
|
||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||
@@ -96,5 +101,5 @@ module.exports = function(privileges) {
|
||||
user.isAdministrator(uid, next);
|
||||
}
|
||||
], callback);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -395,6 +395,12 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Topics.isOwner = function(tid, uid, callback) {
|
||||
Topics.getTopicField(tid, 'uid', function(err, author) {
|
||||
callback(err, parseInt(author, 10) === parseInt(uid, 10));
|
||||
});
|
||||
};
|
||||
|
||||
Topics.updateTimestamp = function(tid, timestamp) {
|
||||
db.sortedSetAdd('topics:recent', timestamp, tid);
|
||||
Topics.setTopicField(tid, 'lastposttime', timestamp);
|
||||
|
||||
Reference in New Issue
Block a user