| 
									
										
										
										
											2014-05-14 17:53:23 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 18:00:55 +02:00
										 |  |  | var async = require('async'); | 
					
						
							| 
									
										
										
										
											2017-06-25 20:00:05 -04:00
										 |  |  | var _ = require('lodash'); | 
					
						
							| 
									
										
										
										
											2016-01-20 18:00:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-27 12:58:08 +03:00
										 |  |  | var meta = require('../meta'); | 
					
						
							|  |  |  | var posts = require('../posts'); | 
					
						
							|  |  |  | var topics = require('../topics'); | 
					
						
							|  |  |  | var user = require('../user'); | 
					
						
							| 
									
										
										
										
											2016-01-20 18:00:55 +02:00
										 |  |  | var helpers = require('./helpers'); | 
					
						
							| 
									
										
										
										
											2016-08-27 12:58:08 +03:00
										 |  |  | var plugins = require('../plugins'); | 
					
						
							| 
									
										
										
										
											2014-05-14 17:53:23 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | module.exports = function (privileges) { | 
					
						
							| 
									
										
										
										
											2014-05-14 17:53:23 -04:00
										 |  |  | 	privileges.posts = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	privileges.posts.get = function (pids, uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-10-02 19:03:03 -04:00
										 |  |  | 		if (!Array.isArray(pids) || !pids.length) { | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 			return setImmediate(callback, null, []); | 
					
						
							| 
									
										
										
										
											2014-10-02 19:03:03 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 		let uniqueCids; | 
					
						
							|  |  |  | 		let cids; | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 		async.waterfall([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 				posts.getCidsByPids(pids, next); | 
					
						
							| 
									
										
										
										
											2015-03-30 13:31:08 -04:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 			function (_cids, next) { | 
					
						
							|  |  |  | 				cids = _cids; | 
					
						
							|  |  |  | 				uniqueCids = _.uniq(cids); | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 				async.parallel({ | 
					
						
							|  |  |  | 					isAdmin: async.apply(user.isAdministrator, uid), | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 					isModerator: async.apply(user.isModerator, uid, uniqueCids), | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 					isOwner: async.apply(posts.isOwner, pids, uid), | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 					'topics:read': async.apply(helpers.isUserAllowedTo, 'topics:read', uid, uniqueCids), | 
					
						
							|  |  |  | 					read: async.apply(helpers.isUserAllowedTo, 'read', uid, uniqueCids), | 
					
						
							|  |  |  | 					'posts:edit': async.apply(helpers.isUserAllowedTo, 'posts:edit', uid, uniqueCids), | 
					
						
							|  |  |  | 					'posts:history': async.apply(helpers.isUserAllowedTo, 'posts:history', uid, uniqueCids), | 
					
						
							|  |  |  | 					'posts:view_deleted': async.apply(helpers.isUserAllowedTo, 'posts:view_deleted', uid, uniqueCids), | 
					
						
							| 
									
										
										
										
											2016-07-01 13:01:09 +03:00
										 |  |  | 				}, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 			function (results, next) { | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 				const isModerator = _.zipObject(uniqueCids, results.isModerator); | 
					
						
							|  |  |  | 				const privData = {}; | 
					
						
							|  |  |  | 				privData['topics:read'] = _.zipObject(uniqueCids, results['topics:read']); | 
					
						
							|  |  |  | 				privData.read = _.zipObject(uniqueCids, results.read); | 
					
						
							|  |  |  | 				privData['posts:edit'] = _.zipObject(uniqueCids, results['posts:edit']); | 
					
						
							|  |  |  | 				privData['posts:history'] = _.zipObject(uniqueCids, results['posts:history']); | 
					
						
							|  |  |  | 				privData['posts:view_deleted'] = _.zipObject(uniqueCids, results['posts:view_deleted']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				var privileges = cids.map(function (cid, i) { | 
					
						
							|  |  |  | 					var isAdminOrMod = results.isAdmin || isModerator[cid]; | 
					
						
							|  |  |  | 					var editable = (privData['posts:edit'][cid] && (results.isOwner[i] || results.isModerator)) || results.isAdmin; | 
					
						
							|  |  |  | 					var viewDeletedPosts = results.isOwner[i] || privData['posts:view_deleted'][cid] || results.isAdmin; | 
					
						
							|  |  |  | 					var viewHistory = results.isOwner[i] || privData['posts:history'][cid] || results.isAdmin; | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					return { | 
					
						
							|  |  |  | 						editable: editable, | 
					
						
							|  |  |  | 						move: isAdminOrMod, | 
					
						
							|  |  |  | 						isAdminOrMod: isAdminOrMod, | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 						'topics:read': privData['topics:read'][cid] || results.isAdmin, | 
					
						
							|  |  |  | 						read: privData.read[cid] || results.isAdmin, | 
					
						
							| 
									
										
										
										
											2018-06-11 16:45:19 -04:00
										 |  |  | 						'posts:history': viewHistory, | 
					
						
							| 
									
										
										
										
											2018-06-08 16:01:11 -04:00
										 |  |  | 						'posts:view_deleted': viewDeletedPosts, | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 					}; | 
					
						
							| 
									
										
										
										
											2015-03-30 13:31:08 -04:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-05-14 17:53:23 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 				next(null, privileges); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2014-05-14 17:53:23 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	privileges.posts.can = function (privilege, pid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				posts.getCidByPid(pid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (cid, next) { | 
					
						
							|  |  |  | 				privileges.categories.can(privilege, cid, uid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2014-05-14 17:53:23 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	privileges.posts.filter = function (privilege, pids, uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-11-09 01:30:27 -05:00
										 |  |  | 		if (!Array.isArray(pids) || !pids.length) { | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 			return setImmediate(callback, null, []); | 
					
						
							| 
									
										
										
										
											2014-07-31 17:29:20 -04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 		var cids; | 
					
						
							|  |  |  | 		var postData; | 
					
						
							|  |  |  | 		var tids; | 
					
						
							|  |  |  | 		var tidToTopic = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-25 20:00:05 -04:00
										 |  |  | 		pids = _.uniq(pids); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				posts.getPostsFields(pids, ['uid', 'tid', 'deleted'], next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (_posts, next) { | 
					
						
							|  |  |  | 				postData = _posts; | 
					
						
							| 
									
										
										
										
											2018-10-20 14:40:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				tids = _.uniq(_posts.map(post => post && post.tid).filter(Boolean)); | 
					
						
							| 
									
										
										
										
											2017-06-25 20:00:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 				topics.getTopicsFields(tids, ['deleted', 'cid'], next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (topicData, next) { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				topicData.forEach(function (topic, index) { | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 					if (topic) { | 
					
						
							|  |  |  | 						tidToTopic[tids[index]] = topic; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				cids = postData.map(function (post, index) { | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 					if (post) { | 
					
						
							|  |  |  | 						post.pid = pids[index]; | 
					
						
							|  |  |  | 						post.topic = tidToTopic[post.tid]; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					return tidToTopic[post.tid] && tidToTopic[post.tid].cid; | 
					
						
							| 
									
										
										
										
											2018-10-20 14:40:48 -04:00
										 |  |  | 				}).filter(cid => parseInt(cid, 10)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				cids = _.uniq(cids); | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 				privileges.categories.getBase(privilege, cids, uid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (results, next) { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				cids = cids.filter(function (cid, index) { | 
					
						
							| 
									
										
										
										
											2018-11-28 20:29:43 -07:00
										 |  |  | 					return !results.categories[index].disabled && | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 						(results.allowedTo[index] || results.isAdmin); | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-20 14:40:48 -04:00
										 |  |  | 				const cidsSet = new Set(cids); | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				pids = postData.filter(function (post) { | 
					
						
							| 
									
										
										
										
											2018-11-28 20:29:43 -07:00
										 |  |  | 					return post.topic && cidsSet.has(post.topic.cid) && | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 						((!post.topic.deleted && !post.deleted) || results.isAdmin); | 
					
						
							| 
									
										
										
										
											2018-10-20 14:40:48 -04:00
										 |  |  | 				}).map(post => post.pid); | 
					
						
							| 
									
										
										
										
											2014-11-14 17:31:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				plugins.fireHook('filter:privileges.posts.filter', { | 
					
						
							|  |  |  | 					privilege: privilege, | 
					
						
							|  |  |  | 					uid: uid, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					pids: pids, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 					next(err, data ? data.pids : null); | 
					
						
							| 
									
										
										
										
											2014-11-14 17:31:39 -05:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-04-29 20:35:49 +03:00
										 |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2014-07-29 21:51:46 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	privileges.posts.canEdit = function (pid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 		let results; | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				async.parallel({ | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 					isAdmin: async.apply(privileges.users.isAdministrator, uid), | 
					
						
							|  |  |  | 					isMod: async.apply(posts.isModerator, [pid], uid), | 
					
						
							|  |  |  | 					owner: async.apply(posts.isOwner, pid, uid), | 
					
						
							|  |  |  | 					edit: async.apply(privileges.posts.can, 'posts:edit', pid, uid), | 
					
						
							|  |  |  | 					postData: async.apply(posts.getPostFields, pid, ['tid', 'timestamp']), | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 				}, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 			function (_results, next) { | 
					
						
							|  |  |  | 				results = _results; | 
					
						
							|  |  |  | 				results.isMod = results.isMod[0]; | 
					
						
							|  |  |  | 				if (results.isAdmin) { | 
					
						
							|  |  |  | 					return callback(null, { flag: true }); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (!results.isMod && meta.config.postEditDuration && (Date.now() - results.postData.timestamp > meta.config.postEditDuration * 1000)) { | 
					
						
							|  |  |  | 					return callback(null, { flag: false, message: '[[error:post-edit-duration-expired, ' + meta.config.postEditDuration + ']]' }); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				topics.isLocked(results.postData.tid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (isLocked, next) { | 
					
						
							|  |  |  | 				if (!results.isMod && isLocked) { | 
					
						
							|  |  |  | 					return callback(null, { flag: false, message: '[[error:topic-locked]]' }); | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-08-10 23:55:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 				results.pid = parseInt(pid, 10); | 
					
						
							|  |  |  | 				results.uid = uid; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				plugins.fireHook('filter:privileges.posts.edit', results, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (result, next) { | 
					
						
							|  |  |  | 				next(null, { flag: result.edit && (result.owner || result.isMod), message: '[[error:no-privileges]]' }); | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 			}, | 
					
						
							|  |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2014-05-15 10:38:02 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	privileges.posts.canDelete = function (pid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2016-06-28 12:34:09 +03:00
										 |  |  | 		var postData; | 
					
						
							|  |  |  | 		async.waterfall([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2016-10-31 22:39:58 +03:00
										 |  |  | 				posts.getPostFields(pid, ['uid', 'tid', 'timestamp', 'deleterUid'], next); | 
					
						
							| 
									
										
										
										
											2016-06-28 12:34:09 +03:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (_postData, next) { | 
					
						
							| 
									
										
										
										
											2016-06-28 12:34:09 +03:00
										 |  |  | 				postData = _postData; | 
					
						
							|  |  |  | 				async.parallel({ | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 					isAdmin: async.apply(privileges.users.isAdministrator, uid), | 
					
						
							|  |  |  | 					isMod: async.apply(posts.isModerator, [pid], uid), | 
					
						
							| 
									
										
										
										
											2016-06-28 12:34:09 +03:00
										 |  |  | 					isLocked: async.apply(topics.isLocked, postData.tid), | 
					
						
							| 
									
										
										
										
											2016-08-06 20:28:55 -05:00
										 |  |  | 					isOwner: async.apply(posts.isOwner, pid, uid), | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 					'posts:delete': async.apply(privileges.posts.can, 'posts:delete', pid, uid), | 
					
						
							| 
									
										
										
										
											2016-06-28 12:34:09 +03:00
										 |  |  | 				}, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 			function (results, next) { | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 				results.isMod = results.isMod[0]; | 
					
						
							|  |  |  | 				if (results.isAdmin) { | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 					return next(null, { flag: true }); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-08-10 23:55:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 				if (!results.isMod && results.isLocked) { | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 					return next(null, { flag: false, message: '[[error:topic-locked]]' }); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-08-10 23:55:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-21 16:47:51 -04:00
										 |  |  | 				var postDeleteDuration = meta.config.postDeleteDuration; | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 				if (!results.isMod && postDeleteDuration && (Date.now() - postData.timestamp > postDeleteDuration * 1000)) { | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 					return next(null, { flag: false, message: '[[error:post-delete-duration-expired, ' + meta.config.postDeleteDuration + ']]' }); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-10-21 19:33:46 -04:00
										 |  |  | 				var deleterUid = postData.deleterUid; | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 				var flag = results['posts:delete'] && ((results.isOwner && (deleterUid === 0 || deleterUid === postData.uid)) || results.isMod); | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 				next(null, { flag: flag, message: '[[error:no-privileges]]' }); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2016-06-28 12:34:09 +03:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 20:08:19 -04:00
										 |  |  | 	privileges.posts.canFlag = function (pid, uid, callback) { | 
					
						
							|  |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				async.parallel({ | 
					
						
							|  |  |  | 					userReputation: async.apply(user.getUserField, uid, 'reputation'), | 
					
						
							|  |  |  | 					isAdminOrMod: async.apply(isAdminOrMod, pid, uid), | 
					
						
							|  |  |  | 				}, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (results, next) { | 
					
						
							| 
									
										
										
										
											2018-10-21 16:47:51 -04:00
										 |  |  | 				var minimumReputation = meta.config['min:rep:flag']; | 
					
						
							|  |  |  | 				var canFlag = results.isAdminOrMod || (results.userReputation >= minimumReputation); | 
					
						
							| 
									
										
										
										
											2017-08-18 20:08:19 -04:00
										 |  |  | 				next(null, { flag: canFlag }); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		], callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	privileges.posts.canMove = function (pid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				posts.isMain(pid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (isMain, next) { | 
					
						
							|  |  |  | 				if (isMain) { | 
					
						
							|  |  |  | 					return next(new Error('[[error:cant-move-mainpost]]')); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				isAdminOrMod(pid, uid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2014-06-23 17:26:02 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	privileges.posts.canPurge = function (pid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2015-09-16 08:35:40 -04:00
										 |  |  | 		async.waterfall([ | 
					
						
							|  |  |  | 			function (next) { | 
					
						
							|  |  |  | 				posts.getCidByPid(pid, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (cid, next) { | 
					
						
							|  |  |  | 				async.parallel({ | 
					
						
							|  |  |  | 					purge: async.apply(privileges.categories.isUserAllowedTo, 'purge', cid, uid), | 
					
						
							|  |  |  | 					owner: async.apply(posts.isOwner, pid, uid), | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 					isAdmin: async.apply(privileges.users.isAdministrator, uid), | 
					
						
							|  |  |  | 					isModerator: async.apply(privileges.users.isModerator, uid, cid), | 
					
						
							| 
									
										
										
										
											2015-09-16 08:35:40 -04:00
										 |  |  | 				}, next); | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			function (results, next) { | 
					
						
							| 
									
										
										
										
											2019-05-30 19:30:47 -04:00
										 |  |  | 				next(null, (results.purge && (results.owner || results.isModerator)) || results.isAdmin); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2015-09-16 08:35:40 -04:00
										 |  |  | 		], callback); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-23 17:26:02 -04:00
										 |  |  | 	function isAdminOrMod(pid, uid, callback) { | 
					
						
							| 
									
										
										
										
											2014-05-15 10:38:02 -04:00
										 |  |  | 		helpers.some([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2017-05-25 21:17:20 -04:00
										 |  |  | 				async.waterfall([ | 
					
						
							|  |  |  | 					function (next) { | 
					
						
							|  |  |  | 						posts.getCidByPid(pid, next); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					function (cid, next) { | 
					
						
							|  |  |  | 						user.isModerator(uid, cid, next); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				], next); | 
					
						
							| 
									
										
										
										
											2014-05-15 10:38:02 -04:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2014-05-15 10:38:02 -04:00
										 |  |  | 				user.isAdministrator(uid, next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2014-05-15 10:38:02 -04:00
										 |  |  | 		], callback); | 
					
						
							| 
									
										
										
										
											2014-06-23 17:26:02 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-18 02:30:48 -07:00
										 |  |  | }; |