mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-30 18:46:01 +01:00 
			
		
		
		
	closes #2904
This commit is contained in:
		| @@ -83,30 +83,5 @@ function isGuestAllowedTo(privilege, cids, callback) { | |||||||
| 	groups.isMemberOfGroups('guests', groupKeys, 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; | module.exports = helpers; | ||||||
| @@ -21,45 +21,34 @@ module.exports = function(privileges) { | |||||||
| 		if (!Array.isArray(pids) || !pids.length) { | 		if (!Array.isArray(pids) || !pids.length) { | ||||||
| 			return callback(null, []); | 			return callback(null, []); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		async.parallel({ | 		async.parallel({ | ||||||
| 			manage: function(next) { | 			isAdmin: function(next){ | ||||||
| 				helpers.hasEnoughReputationFor(['privileges:manage_content', 'privileges:manage_topic'], uid, next); |  | ||||||
| 			}, |  | ||||||
| 			isAdministrator: function(next) { |  | ||||||
| 				user.isAdministrator(uid, next); | 				user.isAdministrator(uid, next); | ||||||
| 			}, | 			}, | ||||||
| 		}, function(err, userResults) { | 			isModerator: function(next) { | ||||||
| 			if(err) { | 				posts.isModerator(pids, uid, next); | ||||||
|  | 			}, | ||||||
|  | 			isOwner: function(next) { | ||||||
|  | 				posts.isOwner(pids, uid, next); | ||||||
|  | 			} | ||||||
|  | 		}, function(err, results) { | ||||||
|  | 			if (err) { | ||||||
| 				return callback(err); | 				return callback(err); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			var userPriv = userResults.isAdministrator || userResults.manage; | 			var privileges = []; | ||||||
|  |  | ||||||
| 			async.parallel({ | 			for (var i=0; i<pids.length; ++i) { | ||||||
| 				isOwner: function(next) { | 				var editable = results.isAdmin || results.isModerator[i] || results.isOwner[i]; | ||||||
| 					posts.isOwner(pids, uid, next); | 				privileges.push({ | ||||||
| 				}, | 					editable: editable, | ||||||
| 				isModerator: function(next) { | 					view_deleted: editable, | ||||||
| 					posts.isModerator(pids, uid, next); | 					move: results.isAdmin || results.isModerator[i] | ||||||
| 				} | 				}); | ||||||
| 			}, function(err, postResults) { | 			} | ||||||
| 				if (err) { |  | ||||||
| 					return callback(err); |  | ||||||
| 				} |  | ||||||
|  |  | ||||||
| 				var privileges = []; | 			callback(null, 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); |  | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| @@ -126,7 +115,7 @@ module.exports = function(privileges) { | |||||||
| 				return callback(new Error('[[error:post-edit-duration-expired, ' + meta.config.postEditDuration + ']]')); | 				return callback(new Error('[[error:post-edit-duration-expired, ' + meta.config.postEditDuration + ']]')); | ||||||
| 			} | 			} | ||||||
| 			callback(null, results.isEditable.editable); | 			callback(null, results.isEditable.editable); | ||||||
| 		});		 | 		}); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	privileges.posts.canMove = function(pid, uid, callback) { | 	privileges.posts.canMove = function(pid, uid, callback) { | ||||||
| @@ -154,16 +143,11 @@ module.exports = function(privileges) { | |||||||
| 				if (isLocked) { | 				if (isLocked) { | ||||||
| 					return callback(null, {isLocked: true}); | 					return callback(null, {isLocked: true}); | ||||||
| 				} | 				} | ||||||
| 				helpers.some([ |  | ||||||
| 					function(next) { | 				posts.isOwner(pid, uid, next); | ||||||
| 						posts.isOwner(pid, uid, next); | 			}, | ||||||
| 					}, | 			function(isOwner, next) { | ||||||
| 					function(next) { | 				next(null, {editable: isOwner}); | ||||||
| 						helpers.hasEnoughReputationFor(['privileges:manage_content', 'privileges:manage_topic'], uid, next); |  | ||||||
| 					} |  | ||||||
| 				], function(err, editable) { |  | ||||||
| 					next(err, {editable: editable}); |  | ||||||
| 				}); |  | ||||||
| 			} | 			} | ||||||
| 		], callback); | 		], callback); | ||||||
| 	} | 	} | ||||||
| @@ -184,7 +168,7 @@ module.exports = function(privileges) { | |||||||
| 					if (err || !cid) { | 					if (err || !cid) { | ||||||
| 						return next(err, false); | 						return next(err, false); | ||||||
| 					} | 					} | ||||||
| 					 |  | ||||||
| 					user.isModerator(uid, cid, next); | 					user.isModerator(uid, cid, next); | ||||||
| 				}); | 				}); | ||||||
| 			}, | 			}, | ||||||
|   | |||||||
| @@ -25,7 +25,6 @@ module.exports = function(privileges) { | |||||||
| 					isOwner: function(next) { | 					isOwner: function(next) { | ||||||
| 						next(null, parseInt(uid, 10) === parseInt(topic.uid, 10)); | 						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), | 					isAdministrator: async.apply(user.isAdministrator, uid), | ||||||
| 					isModerator: async.apply(user.isModerator, uid, topic.cid), | 					isModerator: async.apply(user.isModerator, uid, topic.cid), | ||||||
| 					disabled: async.apply(categories.getCategoryField, topic.cid, 'disabled') | 					disabled: async.apply(categories.getCategoryField, topic.cid, 'disabled') | ||||||
| @@ -38,7 +37,7 @@ module.exports = function(privileges) { | |||||||
|  |  | ||||||
| 			var disabled = parseInt(results.disabled, 10) === 1; | 			var disabled = parseInt(results.disabled, 10) === 1; | ||||||
| 			var	isAdminOrMod = results.isAdministrator || results.isModerator; | 			var	isAdminOrMod = results.isAdministrator || results.isModerator; | ||||||
| 			var editable = isAdminOrMod || results.manage_topic; | 			var editable = isAdminOrMod; | ||||||
| 			var deletable = isAdminOrMod || results.isOwner; | 			var deletable = isAdminOrMod || results.isOwner; | ||||||
|  |  | ||||||
| 			plugins.fireHook('filter:privileges.topics.get', { | 			plugins.fireHook('filter:privileges.topics.get', { | ||||||
| @@ -47,7 +46,7 @@ module.exports = function(privileges) { | |||||||
| 				view_thread_tools: editable || deletable, | 				view_thread_tools: editable || deletable, | ||||||
| 				editable: editable, | 				editable: editable, | ||||||
| 				deletable: deletable, | 				deletable: deletable, | ||||||
| 				view_deleted: isAdminOrMod || results.manage_topic || results.isOwner, | 				view_deleted: isAdminOrMod || results.isOwner, | ||||||
| 				disabled: disabled, | 				disabled: disabled, | ||||||
| 				tid: tid, | 				tid: tid, | ||||||
| 				uid: uid | 				uid: uid | ||||||
| @@ -106,9 +105,6 @@ module.exports = function(privileges) { | |||||||
| 			function(next) { | 			function(next) { | ||||||
| 				topics.isOwner(tid, uid, next); | 				topics.isOwner(tid, uid, next); | ||||||
| 			}, | 			}, | ||||||
| 			function(next) { |  | ||||||
| 				helpers.hasEnoughReputationFor('privileges:manage_topic', uid, next); |  | ||||||
| 			}, |  | ||||||
| 			function(next) { | 			function(next) { | ||||||
| 				isAdminOrMod(tid, uid, next); | 				isAdminOrMod(tid, uid, next); | ||||||
| 			} | 			} | ||||||
|   | |||||||
| @@ -19,24 +19,6 @@ | |||||||
| </div> | </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 panel-default"> | ||||||
| 	<div class="panel-heading">Activity Thresholds</div> | 	<div class="panel-heading">Activity Thresholds</div> | ||||||
| 	<div class="panel-body"> | 	<div class="panel-body"> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user