mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 00:45:47 +01:00
@@ -176,6 +176,7 @@ define('admin/manage/category', [
|
||||
|
||||
$('.privilege-table-container').on('click', '[data-action="search.user"]', Category.addUserToPrivilegeTable);
|
||||
$('.privilege-table-container').on('click', '[data-action="search.group"]', Category.addGroupToPrivilegeTable);
|
||||
$('.privilege-table-container').on('click', '[data-action="copyToChildren"]', Category.copyPrivilegesToChildren);
|
||||
|
||||
Category.exposeAssumedPrivileges();
|
||||
};
|
||||
@@ -335,5 +336,14 @@ define('admin/manage/category', [
|
||||
});
|
||||
};
|
||||
|
||||
Category.copyPrivilegesToChildren = function() {
|
||||
socket.emit('admin.categories.copyPrivilegesToChildren', ajaxify.data.category.cid, function(err) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
app.alertSuccess('Privileges copied!');
|
||||
});
|
||||
};
|
||||
|
||||
return Category;
|
||||
});
|
||||
@@ -4,7 +4,6 @@ var async = require('async'),
|
||||
|
||||
db = require('../../database'),
|
||||
groups = require('../../groups'),
|
||||
user = require('../../user'),
|
||||
categories = require('../../categories'),
|
||||
privileges = require('../../privileges'),
|
||||
plugins = require('../../plugins'),
|
||||
@@ -72,4 +71,41 @@ Categories.getPrivilegeSettings = function(socket, cid, callback) {
|
||||
privileges.categories.list(cid, callback);
|
||||
};
|
||||
|
||||
Categories.copyPrivilegesToChildren = function(socket, cid, callback) {
|
||||
async.parallel({
|
||||
category: function(next) {
|
||||
categories.getCategories([cid], socket.uid, next);
|
||||
},
|
||||
privileges: function(next) {
|
||||
privileges.categories.list(cid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var category = results.category[0];
|
||||
|
||||
async.eachSeries(category.children, function(child, next) {
|
||||
copyPrivilegesToChildrenRecursive(child, results.privileges.groups, next);
|
||||
}, callback);
|
||||
});
|
||||
};
|
||||
|
||||
function copyPrivilegesToChildrenRecursive(category, privilegeGroups, callback) {
|
||||
async.eachSeries(privilegeGroups, function(privGroup, next) {
|
||||
var privs = Object.keys(privGroup.privileges);
|
||||
async.each(privs, function(privilege, next) {
|
||||
var isSet = privGroup.privileges[privilege];
|
||||
groups[isSet ? 'join' : 'leave']('cid:' + category.cid + ':privileges:' + privilege, privGroup.name, next);
|
||||
}, next);
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
async.eachSeries(category.children, function(child, next) {
|
||||
copyPrivilegesToChildrenRecursive(child, privilegeGroups, next);
|
||||
}, callback);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = Categories;
|
||||
@@ -41,7 +41,6 @@
|
||||
<th class="text-center">{privileges.labels.groups.name}</th>
|
||||
<!-- END privileges.labels.groups -->
|
||||
</tr>
|
||||
<!-- IF privileges.groups.length -->
|
||||
<!-- BEGIN privileges.groups -->
|
||||
<tr data-group-name="{privileges.groups.name}" data-private="<!-- IF privileges.groups.isPrivate -->1<!-- ELSE -->0<!-- ENDIF privileges.groups.isPrivate -->">
|
||||
<td>
|
||||
@@ -56,17 +55,12 @@
|
||||
<!-- END privileges.groups -->
|
||||
<tr>
|
||||
<td colspan="{privileges.columnCount}">
|
||||
<div class="btn-toolbar">
|
||||
<button type="button" class="btn btn-primary pull-right" data-ajaxify="false" data-action="search.group"> Add Group</button>
|
||||
<button type="button" class="btn btn-info pull-right" data-ajaxify="false" data-action="copyToChildren"> Copy to Children</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- ELSE -->
|
||||
<tr>
|
||||
<td colspan="{privileges.columnCount}">
|
||||
<button type="button" class="btn btn-primary pull-right" data-ajaxify="false" data-action="search.group"> Add Group</button>
|
||||
No group-specific privileges in this category.
|
||||
</td>
|
||||
</tr>
|
||||
<!-- ENDIF privileges.groups.length -->
|
||||
</table>
|
||||
<div class="help-block">
|
||||
If the <code>registered-users</code> group is granted a specific privilege, all other groups receive an
|
||||
|
||||
Reference in New Issue
Block a user