updating groups access control so:

1. Guests can no longer receive the moderate bit
  2. If you attempt to grant the moderate privilege to a public group, a confirmation modal appears
  3. A lock icon is present next to all private groups
v1.18.x
Julian Lam 10 years ago
parent 89442c91c6
commit c706638b5d

@ -184,24 +184,24 @@ define('admin/manage/category', [
privilege = checkboxEl.parent().attr('data-privilege'), privilege = checkboxEl.parent().attr('data-privilege'),
state = checkboxEl.prop('checked'), state = checkboxEl.prop('checked'),
rowEl = checkboxEl.parents('tr'), rowEl = checkboxEl.parents('tr'),
member = rowEl.attr('data-group-name') || rowEl.attr('data-uid'); member = rowEl.attr('data-group-name') || rowEl.attr('data-uid'),
isPrivate = parseInt(rowEl.attr('data-private') || 0, 10),
isGroup = rowEl.attr('data-group-name') !== undefined;
if (member) { if (member) {
socket.emit('admin.categories.setPrivilege', { if (isGroup && privilege === 'groups:moderate' && !isPrivate && state) {
cid: ajaxify.variables.get('cid'), bootbox.confirm('<strong>Are you sure you wish to grant the moderation privilege to this user group?</strong> This group is public, and any users can join at will.', function(confirm) {
privilege: privilege, if (confirm) {
set: state, Category.setPrivilege(member, privilege, state, checkboxEl);
member: member } else {
}, function(err) { checkboxEl.prop('checked', checkboxEl.prop('checked') ^ 1);
if (err) { }
return app.alertError(err.message); });
} } else {
Category.setPrivilege(member, privilege, state, checkboxEl);
checkboxEl.replaceWith('<i class="fa fa-spin fa-spinner"></i>'); }
Category.refreshPrivilegeTable();
});
} else { } else {
app.alertError('No member or group was selected'); app.alertError('[[error:invalid-data]]');
} }
}) })
}; };
@ -220,6 +220,22 @@ define('admin/manage/category', [
}); });
}; };
Category.setPrivilege = function(member, privilege, state, checkboxEl) {
socket.emit('admin.categories.setPrivilege', {
cid: ajaxify.variables.get('cid'),
privilege: privilege,
set: state,
member: member
}, function(err) {
if (err) {
return app.alertError(err.message);
}
checkboxEl.replaceWith('<i class="fa fa-spin fa-spinner"></i>');
Category.refreshPrivilegeTable();
});
};
Category.launchParentSelector = function() { Category.launchParentSelector = function() {
socket.emit('categories.get', function(err, categories) { socket.emit('categories.get', function(err, categories) {
templates.parse('partials/category_list', { templates.parse('partials/category_list', {

@ -108,7 +108,7 @@
} }
}; };
helpers.spawnPrivilegeStates = function(privileges) { helpers.spawnPrivilegeStates = function(member, privileges) {
var states = []; var states = [];
for(var priv in privileges) { for(var priv in privileges) {
if (privileges.hasOwnProperty(priv)) { if (privileges.hasOwnProperty(priv)) {
@ -119,7 +119,7 @@
} }
} }
return states.map(function(priv) { return states.map(function(priv) {
return '<td class="text-center" data-privilege="' + priv.name + '"><input type="checkbox"' + (priv.state ? ' checked' : '') + ' /></td>'; return '<td class="text-center" data-privilege="' + priv.name + '"><input type="checkbox"' + (priv.state ? ' checked' : '') + (member === 'guests' && priv.name === 'groups:moderate' ? ' disabled="disabled"' : '') + ' /></td>';
}).join(''); }).join('');
}; };

@ -117,6 +117,19 @@ module.exports = function(privileges) {
next(null, memberData); next(null, memberData);
}); });
},
function(memberData, next) {
// Grab privacy info for the groups as well
async.map(memberData, function(member, next) {
groups.isPrivate(member.name, function(err, isPrivate) {
if (err) {
return next(err);
}
member.isPrivate = isPrivate;
next(null, member);
});
}, next);
} }
], next); ], next);
} }

@ -79,7 +79,7 @@
<div class="panel-body"> <div class="panel-body">
<p> <p>
You can configure the access control privileges for this category in this section. Privileges can be granted on a per-user or You can configure the access control privileges for this category in this section. Privileges can be granted on a per-user or
a per-group basis. You can add a new user or group to this table by searching for them in the form below. a per-group basis. You can add a new user to this table by searching for them in the form below.
</p> </p>
<p class="text-warning"> <p class="text-warning">
<strong>Note</strong>: Privilege settings take effect immediately. It is not necessary to save the category after adjusting <strong>Note</strong>: Privilege settings take effect immediately. It is not necessary to save the category after adjusting

@ -11,7 +11,7 @@
<tr data-uid="{uid}"> <tr data-uid="{uid}">
<td><img src="{picture}" title="{username}" /></td> <td><img src="{picture}" title="{username}" /></td>
<td>{username}</td> <td>{username}</td>
{function.spawnPrivilegeStates, privileges} {function.spawnPrivilegeStates, username, privileges}
</tr> </tr>
<!-- END privileges.users --> <!-- END privileges.users -->
<!-- ELSE --> <!-- ELSE -->
@ -31,9 +31,14 @@
<!-- END privileges.labels.groups --> <!-- END privileges.labels.groups -->
</tr> </tr>
<!-- BEGIN privileges.groups --> <!-- BEGIN privileges.groups -->
<tr data-group-name="{privileges.groups.name}"> <tr data-group-name="{privileges.groups.name}" data-private="<!-- IF privileges.groups.isPrivate -->1<!-- ELSE -->0<!-- ENDIF privileges.groups.isPrivate -->">
<td>{privileges.groups.name}</td> <td>
{function.spawnPrivilegeStates, privileges} <!-- IF privileges.groups.isPrivate -->
<i class="fa fa-lock text-muted" title="This group is private"></i>
<!-- ENDIF privileges.groups.isPrivate -->
{privileges.groups.name}
</td>
{function.spawnPrivilegeStates, name, privileges}
</tr> </tr>
<!-- END privileges.groups --> <!-- END privileges.groups -->
</table> </table>

Loading…
Cancel
Save