diff --git a/src/categories.js b/src/categories.js
index 58cf09c204..6a6adc8c9e 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -1,7 +1,8 @@
var RDB = require('./redis.js'),
posts = require('./posts.js'),
utils = require('./utils.js'),
- user = require('./user.js');
+ user = require('./user.js'),
+ async = require('async');
(function(Categories) {
@@ -27,6 +28,30 @@ var RDB = require('./redis.js'),
});
};
+ Categories.privileges = function(cid, uid, callback) {
+ async.parallel([
+ // function(next) {
+ // user.getUserField(uid, 'reputation', function(reputation) {
+ // next(null, reputation >= config.privilege_thresholds.manage_category);
+ // });
+ // },
+ function(next) {
+ user.isModerator(uid, cid, function(isMod) {
+ next(null, isMod);
+ });
+ }, function(next) {
+ user.isAdministrator(uid, function(isAdmin) {
+ next(null, isAdmin);
+ });
+ }
+ ], function(err, results) {
+ callback({
+ editable: results.indexOf(true) !== -1 ? true : false,
+ view_deleted: results.indexOf(true) !== -1 ? true : false
+ });
+ });
+ }
+
Categories.edit = function(data, callback) {
// just a reminder to self that name + slugs are stored into topics data as well.
};
diff --git a/src/posts.js b/src/posts.js
index 753ed3e8c2..a4e2580d4e 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -13,34 +13,28 @@ marked.setOptions({
(function(Posts) {
Posts.get = function(callback, tid, current_user, start, end) {
-
if (start == null) start = 0;
if (end == null) end = -1;//start + 10;
- var post_data, user_data, thread_data, vote_data, viewer_data;
+ var post_data, user_data, thread_data, vote_data, privileges;
getTopicPosts();
- getViewerData();
+ getPrivileges();
//compile thread after all data is asynchronously called
function generateThread() {
- if (!post_data || !user_data || !thread_data || !vote_data || !viewer_data) return;
+ if (!post_data || !user_data || !thread_data || !vote_data || !privileges) return;
var posts = [],
- main_posts = [],
- manage_content = (
- viewer_data.reputation >= config.privilege_thresholds.manage_content ||
- viewer_data.isModerator ||
- viewer_data.isAdministrator
- );
+ main_posts = [];
for (var i=0, ii= post_data.pid.length; i 0) next(null, author === uid);
@@ -202,23 +179,12 @@ marked.setOptions({
user.getUserField(uid, 'reputation', function(reputation) {
next(null, reputation >= config.privilege_thresholds.manage_content);
});
- },
- function(next) {
- Posts.get_tid_by_pid(pid, function(tid) {
- RDB.get('tid:' + tid + ':cid', function(err, 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);
+ callback({
+ editable: results[0].editable || (results.slice(1).indexOf(true) !== -1 ? true : false),
+ view_deleted: results[0].view_deleted || (results.slice(1).indexOf(true) !== -1 ? true : false)
+ });
});
}
@@ -462,8 +428,8 @@ marked.setOptions({
});
};
- Posts.editable(uid, pid, function(editable) {
- if (editable) success();
+ Posts.privileges(pid, uid, function(privileges) {
+ if (privileges.editable) success();
});
}
@@ -476,8 +442,8 @@ marked.setOptions({
});
};
- Posts.editable(uid, pid, function(editable) {
- if (editable) success();
+ Posts.privileges(pid, uid, function(privileges) {
+ if (privileges.editable) success();
});
}
@@ -490,8 +456,8 @@ marked.setOptions({
});
};
- Posts.editable(uid, pid, function(editable) {
- if (editable) success();
+ Posts.privileges(pid, uid, function(privileges) {
+ if (privileges.editable) success();
});
}
}(exports));
\ No newline at end of file
diff --git a/src/topics.js b/src/topics.js
index 37be5dbcb3..b6afa9e93b 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -87,29 +87,33 @@ marked.setOptions({
var usernames,
has_read,
moderators,
- teaser_info;
+ teaser_info,
+ privileges;
function generate_topic() {
- if (!usernames || !has_read || !moderators || !teaser_info) return;
+ if (!usernames || !has_read || !moderators || !teaser_info || !privileges) return;
if (tids.length > 0) {
for (var i=0, ii=title.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);
+ callback({
+ editable: results[0].editable || (results.slice(1).indexOf(true) !== -1 ? true : false),
+ view_deleted: results[0].view_deleted || (results.slice(1).indexOf(true) !== -1 ? true : false)
+ });
});
}
@@ -383,8 +381,8 @@ marked.setOptions({
};
Topics.lock = function(tid, uid, socket) {
- Topics.editable(tid, uid, function(editable) {
- if (editable) {
+ Topics.privileges(tid, uid, function(privileges) {
+ if (privileges.editable) {
// Mark thread as locked
RDB.set('tid:' + tid + ':locked', 1);
@@ -399,8 +397,8 @@ marked.setOptions({
}
Topics.unlock = function(tid, uid, socket) {
- Topics.editable(tid, uid, function(editable) {
- if (editable) {
+ Topics.privileges(tid, uid, function(privileges) {
+ if (privileges.editable) {
// Mark thread as unlocked
RDB.del('tid:' + tid + ':locked');
@@ -415,8 +413,8 @@ marked.setOptions({
}
Topics.delete = function(tid, uid, socket) {
- Topics.editable(tid, uid, function(editable) {
- if (editable) {
+ Topics.privileges(tid, uid, function(privileges) {
+ if (privileges.editable) {
// Mark thread as deleted
RDB.set('tid:' + tid + ':deleted', 1);
Topics.lock(tid, uid);
@@ -432,8 +430,8 @@ marked.setOptions({
}
Topics.restore = function(tid, uid, socket) {
- Topics.editable(tid, uid, function(editable) {
- if (editable) {
+ Topics.privileges(tid, uid, function(privileges) {
+ if (privileges.editable) {
// Mark thread as restored
RDB.del('tid:' + tid + ':deleted');
Topics.unlock(tid, uid);
@@ -449,8 +447,8 @@ marked.setOptions({
}
Topics.pin = function(tid, uid, socket) {
- Topics.editable(tid, uid, function(editable) {
- if (editable) {
+ Topics.privileges(tid, uid, function(privileges) {
+ if (privileges.editable) {
// Mark thread as pinned
RDB.set('tid:' + tid + ':pinned', 1);
@@ -465,8 +463,8 @@ marked.setOptions({
}
Topics.unpin = function(tid, uid, socket) {
- Topics.editable(tid, uid, function(editable) {
- if (editable) {
+ Topics.privileges(tid, uid, function(privileges) {
+ if (privileges.editable) {
// Mark thread as unpinned
RDB.del('tid:' + tid + ':pinned');