2014-04-15 02:27:58 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
2014-06-10 17:48:48 -04:00
|
|
|
var async = require('async'),
|
|
|
|
|
|
|
|
|
|
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'),
|
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);
|
|
|
|
|
};
|
|
|
|
|
|
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.search = function(socket, data, callback) {
|
|
|
|
|
if(!data) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var username = data.username,
|
|
|
|
|
cid = data.cid;
|
|
|
|
|
|
2015-01-29 17:02:20 -05:00
|
|
|
user.search({query: username, uid: socket.uid}, function(err, data) {
|
2014-05-15 20:49:47 -04:00
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-15 02:27:58 -04:00
|
|
|
async.map(data.users, function(userObj, next) {
|
2014-05-15 20:49:47 -04:00
|
|
|
privileges.categories.userPrivileges(cid, userObj.uid, function(err, privileges) {
|
2014-04-15 02:27:58 -04:00
|
|
|
if(err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
userObj.privileges = privileges;
|
|
|
|
|
next(null, userObj);
|
|
|
|
|
});
|
|
|
|
|
}, callback);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Categories.setPrivilege = function(socket, data, callback) {
|
|
|
|
|
if(!data) {
|
|
|
|
|
return callback(new Error('[[error:invalid-data]]'));
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-25 15:42:15 -04:00
|
|
|
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;
|