mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-07 00:06:33 +02:00
Copy group privs (#7610)
* feat: ability to copy a groups privileges ability to copy a group's privileges to all categories, or children of current category * feat: switch to dropdown added copy from category to groups * fix: indents
This commit is contained in:
committed by
GitHub
parent
183b0ed3f1
commit
dfab231afd
@@ -208,18 +208,28 @@ module.exports = function (Categories) {
|
||||
], callback);
|
||||
}
|
||||
|
||||
Categories.copyPrivilegesFrom = function (fromCid, toCid, callback) {
|
||||
Categories.copyPrivilegesFrom = function (fromCid, toCid, group, callback) {
|
||||
if (typeof group === 'function') {
|
||||
callback = group;
|
||||
group = '';
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
plugins.fireHook('filter:categories.copyPrivilegesFrom', {
|
||||
privileges: privileges.privilegeList.slice(),
|
||||
fromCid: fromCid,
|
||||
toCid: toCid,
|
||||
group: group,
|
||||
}, next);
|
||||
},
|
||||
function (data, next) {
|
||||
async.each(data.privileges, function (privilege, next) {
|
||||
copyPrivilege(privilege, data.fromCid, data.toCid, next);
|
||||
if (group) {
|
||||
copyPrivilegeByGroup(privilege, data.fromCid, data.toCid, group, next);
|
||||
} else {
|
||||
copyPrivilege(privilege, data.fromCid, data.toCid, next);
|
||||
}
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
@@ -249,4 +259,22 @@ module.exports = function (Categories) {
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
function copyPrivilegeByGroup(privilege, fromCid, toCid, group, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
groups.leave('cid:' + toCid + ':privileges:' + privilege, group, next);
|
||||
},
|
||||
function (next) {
|
||||
db.isSortedSetMember('group:cid:' + fromCid + ':privileges:' + privilege + ':members', group, next);
|
||||
},
|
||||
function (isMember, next) {
|
||||
if (!isMember) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
groups.join('cid:' + toCid + ':privileges:' + privilege, group, next);
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -101,25 +101,25 @@ Categories.getPrivilegeSettings = function (socket, cid, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
Categories.copyPrivilegesToChildren = function (socket, cid, callback) {
|
||||
Categories.copyPrivilegesToChildren = function (socket, data, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.getChildren([cid], socket.uid, next);
|
||||
categories.getChildren([data.cid], socket.uid, next);
|
||||
},
|
||||
function (children, next) {
|
||||
children = children[0];
|
||||
|
||||
async.eachSeries(children, function (child, next) {
|
||||
copyPrivilegesToChildrenRecursive(cid, child, next);
|
||||
copyPrivilegesToChildrenRecursive(data.cid, child, data.group, next);
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
function copyPrivilegesToChildrenRecursive(parentCid, category, callback) {
|
||||
function copyPrivilegesToChildrenRecursive(parentCid, category, group, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.copyPrivilegesFrom(parentCid, category.cid, next);
|
||||
categories.copyPrivilegesFrom(parentCid, category.cid, group, next);
|
||||
},
|
||||
function (next) {
|
||||
async.eachSeries(category.children, function (child, next) {
|
||||
@@ -134,5 +134,19 @@ Categories.copySettingsFrom = function (socket, data, callback) {
|
||||
};
|
||||
|
||||
Categories.copyPrivilegesFrom = function (socket, data, callback) {
|
||||
categories.copyPrivilegesFrom(data.fromCid, data.toCid, callback);
|
||||
categories.copyPrivilegesFrom(data.fromCid, data.toCid, data.group, callback);
|
||||
};
|
||||
|
||||
Categories.copyPrivilegesToAllCategories = function (socket, data, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.getAllCidsFromSet('categories:cid', next);
|
||||
},
|
||||
function (cids, next) {
|
||||
cids = cids.filter(cid => parseInt(cid, 10) !== parseInt(data.cid, 10));
|
||||
async.eachSeries(cids, function (toCid, next) {
|
||||
categories.copyPrivilegesFrom(data.cid, toCid, data.group, next);
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
@@ -94,7 +94,18 @@
|
||||
<!-- ENDIF privileges.groups.isPrivate -->
|
||||
{privileges.groups.name}
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
<i class="fa fa-copy"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
|
||||
<li data-action="copyToAllGroup"><a href="#">[[admin/manage/categories:privileges.copy-group-privileges-to-all-categories]]</a></li>
|
||||
<li data-action="copyToChildrenGroup"><a href="#">[[admin/manage/categories:privileges.copy-group-privileges-to-children]]</a></li>
|
||||
<li data-action="copyPrivilegesFromGroup"><a href="#">[[admin/manage/categories:privileges.copy-group-privileges-from]]</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
{function.spawnPrivilegeStates, privileges.groups.name, ../privileges}
|
||||
</tr>
|
||||
<!-- END privileges.groups -->
|
||||
@@ -104,11 +115,14 @@
|
||||
<button type="button" class="btn btn-primary pull-right" data-ajaxify="false" data-action="search.group">
|
||||
[[admin/manage/categories:privileges.search-group]]
|
||||
</button>
|
||||
<button type="button" class="btn btn-info pull-right" data-ajaxify="false" data-action="copyPrivilegesFrom">
|
||||
[[admin/manage/categories:privileges.copy-from-category]]
|
||||
</button>
|
||||
<button type="button" class="btn btn-info pull-right" data-ajaxify="false" data-action="copyToChildren">
|
||||
[[admin/manage/categories:privileges.copy-to-children]]
|
||||
</button>
|
||||
<button type="button" class="btn btn-info pull-right" data-ajaxify="false" data-action="copyPrivilegesFrom">
|
||||
[[admin/manage/categories:privileges.copy-from-category]]
|
||||
<button type="button" class="btn btn-info pull-right" data-ajaxify="false" data-action="copyToAll">
|
||||
[[admin/manage/categories:privileges.copy-privileges-to-all-categories]]
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user