Node.js based forum software built for the modern web
closes #3917, closes #2941
barisusakli1ad4128649b9
diff --git a/public/src/admin/manage/category.js b/public/src/admin/manage/category.jsindex 0337064ad3..ca3d9982c6 100644--- a/public/src/admin/manage/category.js+++ b/public/src/admin/manage/category.js@@ -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;});\ No newline at end of filediff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.jsindex e1e72c5ec8..a3d929e5c2 100644--- a/src/socket.io/admin/categories.js+++ b/src/socket.io/admin/categories.js@@ -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;\ No newline at end of filediff --git a/src/views/admin/partials/categories/privileges.tpl b/src/views/admin/partials/categories/privileges.tplindex 74c29bfeba..b5605c0935 100644--- a/src/views/admin/partials/categories/privileges.tpl+++ b/src/views/admin/partials/categories/privileges.tpl@@ -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}">- <button type="button" class="btn btn-primary pull-right" data-ajaxify="false" data-action="search.group"> Add Group</button>+ <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