mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	closes #2904
This commit is contained in:
		| @@ -83,30 +83,5 @@ function isGuestAllowedTo(privilege, cids, callback) { | ||||
| 	groups.isMemberOfGroups('guests', groupKeys, callback); | ||||
| } | ||||
|  | ||||
| helpers.hasEnoughReputationFor = function(privilege, uid, callback) { | ||||
| 	if (parseInt(meta.config['privileges:disabled'], 10) || !parseInt(uid, 10)) { | ||||
| 		return callback(null, false); | ||||
| 	} | ||||
|  | ||||
| 	user.getUserField(uid, 'reputation', function(err, reputation) { | ||||
| 		if (err) { | ||||
| 			return callback(null, false); | ||||
| 		} | ||||
|  | ||||
| 		reputation = parseInt(reputation, 10); | ||||
|  | ||||
| 		if (Array.isArray(privilege)) { | ||||
| 			for(var i=0; i<privilege.length; ++i) { | ||||
| 				if (reputation >= parseInt(meta.config[privilege[i]], 10)) { | ||||
| 					return callback(null, true); | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			callback(null, false); | ||||
| 		} else { | ||||
| 			callback(null, reputation >= parseInt(meta.config[privilege], 10)); | ||||
| 		} | ||||
| 	}); | ||||
| }; | ||||
|  | ||||
| module.exports = helpers; | ||||
| @@ -21,45 +21,34 @@ module.exports = function(privileges) { | ||||
| 		if (!Array.isArray(pids) || !pids.length) { | ||||
| 			return callback(null, []); | ||||
| 		} | ||||
|  | ||||
| 		async.parallel({ | ||||
| 			manage: function(next) { | ||||
| 				helpers.hasEnoughReputationFor(['privileges:manage_content', 'privileges:manage_topic'], uid, next); | ||||
| 			}, | ||||
| 			isAdministrator: function(next) { | ||||
| 			isAdmin: function(next){ | ||||
| 				user.isAdministrator(uid, next); | ||||
| 			}, | ||||
| 		}, function(err, userResults) { | ||||
| 			if(err) { | ||||
| 			isModerator: function(next) { | ||||
| 				posts.isModerator(pids, uid, next); | ||||
| 			}, | ||||
| 			isOwner: function(next) { | ||||
| 				posts.isOwner(pids, uid, next); | ||||
| 			} | ||||
| 		}, function(err, results) { | ||||
| 			if (err) { | ||||
| 				return callback(err); | ||||
| 			} | ||||
|  | ||||
| 			var userPriv = userResults.isAdministrator || userResults.manage; | ||||
| 			var privileges = []; | ||||
|  | ||||
| 			async.parallel({ | ||||
| 				isOwner: function(next) { | ||||
| 					posts.isOwner(pids, uid, next); | ||||
| 				}, | ||||
| 				isModerator: function(next) { | ||||
| 					posts.isModerator(pids, uid, next); | ||||
| 				} | ||||
| 			}, function(err, postResults) { | ||||
| 				if (err) { | ||||
| 					return callback(err); | ||||
| 				} | ||||
| 			for (var i=0; i<pids.length; ++i) { | ||||
| 				var editable = results.isAdmin || results.isModerator[i] || results.isOwner[i]; | ||||
| 				privileges.push({ | ||||
| 					editable: editable, | ||||
| 					view_deleted: editable, | ||||
| 					move: results.isAdmin || results.isModerator[i] | ||||
| 				}); | ||||
| 			} | ||||
|  | ||||
| 				var privileges = []; | ||||
|  | ||||
| 				for (var i=0; i<pids.length; ++i) { | ||||
| 					var editable = userPriv || postResults.isModerator[i] || postResults.isOwner[i]; | ||||
| 					privileges.push({ | ||||
| 						editable: editable, | ||||
| 						view_deleted: editable, | ||||
| 						move: userResults.isAdministrator || postResults.isModerator[i] | ||||
| 					}); | ||||
| 				} | ||||
|  | ||||
| 				callback(null, privileges); | ||||
| 			}); | ||||
| 			callback(null, privileges); | ||||
| 		}); | ||||
| 	}; | ||||
|  | ||||
| @@ -154,16 +143,11 @@ module.exports = function(privileges) { | ||||
| 				if (isLocked) { | ||||
| 					return callback(null, {isLocked: true}); | ||||
| 				} | ||||
| 				helpers.some([ | ||||
| 					function(next) { | ||||
| 						posts.isOwner(pid, uid, next); | ||||
| 					}, | ||||
| 					function(next) { | ||||
| 						helpers.hasEnoughReputationFor(['privileges:manage_content', 'privileges:manage_topic'], uid, next); | ||||
| 					} | ||||
| 				], function(err, editable) { | ||||
| 					next(err, {editable: editable}); | ||||
| 				}); | ||||
|  | ||||
| 				posts.isOwner(pid, uid, next); | ||||
| 			}, | ||||
| 			function(isOwner, next) { | ||||
| 				next(null, {editable: isOwner}); | ||||
| 			} | ||||
| 		], callback); | ||||
| 	} | ||||
|   | ||||
| @@ -25,7 +25,6 @@ module.exports = function(privileges) { | ||||
| 					isOwner: function(next) { | ||||
| 						next(null, parseInt(uid, 10) === parseInt(topic.uid, 10)); | ||||
| 					}, | ||||
| 					manage_topic: async.apply(helpers.hasEnoughReputationFor, 'privileges:manage_topic', uid), | ||||
| 					isAdministrator: async.apply(user.isAdministrator, uid), | ||||
| 					isModerator: async.apply(user.isModerator, uid, topic.cid), | ||||
| 					disabled: async.apply(categories.getCategoryField, topic.cid, 'disabled') | ||||
| @@ -38,7 +37,7 @@ module.exports = function(privileges) { | ||||
|  | ||||
| 			var disabled = parseInt(results.disabled, 10) === 1; | ||||
| 			var	isAdminOrMod = results.isAdministrator || results.isModerator; | ||||
| 			var editable = isAdminOrMod || results.manage_topic; | ||||
| 			var editable = isAdminOrMod; | ||||
| 			var deletable = isAdminOrMod || results.isOwner; | ||||
|  | ||||
| 			plugins.fireHook('filter:privileges.topics.get', { | ||||
| @@ -47,7 +46,7 @@ module.exports = function(privileges) { | ||||
| 				view_thread_tools: editable || deletable, | ||||
| 				editable: editable, | ||||
| 				deletable: deletable, | ||||
| 				view_deleted: isAdminOrMod || results.manage_topic || results.isOwner, | ||||
| 				view_deleted: isAdminOrMod || results.isOwner, | ||||
| 				disabled: disabled, | ||||
| 				tid: tid, | ||||
| 				uid: uid | ||||
| @@ -106,9 +105,6 @@ module.exports = function(privileges) { | ||||
| 			function(next) { | ||||
| 				topics.isOwner(tid, uid, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				helpers.hasEnoughReputationFor('privileges:manage_topic', uid, next); | ||||
| 			}, | ||||
| 			function(next) { | ||||
| 				isAdminOrMod(tid, uid, next); | ||||
| 			} | ||||
|   | ||||
| @@ -19,24 +19,6 @@ | ||||
| </div> | ||||
|  | ||||
|  | ||||
| <div class="panel panel-default"> | ||||
| 	<div class="panel-heading">Privilege Thresholds</div> | ||||
| 	<div class="panel-body"> | ||||
| 		<form> | ||||
| 			<p class="help-block"> | ||||
| 				Use privilege thresholds to manage how much reputation a user must gain to receive moderator access. | ||||
| 			</p> | ||||
| 			<strong>Manage Thread</strong><br /> <input type="text" class="form-control" value="1000" data-field="privileges:manage_topic"><br /> | ||||
| 			<strong>Manage Content</strong><br /> <input type="text" class="form-control" value="1000" data-field="privileges:manage_content"><br /> | ||||
| 			<div class="checkbox"> | ||||
| 				<label> | ||||
| 					<input type="checkbox" data-field="privileges:disabled"> <strong>Disable Privilege Threshold System</strong> | ||||
| 				</label> | ||||
| 			</div> | ||||
| 		</form> | ||||
| 	</div> | ||||
| </div> | ||||
|  | ||||
| <div class="panel panel-default"> | ||||
| 	<div class="panel-heading">Activity Thresholds</div> | ||||
| 	<div class="panel-body"> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user