From 1a38644eb82437ebf4b065af4da4389b743d81dc Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 17 May 2013 21:14:58 -0400 Subject: [PATCH] exposing thread tools to users in the "administrators" set, fixing up Topics methods to call the "editable" method first instead of just checking rep thresholds. Also changed the limit on thread length from 10 to infinity (for now, until infinite scrolling makes it in) --- src/posts.js | 24 +++++++++++++++++++----- src/topics.js | 52 +++++++++++++++++++++++++++++++++++++-------------- src/user.js | 10 ++++++++-- 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/src/posts.js b/src/posts.js index 85103b827f..ab87b5ba63 100644 --- a/src/posts.js +++ b/src/posts.js @@ -15,7 +15,7 @@ marked.setOptions({ Posts.get = function(callback, tid, current_user, start, end) { if (start == null) start = 0; - if (end == null) end = start + 10; + if (end == null) end = -1;//start + 10; var post_data, user_data, thread_data, vote_data, viewer_data; @@ -30,8 +30,11 @@ marked.setOptions({ var posts = [], main_posts = [], - manage_content = viewer_data.reputation >= config.privilege_thresholds.manage_content; - + manage_content = ( + viewer_data.reputation >= config.privilege_thresholds.manage_content || + viewer_data.isModerator || + viewer_data.isAdministrator + ); for (var i=0, ii= post_data.pid.length; i= config.privilege_thresholds.manage_thread); + }); + }, + function(next) { + Topics.get_cid_by_tid(tid, function(cid) { + user.isModerator(uid, cid, function(isMod) { + next(null, isMod); + }); + }); + }, function(next) { + user.isAdministrator(uid, function(isAdmin) { + next(null, isAdmin); + }); + } + ], function(err, results) { + // If any return true, allow the edit + if (results.indexOf(true) !== -1) callback(true); + }); + } + Topics.get_topic = function(tid, uid, callback) { var topicData = {}; @@ -223,7 +247,7 @@ marked.setOptions({ } Topics.get_cid_by_tid = function(tid, callback) { - RDB.get('tid:' + pid + ':cid', function(err, cid) { + RDB.get('tid:' + tid + ':cid', function(err, cid) { if (cid && parseInt(cid) > 0) callback(cid); else callback(false); }); @@ -359,8 +383,8 @@ marked.setOptions({ }; Topics.lock = function(tid, uid, socket) { - user.getUserField(uid, 'reputation', function(rep) { - if (rep >= configs.privilege_thresholds.manage_thread) { + Topics.editable(tid, uid, function(editable) { + if (editable) { // Mark thread as locked RDB.set('tid:' + tid + ':locked', 1); @@ -375,8 +399,8 @@ marked.setOptions({ } Topics.unlock = function(tid, uid, socket) { - user.getUserField(uid, 'reputation', function(rep) { - if (rep >= configs.privilege_thresholds.manage_thread) { + Topics.editable(tid, uid, function(editable) { + if (editable) { // Mark thread as unlocked RDB.del('tid:' + tid + ':locked'); @@ -391,8 +415,8 @@ marked.setOptions({ } Topics.delete = function(tid, uid, socket) { - user.getUserField(uid, 'reputation', function(rep) { - if (rep >= configs.privilege_thresholds.manage_thread) { + Topics.editable(tid, uid, function(editable) { + if (editable) { // Mark thread as deleted RDB.set('tid:' + tid + ':deleted', 1); Topics.lock(tid, uid); @@ -408,8 +432,8 @@ marked.setOptions({ } Topics.restore = function(tid, uid, socket) { - user.getUserField(uid, 'reputation', function(rep) { - if (rep >= configs.privilege_thresholds.manage_thread) { + Topics.editable(tid, uid, function(editable) { + if (editable) { // Mark thread as restored RDB.del('tid:' + tid + ':deleted'); Topics.unlock(tid, uid); @@ -425,8 +449,8 @@ marked.setOptions({ } Topics.pin = function(tid, uid, socket) { - user.getUserField(uid, 'reputation', function(rep) { - if (rep >= configs.privilege_thresholds.manage_thread) { + Topics.editable(tid, uid, function(editable) { + if (editable) { // Mark thread as pinned RDB.set('tid:' + tid + ':pinned', 1); @@ -441,8 +465,8 @@ marked.setOptions({ } Topics.unpin = function(tid, uid, socket) { - user.getUserField(uid, 'reputation', function(rep) { - if (rep >= configs.privilege_thresholds.manage_thread) { + Topics.editable(tid, uid, function(editable) { + if (editable) { // Mark thread as unpinned RDB.del('tid:' + tid + ':pinned'); diff --git a/src/user.js b/src/user.js index 399f0ebb08..37d4577d3a 100644 --- a/src/user.js +++ b/src/user.js @@ -264,7 +264,7 @@ var config = require('../config.js'), User.exists(username, function(exists) { RDB.incr('global:next_user_id', function(err, uid) { - RDB.handle(err); + RDB.handfle(err); var gravatar = User.createGravatarURLFromEmail(email); @@ -524,7 +524,13 @@ var config = require('../config.js'), User.isModerator = function(uid, cid, callback) { RDB.sismember('cid:' + cid + ':moderators', uid, function(err, exists) { - callback(exists); + callback(!!exists); + }); + } + + User.isAdministrator = function(uid, callback) { + RDB.sismember('administrators', uid, function(err, exists) { + callback(!!exists); }); }