You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/socket.io/admin/categories.js

107 lines
3.0 KiB
JavaScript

8 years ago
'use strict';
9 years ago
var async = require('async');
9 years ago
var db = require('../../database');
var groups = require('../../groups');
var categories = require('../../categories');
var privileges = require('../../privileges');
var plugins = require('../../plugins');
var Categories = {};
Categories.create = function (socket, data, callback) {
9 years ago
if (!data) {
return callback(new Error('[[error:invalid-data]]'));
}
categories.create(data, callback);
};
Categories.getAll = function (socket, data, callback) {
10 years ago
async.waterfall([
async.apply(db.getSortedSetRange, 'categories:cid', 0, -1),
10 years ago
async.apply(categories.getCategoriesData),
function (categories, next) {
// Hook changes, there is no req, and res
plugins.fireHook('filter:admin.categories.get', { categories: categories }, next);
10 years ago
},
function (result, next) {
10 years ago
next(null, categories.getTree(result.categories, 0));
},
], function (err, categoriesTree) {
10 years ago
if (err) {
return callback(err);
}
callback(null, categoriesTree);
});
};
Categories.getNames = function (socket, data, callback) {
10 years ago
categories.getAllCategoryFields(['cid', 'name'], callback);
};
Categories.purge = function (socket, cid, callback) {
9 years ago
categories.purge(cid, socket.uid, callback);
};
Categories.update = function (socket, data, callback) {
9 years ago
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]]'));
}
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);
}
};
Categories.getPrivilegeSettings = function (socket, cid, callback) {
privileges.categories.list(cid, callback);
};
Categories.copyPrivilegesToChildren = function (socket, cid, callback) {
categories.getCategories([cid], socket.uid, function (err, categories) {
if (err) {
return callback(err);
}
9 years ago
var category = categories[0];
async.eachSeries(category.children, function (child, next) {
9 years ago
copyPrivilegesToChildrenRecursive(cid, child, next);
}, callback);
});
};
9 years ago
function copyPrivilegesToChildrenRecursive(parentCid, category, callback) {
categories.copyPrivilegesFrom(parentCid, category.cid, function (err) {
if (err) {
return callback(err);
}
async.eachSeries(category.children, function (child, next) {
9 years ago
copyPrivilegesToChildrenRecursive(parentCid, child, next);
}, callback);
});
}
Categories.copySettingsFrom = function (socket, data, callback) {
9 years ago
categories.copySettingsFrom(data.fromCid, data.toCid, true, callback);
9 years ago
};
Categories.copyPrivilegesFrom = function (socket, data, callback) {
9 years ago
categories.copyPrivilegesFrom(data.fromCid, data.toCid, callback);
};
8 years ago
module.exports = Categories;