mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 20:16:04 +01:00
privilege cleanup
This commit is contained in:
@@ -164,7 +164,7 @@ var db = require('./database'),
|
||||
}
|
||||
|
||||
async.filter(pids, function(pid, next) {
|
||||
privileges.posts.canRead(pid, callerUid, function(err, canRead) {
|
||||
privileges.posts.can('read', pid, callerUid, function(err, canRead) {
|
||||
next(!err && canRead);
|
||||
});
|
||||
}, function(pids) {
|
||||
@@ -216,7 +216,7 @@ var db = require('./database'),
|
||||
}
|
||||
|
||||
async.filter(pids, function(pid, next) {
|
||||
privileges.posts.canRead(pid, uid, function(err, canRead) {
|
||||
privileges.posts.can('read', pid, uid, function(err, canRead) {
|
||||
next(!err && canRead);
|
||||
});
|
||||
}, function(pids) {
|
||||
|
||||
@@ -58,20 +58,6 @@ module.exports = function(privileges) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
privileges.categories.canMoveAllTopics = function(currentCid, targetCid, uid, callback) {
|
||||
async.parallel({
|
||||
isAdministrator: function(next) {
|
||||
|
||||
@@ -30,22 +30,8 @@ helpers.allowedTo = function(privilege, uid, cid, callback) {
|
||||
return callback(null, false);
|
||||
}
|
||||
|
||||
// Guests handling
|
||||
if (parseInt(uid, 10) === 0) {
|
||||
return async.parallel([
|
||||
function(next) {
|
||||
groups.exists('cid:' + cid + ':privileges:' + privilege, function(err, exists) {
|
||||
next(err, !err ? !exists : false);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
helpers.isMember(groups.isMember, 'cid:' + cid + ':privileges:groups:' + privilege, 'guests', function(err, isMember) {
|
||||
next(err, privilege !== 'find' && privilege !== 'read' ? isMember === true : isMember !== false);
|
||||
});
|
||||
}
|
||||
], function(err, results) {
|
||||
callback(err, results[0] && (results[1] || results[1] === null));
|
||||
});
|
||||
return isGuestAllowedTo(privilege, cid, callback);
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
@@ -65,6 +51,23 @@ helpers.allowedTo = function(privilege, uid, cid, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
function isGuestAllowedTo(privilege, cid, callback) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
groups.exists('cid:' + cid + ':privileges:' + privilege, function(err, exists) {
|
||||
next(err, !err ? !exists : false);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
helpers.isMember(groups.isMember, 'cid:' + cid + ':privileges:groups:' + privilege, 'guests', function(err, isMember) {
|
||||
next(err, privilege !== 'find' && privilege !== 'read' ? isMember === true : isMember !== false);
|
||||
});
|
||||
}
|
||||
], function(err, results) {
|
||||
callback(err, results[0] && (results[1] || results[1] === null));
|
||||
});
|
||||
}
|
||||
|
||||
helpers.isMember = function(method, group, uid, callback) {
|
||||
groups.exists(group, function(err, exists) {
|
||||
if (err) {
|
||||
@@ -77,7 +80,7 @@ helpers.isMember = function(method, group, uid, callback) {
|
||||
|
||||
method(uid, group, callback);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
helpers.hasEnoughReputationFor = function(privilege, uid, callback) {
|
||||
if (parseInt(meta.config['privileges:disabled'], 10)) {
|
||||
|
||||
@@ -53,13 +53,13 @@ module.exports = function(privileges) {
|
||||
});
|
||||
};
|
||||
|
||||
privileges.posts.canRead = function(pid, uid, callback) {
|
||||
privileges.posts.can = function(privilege, pid, uid, callback) {
|
||||
posts.getCidByPid(pid, function(err, cid) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
privileges.categories.canRead(cid, uid, callback);
|
||||
privileges.categories.can(privilege, cid, uid, callback);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -65,50 +65,6 @@ module.exports = function(privileges) {
|
||||
});
|
||||
};
|
||||
|
||||
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.canCreate = function(cid, uid, callback) {
|
||||
helpers.some([
|
||||
function(next) {
|
||||
helpers.allowedTo('topics:create', uid, cid, next);
|
||||
},
|
||||
function(next) {
|
||||
user.isModerator(uid, cid, next);
|
||||
},
|
||||
function(next) {
|
||||
user.isAdministrator(uid, next);
|
||||
}
|
||||
], 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) {
|
||||
|
||||
@@ -9,7 +9,7 @@ var async = require('async'),
|
||||
SocketCategories = {};
|
||||
|
||||
SocketCategories.getRecentReplies = function(socket, cid, callback) {
|
||||
privileges.categories.canRead(cid, socket.uid, function(err, canRead) {
|
||||
privileges.categories.can('read', cid, socket.uid, function(err, canRead) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ function sendNotificationToPostOwner(data, uid, notification) {
|
||||
SocketPosts.getRawPost = function(socket, pid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
privileges.posts.canRead(pid, socket.uid, next);
|
||||
privileges.posts.can('read', pid, socket.uid, next);
|
||||
},
|
||||
function(canRead, next) {
|
||||
if (!canRead) {
|
||||
|
||||
@@ -130,7 +130,7 @@ var async = require('async'),
|
||||
}
|
||||
|
||||
async.filter(tids, function(tid, next) {
|
||||
privileges.topics.canRead(tid, uid, function(err, canRead) {
|
||||
privileges.topics.can('read', tid, uid, function(err, canRead) {
|
||||
next(!err && canRead);
|
||||
});
|
||||
}, function(tids) {
|
||||
|
||||
@@ -99,7 +99,7 @@ module.exports = function(Topics) {
|
||||
if (!categoryExists) {
|
||||
return next(new Error('[[error:no-category]]'));
|
||||
}
|
||||
privileges.topics.canCreate(cid, uid, next);
|
||||
privileges.categories.can('topics:create', cid, uid, next);
|
||||
},
|
||||
function(canCreate, next) {
|
||||
if(!canCreate) {
|
||||
@@ -173,7 +173,7 @@ module.exports = function(Topics) {
|
||||
return next(new Error('[[error:topic-locked]]'));
|
||||
}
|
||||
|
||||
privileges.topics.canReply(tid, uid, next);
|
||||
privileges.topics.can('topics:reply', tid, uid, next);
|
||||
},
|
||||
function(canReply, next) {
|
||||
if (!canReply) {
|
||||
|
||||
@@ -49,7 +49,7 @@ module.exports = function(Topics) {
|
||||
});
|
||||
|
||||
async.filter(newtids, function(tid, next) {
|
||||
privileges.topics.canRead(tid, uid, function(err, canRead) {
|
||||
privileges.topics.can('read', tid, uid, function(err, canRead) {
|
||||
next(!err && canRead);
|
||||
});
|
||||
}, function(newtids) {
|
||||
|
||||
Reference in New Issue
Block a user