mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
@@ -278,7 +278,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
|
|||||||
|
|
||||||
pagination.recreatePaginationLinks(newPageCount);
|
pagination.recreatePaginationLinks(newPageCount);
|
||||||
|
|
||||||
if(pagination.currentPage === pagination.pageCount) {
|
if (pagination.currentPage === pagination.pageCount) {
|
||||||
createNewPosts(data);
|
createNewPosts(data);
|
||||||
} else if(data.posts && data.posts.length && parseInt(data.posts[0].uid, 10) === parseInt(app.uid, 10)) {
|
} else if(data.posts && data.posts.length && parseInt(data.posts[0].uid, 10) === parseInt(app.uid, 10)) {
|
||||||
pagination.loadPage(pagination.pageCount);
|
pagination.loadPage(pagination.pageCount);
|
||||||
@@ -390,8 +390,11 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toggleModTools(postHtml, privileges) {
|
function toggleModTools(postHtml, privileges) {
|
||||||
postHtml.find('.edit, .delete').toggleClass('none', !privileges.editable);
|
postHtml.find('.edit, .delete').toggleClass('none', !privileges.meta.editable);
|
||||||
postHtml.find('.move').toggleClass('none', !privileges.move);
|
postHtml.find('.move').toggleClass('none', !privileges.meta.move);
|
||||||
|
postHtml.find('.reply, .quote').toggleClass('none', !$('.post_reply').length)
|
||||||
|
var isSelfPost = parseInt(postHtml.attr('data-uid'), 10) === parseInt(app.uid, 10);
|
||||||
|
postHtml.find('.chat, .flag').toggleClass('none', isSelfPost);
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadMorePosts(tid, after, callback) {
|
function loadMorePosts(tid, after, callback) {
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ define(['forum/topic/fork', 'forum/topic/move'], function(fork, move) {
|
|||||||
ThreadTools.setPinnedState({tid: tid, isPinned: true});
|
ThreadTools.setPinnedState({tid: tid, isPinned: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ajaxify.variables.get('expose_tools') === '1') {
|
|
||||||
|
|
||||||
$('.thread-tools').removeClass('hide');
|
|
||||||
|
|
||||||
$('.delete_thread').on('click', function(e) {
|
$('.delete_thread').on('click', function(e) {
|
||||||
var command = threadState.deleted !== '1' ? 'delete' : 'restore';
|
var command = threadState.deleted !== '1' ? 'delete' : 'restore';
|
||||||
|
|
||||||
@@ -67,7 +63,6 @@ define(['forum/topic/fork', 'forum/topic/move'], function(fork, move) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
fork.init();
|
fork.init();
|
||||||
}
|
|
||||||
|
|
||||||
socket.emit('topics.followCheck', tid, function(err, state) {
|
socket.emit('topics.followCheck', tid, function(err, state) {
|
||||||
setFollowState(state);
|
setFollowState(state);
|
||||||
|
|||||||
@@ -10,27 +10,27 @@ var topicsController = {},
|
|||||||
meta = require('./../meta'),
|
meta = require('./../meta'),
|
||||||
topics = require('./../topics'),
|
topics = require('./../topics'),
|
||||||
posts = require('../posts'),
|
posts = require('../posts'),
|
||||||
threadTools = require('./../threadTools'),
|
privileges = require('../privileges'),
|
||||||
utils = require('./../../public/src/utils');
|
utils = require('./../../public/src/utils');
|
||||||
|
|
||||||
topicsController.get = function(req, res, next) {
|
topicsController.get = function(req, res, next) {
|
||||||
var tid = req.params.topic_id,
|
var tid = req.params.topic_id,
|
||||||
page = req.query.page || 1,
|
page = req.query.page || 1,
|
||||||
uid = req.user ? req.user.uid : 0,
|
uid = req.user ? req.user.uid : 0,
|
||||||
privileges;
|
userPrivileges;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
threadTools.privileges(tid, uid, function(err, userPrivileges) {
|
privileges.topics.get(tid, uid, function(err, privileges) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userPrivileges.meta.read) {
|
if (!privileges.meta.read) {
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
privileges = userPrivileges;
|
userPrivileges = privileges;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -45,7 +45,7 @@ topicsController.get = function(req, res, next) {
|
|||||||
|
|
||||||
topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) {
|
topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) {
|
||||||
if (topicData) {
|
if (topicData) {
|
||||||
if (parseInt(topicData.deleted, 10) === 1 && parseInt(topicData.expose_tools, 10) === 0) {
|
if (parseInt(topicData.deleted, 10) === 1 && !userPrivileges.view_deleted) {
|
||||||
return next(new Error('[[error:no-topic]]'));
|
return next(new Error('[[error:no-topic]]'));
|
||||||
}
|
}
|
||||||
topicData.currentPage = page;
|
topicData.currentPage = page;
|
||||||
@@ -154,7 +154,7 @@ topicsController.get = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.privileges = privileges;
|
data.privileges = userPrivileges;
|
||||||
|
|
||||||
var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
|
var topic_url = tid + (req.params.slug ? '/' + req.params.slug : '');
|
||||||
var queryString = qs.stringify(req.query);
|
var queryString = qs.stringify(req.query);
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
var privileges = {};
|
var privileges = {};
|
||||||
|
|
||||||
|
require('./privileges/categories')(privileges);
|
||||||
|
require('./privileges/topics')(privileges);
|
||||||
require('./privileges/posts')(privileges);
|
require('./privileges/posts')(privileges);
|
||||||
|
|
||||||
|
|
||||||
module.exports = privileges;
|
module.exports = privileges;
|
||||||
28
src/privileges/categories.js
Normal file
28
src/privileges/categories.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async'),
|
||||||
|
|
||||||
|
user = require('../user'),
|
||||||
|
helpers = require('./helpers');
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function(privileges) {
|
||||||
|
|
||||||
|
privileges.categories = {};
|
||||||
|
|
||||||
|
privileges.categories.canRead = function(cid, uid, callback) {
|
||||||
|
helpers.some([
|
||||||
|
function(next) {
|
||||||
|
helpers.allowedTo('read', uid, cid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
user.isModerator(uid, cid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
user.isAdministrator(uid, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
@@ -10,6 +10,16 @@ var async = require('async'),
|
|||||||
|
|
||||||
var helpers = {};
|
var helpers = {};
|
||||||
|
|
||||||
|
helpers.some = function(tasks, callback) {
|
||||||
|
async.some(tasks, function(task, next) {
|
||||||
|
task(function(err, result) {
|
||||||
|
next(!err && result);
|
||||||
|
});
|
||||||
|
}, function(result) {
|
||||||
|
callback(null, result);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
helpers.allowedTo = function(privilege, uid, cid, callback) {
|
helpers.allowedTo = function(privilege, uid, cid, callback) {
|
||||||
categories.getCategoryField(cid, 'disabled', function(err, disabled) {
|
categories.getCategoryField(cid, 'disabled', function(err, disabled) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -47,7 +57,7 @@ function isMember(method, group, uid, callback) {
|
|||||||
return callback(null, null);
|
return callback(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
method(group, uid, callback);
|
method(uid, group, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,28 +59,12 @@ module.exports = function(privileges) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.some([
|
privileges.categories.canRead(cid, uid, callback);
|
||||||
function(next) {
|
|
||||||
helpers.allowedTo('read', uid, cid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
user.isModerator(uid, cid, next);
|
|
||||||
},
|
|
||||||
function(next) {
|
|
||||||
user.isAdministrator(uid, next);
|
|
||||||
}
|
|
||||||
], function(task, next) {
|
|
||||||
task(function(err, result) {
|
|
||||||
next(!err && result);
|
|
||||||
});
|
|
||||||
}, function(result) {
|
|
||||||
callback(null, result);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
privileges.posts.canEdit = function(pid, uid, callback) {
|
privileges.posts.canEdit = function(pid, uid, callback) {
|
||||||
async.some([
|
helpers.some([
|
||||||
function(next) {
|
function(next) {
|
||||||
posts.isOwner(pid, uid, next);
|
posts.isOwner(pid, uid, next);
|
||||||
},
|
},
|
||||||
@@ -101,12 +85,22 @@ module.exports = function(privileges) {
|
|||||||
function(next) {
|
function(next) {
|
||||||
user.isAdministrator(uid, next);
|
user.isAdministrator(uid, next);
|
||||||
}
|
}
|
||||||
], function(task, next) {
|
], callback);
|
||||||
task(function(err, result) {
|
};
|
||||||
next(!err && result);
|
|
||||||
});
|
privileges.posts.canMove = function(pid, uid, callback) {
|
||||||
}, function(result) {
|
helpers.some([
|
||||||
callback(null, result);
|
function(next) {
|
||||||
|
posts.getCidByPid(pid, function(err, cid) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
user.isModerator(uid, cid, next);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
user.isAdministrator(uid, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
122
src/privileges/topics.js
Normal file
122
src/privileges/topics.js
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async'),
|
||||||
|
|
||||||
|
topics = require('../topics'),
|
||||||
|
user = require('../user'),
|
||||||
|
helpers = require('./helpers'),
|
||||||
|
groups = require('../groups'),
|
||||||
|
categories = require('../categories');
|
||||||
|
|
||||||
|
module.exports = function(privileges) {
|
||||||
|
|
||||||
|
privileges.topics = {};
|
||||||
|
|
||||||
|
privileges.topics.get = function(tid, uid, callback) {
|
||||||
|
|
||||||
|
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
async.parallel({
|
||||||
|
'topics:reply': function(next) {
|
||||||
|
helpers.allowedTo('topics:reply', uid, cid, next);
|
||||||
|
},
|
||||||
|
read: function(next) {
|
||||||
|
helpers.allowedTo('read', uid, cid, next);
|
||||||
|
},
|
||||||
|
manage_topic: function(next) {
|
||||||
|
helpers.hasEnoughReputationFor('privileges:manage_topic', uid, next);
|
||||||
|
},
|
||||||
|
isAdministrator: function(next) {
|
||||||
|
user.isAdministrator(uid, next);
|
||||||
|
},
|
||||||
|
isModerator: function(next) {
|
||||||
|
user.isModerator(uid, cid, next);
|
||||||
|
}
|
||||||
|
}, function(err, results) {
|
||||||
|
if(err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
var editable = results.isAdministrator || results.isModerator || results.manage_topic;
|
||||||
|
|
||||||
|
callback(null, {
|
||||||
|
meta: {
|
||||||
|
'topics:reply': results['topics:reply'],
|
||||||
|
editable: editable,
|
||||||
|
view_deleted: editable,
|
||||||
|
read: results.read
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
privileges.topics.canRead = function(tid, uid, callback) {
|
||||||
|
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
privileges.categories.canRead(cid, uid, callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
privileges.topics.canReply = function(tid, uid, callback) {
|
||||||
|
topics.getTopicField(tid, 'cid', function(err, cid) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
helpers.some([
|
||||||
|
function(next) {
|
||||||
|
helpers.allowedTo('topics:reply', uid, cid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
user.isModerator(uid, cid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
user.isAdministrator(uid, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
privileges.topics.canEdit = function(tid, uid, callback) {
|
||||||
|
helpers.some([
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
privileges.topics.canMove = function(tid, uid, callback) {
|
||||||
|
helpers.some([
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -7,30 +7,29 @@ var posts = require('./../posts'),
|
|||||||
rss = require('rss'),
|
rss = require('rss'),
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
|
|
||||||
ThreadTools = require('./../threadTools'),
|
privileges = require('../privileges');
|
||||||
CategoryTools = require('./../categoryTools');
|
|
||||||
|
|
||||||
function hasTopicPrivileges(req, res, next) {
|
function hasTopicPrivileges(req, res, next) {
|
||||||
var tid = req.params.topic_id;
|
var tid = req.params.topic_id;
|
||||||
|
|
||||||
hasPrivileges(ThreadTools, tid, req, res, next);
|
hasPrivileges(privileges.topics.canRead, tid, req, res, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasCategoryPrivileges(req, res, next) {
|
function hasCategoryPrivileges(req, res, next) {
|
||||||
var cid = req.params.category_id;
|
var cid = req.params.category_id;
|
||||||
|
|
||||||
hasPrivileges(CategoryTools, cid, req, res, next);
|
hasPrivileges(privileges.categories.canRead, cid, req, res, next);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasPrivileges(module, id, req, res, next) {
|
function hasPrivileges(method, id, req, res, next) {
|
||||||
var uid = req.user ? req.user.uid || 0 : 0;
|
var uid = req.user ? req.user.uid || 0 : 0;
|
||||||
|
|
||||||
module.privileges(id, uid, function(err, privileges) {
|
method(id, uid, function(err, canRead) {
|
||||||
if(err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!privileges.read) {
|
if (!canRead) {
|
||||||
return res.redirect('403');
|
return res.redirect('403');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +65,7 @@ function generateForTopic(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
topicData.posts.forEach(function(postData) {
|
topicData.posts.forEach(function(postData) {
|
||||||
if (parseInt(postData.deleted, 10) === 0) {
|
if (!postData.deleted) {
|
||||||
dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
|
dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
|
||||||
|
|
||||||
feed.item({
|
feed.item({
|
||||||
|
|||||||
@@ -37,8 +37,15 @@ SocketPosts.reply = function(socket, data, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (postData) {
|
if (postData) {
|
||||||
|
var privileges = {
|
||||||
|
meta : {
|
||||||
|
'topics:reply': true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
websockets.server.sockets.emit('event:new_post', {
|
websockets.server.sockets.emit('event:new_post', {
|
||||||
posts: [postData]
|
posts: [postData],
|
||||||
|
privileges: privileges
|
||||||
});
|
});
|
||||||
|
|
||||||
module.parent.exports.emitTopicPostStats();
|
module.parent.exports.emitTopicPostStats();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
var topics = require('../topics'),
|
var topics = require('../topics'),
|
||||||
categories = require('../categories'),
|
categories = require('../categories'),
|
||||||
|
privileges = require('../privileges'),
|
||||||
threadTools = require('../threadTools'),
|
threadTools = require('../threadTools'),
|
||||||
categoryTools = require('../categoryTools'),
|
categoryTools = require('../categoryTools'),
|
||||||
websockets = require('./index'),
|
websockets = require('./index'),
|
||||||
@@ -181,12 +182,12 @@ function doTopicAction(action, socket, tids, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async.each(tids, function(tid, next) {
|
async.each(tids, function(tid, next) {
|
||||||
threadTools.privileges(tid, socket.uid, function(err, privileges) {
|
privileges.topics.canEdit(tid, socket.uid, function(err, canEdit) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!privileges || !privileges.meta.editable) {
|
if(!canEdit) {
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,21 +211,17 @@ SocketTopics.createTopicFromPosts = function(socket, data, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.movePost = function(socket, data, callback) {
|
SocketTopics.movePost = function(socket, data, callback) {
|
||||||
if(!socket.uid) {
|
if (!socket.uid) {
|
||||||
return callback(new Error('[[error:not-logged-in]]'));
|
return callback(new Error('[[error:not-logged-in]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!data || !data.pid || !data.tid) {
|
if (!data || !data.pid || !data.tid) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
threadTools.privileges(data.tid, socket.uid, function(err, privileges) {
|
privileges.posts.canMove(data.tid, socket.uid, function(err, canMove) {
|
||||||
if(err) {
|
if (err || !canMove) {
|
||||||
return callback(err);
|
return callback(err || new Error('[[error:no-privileges]]'));
|
||||||
}
|
|
||||||
|
|
||||||
if(!(privileges.admin || privileges.moderator)) {
|
|
||||||
return callback(new Error('[[error:no-privileges]]'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
topics.movePostToTopic(data.pid, data.tid, callback);
|
topics.movePostToTopic(data.pid, data.tid, callback);
|
||||||
@@ -240,10 +237,10 @@ SocketTopics.move = function(socket, data, callback) {
|
|||||||
var oldCid;
|
var oldCid;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function(next) {
|
function(next) {
|
||||||
threadTools.privileges(tid, socket.uid, next);
|
privileges.topics.canMove(tid, socket.uid, next);
|
||||||
},
|
},
|
||||||
function(privileges, next) {
|
function(canMove, next) {
|
||||||
if(!(privileges.admin || privileges.moderator)) {
|
if (!canMove) {
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
@@ -336,7 +333,7 @@ SocketTopics.loadMore = function(socket, data, callback) {
|
|||||||
topics.getTopicPosts(data.tid, start, end, socket.uid, false, next);
|
topics.getTopicPosts(data.tid, start, end, socket.uid, false, next);
|
||||||
},
|
},
|
||||||
privileges: function(next) {
|
privileges: function(next) {
|
||||||
threadTools.privileges(data.tid, socket.uid, next);
|
privileges.topics.get(data.tid, socket.uid, next);
|
||||||
}
|
}
|
||||||
}, callback);
|
}, callback);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,38 +23,6 @@ var winston = require('winston'),
|
|||||||
db.isSortedSetMember('topics:tid', tid, callback);
|
db.isSortedSetMember('topics:tid', tid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
ThreadTools.privileges = function(tid, uid, callback) {
|
|
||||||
async.parallel({
|
|
||||||
categoryPrivs: function(next) {
|
|
||||||
topics.getTopicField(tid, 'cid', function(err, cid) {
|
|
||||||
CategoryTools.privileges(cid, uid, next);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
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_topic'], 10));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, function(err, results) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
var privileges = results.categoryPrivs;
|
|
||||||
privileges.meta.editable = privileges.meta.editable || results.hasEnoughRep;
|
|
||||||
privileges.meta.view_deleted = privileges.meta.view_deleted || results.hasEnoughRep;
|
|
||||||
|
|
||||||
callback(null, privileges);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
ThreadTools.delete = function(tid, uid, callback) {
|
ThreadTools.delete = function(tid, uid, callback) {
|
||||||
toggleDelete(tid, uid, true, callback);
|
toggleDelete(tid, uid, true, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ var async = require('async'),
|
|||||||
user = require('./user'),
|
user = require('./user'),
|
||||||
categories = require('./categories'),
|
categories = require('./categories'),
|
||||||
categoryTools = require('./categoryTools'),
|
categoryTools = require('./categoryTools'),
|
||||||
threadTools = require('./threadTools');
|
threadTools = require('./threadTools'),
|
||||||
|
privileges = require('./privileges');
|
||||||
|
|
||||||
(function(Topics) {
|
(function(Topics) {
|
||||||
|
|
||||||
@@ -132,8 +133,8 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
async.filter(tids, function(tid, next) {
|
async.filter(tids, function(tid, next) {
|
||||||
threadTools.privileges(tid, uid, function(err, privileges) {
|
privileges.topics.canRead(tid, uid, function(err, canRead) {
|
||||||
next(!err && privileges.meta.read);
|
next(!err && canRead);
|
||||||
});
|
});
|
||||||
}, function(tids) {
|
}, function(tids) {
|
||||||
Topics.getTopicsByTids(tids, uid, function(err, topicData) {
|
Topics.getTopicsByTids(tids, uid, function(err, topicData) {
|
||||||
@@ -269,9 +270,6 @@ var async = require('async'),
|
|||||||
posts: function(next) {
|
posts: function(next) {
|
||||||
Topics.getTopicPosts(tid, start, end, uid, false, next);
|
Topics.getTopicPosts(tid, start, end, uid, false, next);
|
||||||
},
|
},
|
||||||
privileges: function(next) {
|
|
||||||
threadTools.privileges(tid, uid, next);
|
|
||||||
},
|
|
||||||
category: function(next) {
|
category: function(next) {
|
||||||
Topics.getCategoryData(tid, next);
|
Topics.getCategoryData(tid, next);
|
||||||
},
|
},
|
||||||
@@ -291,7 +289,6 @@ var async = require('async'),
|
|||||||
topicData.thread_tools = results.threadTools;
|
topicData.thread_tools = results.threadTools;
|
||||||
topicData.pageCount = results.pageCount;
|
topicData.pageCount = results.pageCount;
|
||||||
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
|
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
|
||||||
topicData.expose_tools = results.privileges.meta.editable ? 1 : 0;
|
|
||||||
|
|
||||||
callback(null, topicData);
|
callback(null, topicData);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ var async = require('async'),
|
|||||||
meta = require('./../meta'),
|
meta = require('./../meta'),
|
||||||
posts = require('./../posts'),
|
posts = require('./../posts'),
|
||||||
threadTools = require('./../threadTools'),
|
threadTools = require('./../threadTools'),
|
||||||
|
privileges = require('../privileges'),
|
||||||
categoryTools = require('./../categoryTools');
|
categoryTools = require('./../categoryTools');
|
||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
@@ -144,7 +145,6 @@ module.exports = function(Topics) {
|
|||||||
uid = data.uid,
|
uid = data.uid,
|
||||||
toPid = data.toPid,
|
toPid = data.toPid,
|
||||||
content = data.content,
|
content = data.content,
|
||||||
privileges,
|
|
||||||
postData;
|
postData;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
@@ -173,11 +173,10 @@ module.exports = function(Topics) {
|
|||||||
return next(new Error('[[error:topic-locked]]'));
|
return next(new Error('[[error:topic-locked]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
threadTools.privileges(tid, uid, next);
|
privileges.topics.canReply(tid, uid, next);
|
||||||
},
|
},
|
||||||
function(privilegesData, next) {
|
function(canReply, next) {
|
||||||
privileges = privilegesData;
|
if (!canReply) {
|
||||||
if (!privileges.meta['topics:reply']) {
|
|
||||||
return next(new Error('[[error:no-privileges]]'));
|
return next(new Error('[[error:no-privileges]]'));
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
@@ -232,7 +231,8 @@ module.exports = function(Topics) {
|
|||||||
postData.favourited = false;
|
postData.favourited = false;
|
||||||
postData.votes = 0;
|
postData.votes = 0;
|
||||||
postData.display_moderator_tools = true;
|
postData.display_moderator_tools = true;
|
||||||
postData.display_move_tools = privileges.admin || privileges.moderator;
|
postData.display_move_tools = true;
|
||||||
|
postData.selfPost = false;
|
||||||
postData.relativeTime = utils.toISOString(postData.timestamp);
|
postData.relativeTime = utils.toISOString(postData.timestamp);
|
||||||
|
|
||||||
next(null, postData);
|
next(null, postData);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ var async = require('async'),
|
|||||||
user = require('./../user'),
|
user = require('./../user'),
|
||||||
notifications = require('./../notifications'),
|
notifications = require('./../notifications'),
|
||||||
categories = require('./../categories'),
|
categories = require('./../categories'),
|
||||||
threadTools = require('./../threadTools');
|
privileges = require('../privileges');
|
||||||
|
|
||||||
module.exports = function(Topics) {
|
module.exports = function(Topics) {
|
||||||
|
|
||||||
@@ -49,8 +49,8 @@ module.exports = function(Topics) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async.filter(newtids, function(tid, next) {
|
async.filter(newtids, function(tid, next) {
|
||||||
threadTools.privileges(tid, uid, function(err, privileges) {
|
privileges.topics.canRead(tid, uid, function(err, canRead) {
|
||||||
next(!err && privileges.meta.read);
|
next(!err && canRead);
|
||||||
});
|
});
|
||||||
}, function(newtids) {
|
}, function(newtids) {
|
||||||
unreadTids.push.apply(unreadTids, newtids);
|
unreadTids.push.apply(unreadTids, newtids);
|
||||||
|
|||||||
Reference in New Issue
Block a user