| 
									
										
										
										
											2014-04-15 02:27:58 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-10 17:48:48 -04:00
										 |  |  | var async = require('async'), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-30 18:44:31 +03:00
										 |  |  | 	db = require('../../database'), | 
					
						
							| 
									
										
										
										
											2014-06-10 17:48:48 -04:00
										 |  |  | 	groups = require('../../groups'), | 
					
						
							| 
									
										
										
										
											2014-04-15 02:27:58 -04:00
										 |  |  | 	user = require('../../user'), | 
					
						
							|  |  |  | 	categories = require('../../categories'), | 
					
						
							| 
									
										
										
										
											2014-05-15 20:49:47 -04:00
										 |  |  | 	privileges = require('../../privileges'), | 
					
						
							| 
									
										
										
										
											2015-05-30 18:44:31 +03:00
										 |  |  | 	plugins = require('../../plugins'), | 
					
						
							| 
									
										
										
										
											2014-04-15 02:27:58 -04:00
										 |  |  | 	Categories = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.create = function(socket, data, callback) { | 
					
						
							|  |  |  | 	if(!data) { | 
					
						
							|  |  |  | 		return callback(new Error('[[error:invalid-data]]')); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	categories.create(data, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-30 18:44:31 +03:00
										 |  |  | Categories.getAll = function(socket, data, callback) { | 
					
						
							|  |  |  | 	async.waterfall([ | 
					
						
							| 
									
										
										
										
											2015-08-18 14:17:16 -04:00
										 |  |  | 		async.apply(db.getSortedSetRange, 'categories:cid', 0, -1), | 
					
						
							| 
									
										
										
										
											2015-05-30 18:44:31 +03:00
										 |  |  | 		async.apply(categories.getCategoriesData), | 
					
						
							|  |  |  | 		function(categories, next) { | 
					
						
							|  |  |  | 			//Hook changes, there is no req, and res
 | 
					
						
							|  |  |  | 			plugins.fireHook('filter:admin.categories.get', {categories: categories}, next); | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function(result, next){ | 
					
						
							|  |  |  | 			next(null, categories.getTree(result.categories, 0)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	], function(err, categoriesTree) { | 
					
						
							|  |  |  | 		if (err) { | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		callback(null, categoriesTree); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-17 18:19:51 -04:00
										 |  |  | Categories.getNames = function(socket, data, callback) { | 
					
						
							|  |  |  | 	categories.getAllCategoryFields(['cid', 'name'], callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-10 17:48:48 -04:00
										 |  |  | Categories.purge = function(socket, cid, callback) { | 
					
						
							|  |  |  | 	categories.purge(cid, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-15 02:27:58 -04:00
										 |  |  | Categories.update = function(socket, data, callback) { | 
					
						
							|  |  |  | 	if(!data) { | 
					
						
							|  |  |  | 		return callback(new Error('[[error:invalid-data]]')); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	categories.update(data, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.setPrivilege = function(socket, data, callback) { | 
					
						
							|  |  |  | 	if(!data) { | 
					
						
							|  |  |  | 		return callback(new Error('[[error:invalid-data]]')); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-26 11:52:34 -04:00
										 |  |  | 	if (Array.isArray(data.privilege)) { | 
					
						
							|  |  |  | 		async.each(data.privilege, function(privilege, next) { | 
					
						
							|  |  |  | 			groups[data.set ? 'join' : 'leave']('cid:' + data.cid + ':privileges:' + privilege, data.member, next); | 
					
						
							|  |  |  | 		}, callback); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		groups[data.set ? 'join' : 'leave']('cid:' + data.cid + ':privileges:' + data.privilege, data.member, callback); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-04-15 02:27:58 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Categories.getPrivilegeSettings = function(socket, cid, callback) { | 
					
						
							| 
									
										
										
										
											2015-03-25 15:42:15 -04:00
										 |  |  | 	privileges.categories.list(cid, callback); | 
					
						
							| 
									
										
										
										
											2014-04-15 02:27:58 -04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = Categories; |