Skip to content

Node.js based forum software built for the modern web

updated acp category privilege settings so that not all groups are shown in privilege table, closes #3036

Julian Lam8f7416d1cb07
diff --git a/public/less/admin/admin.less b/public/less/admin/admin.less
index 40ddcf08e3..8ab5c633e9 100644
--- a/public/less/admin/admin.less
+++ b/public/less/admin/admin.less
@@ -283,6 +283,11 @@
#taskbar {
display: none; /* not sure why I have to do this, but it only seems to show up on prod */
}
+
+ /* Allows the autocomplete dropbox to appear on top of a modal's backdrop */
+ .ui-autocomplete {
+ z-index: @zindex-popover;
+ }
}
// Allowing text to the right of an image-type brand
diff --git a/public/src/admin/manage/category.js b/public/src/admin/manage/category.js
index 238317144c..6524ed8b37 100644
--- a/public/src/admin/manage/category.js
+++ b/public/src/admin/manage/category.js
@@ -158,26 +158,6 @@ define('admin/manage/category', [
};
Category.setupPrivilegeTable = function() {
- var searchEl = $('.privilege-search'),
- searchObj = autocomplete.user(searchEl);
-
- // User search + addition to table
- searchObj.on('autocompleteselect', function(ev, ui) {
- socket.emit('admin.categories.setPrivilege', {
- cid: ajaxify.variables.get('cid'),
- privilege: 'read',
- set: true,
- member: ui.item.user.uid
- }, function(err) {
- if (err) {
- return app.alertError(err.message);
- }
-
- Category.refreshPrivilegeTable();
- searchEl.val('');
- });
- });
-
// Checkbox event capture
$('.privilege-table-container').on('change', 'input[type="checkbox"]', function() {
var checkboxEl = $(this),
@@ -205,6 +185,9 @@ 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);
+
Category.exposeAssumedPrivileges();
};
@@ -292,5 +275,65 @@ define('admin/manage/category', [
});
};
+ Category.addUserToPrivilegeTable = function() {
+ var modal = bootbox.dialog({
+ title: 'Find a User',
+ message: '<input class="form-control input-lg" placeholder="Search for a user here..." />',
+ show: true
+ });
+
+ modal.on('shown.bs.modal', function() {
+ var inputEl = modal.find('input'),
+ searchObj = autocomplete.user(inputEl);
+
+ searchObj.on('autocompleteselect', function(ev, ui) {
+ socket.emit('admin.categories.setPrivilege', {
+ cid: ajaxify.variables.get('cid'),
+ privilege: ['find', 'read'],
+ set: true,
+ member: ui.item.user.uid
+ }, function(err) {
+ if (err) {
+ return app.alertError(err.message);
+ }
+
+ Category.refreshPrivilegeTable();
+ modal.modal('hide');
+ });
+ });
+ });
+ };
+
+ Category.addGroupToPrivilegeTable = function() {
+ var modal = bootbox.dialog({
+ title: 'Find a Group',
+ message: '<input class="form-control input-lg" placeholder="Search for a group here..." />',
+ show: true
+ });
+
+ modal.on('shown.bs.modal', function() {
+ var inputEl = modal.find('input'),
+ searchObj = autocomplete.group(inputEl);
+
+ searchObj.on('autocompleteselect', function(ev, ui) {
+ console.log(ui);
+ socket.emit('admin.categories.setPrivilege', {
+ cid: ajaxify.variables.get('cid'),
+ privilege: ['groups:find', 'groups:read'],
+ set: true,
+ member: ui.item.group.name
+ }, function(err) {
+ console.log(arguments);
+ if (err) {
+ return app.alertError(err.message);
+ }
+
+ Category.refreshPrivilegeTable();
+ modal.modal('hide');
+ });
+ });
+ });
+ };
+
return Category;
});
\ No newline at end of file
diff --git a/public/src/modules/autocomplete.js b/public/src/modules/autocomplete.js
index 55c15b8686..8a6967a308 100644
--- a/public/src/modules/autocomplete.js
+++ b/public/src/modules/autocomplete.js
@@ -35,5 +35,36 @@ define('autocomplete', function() {
});
};
+ module.group = function(input) {
+ return input.autocomplete({
+ delay: 100,
+ source: function(request, response) {
+ socket.emit('groups.search', {
+ query: request.term,
+ options: {}
+ }, function(err, results) {
+ if (err) {
+ return app.alertError(err.message);
+ }
+
+ if (results && results.length) {
+ var names = results.map(function(group) {
+ return group && {
+ label: group.name,
+ value: group.name,
+ group: {
+ name: group.name,
+ slug: group.slug
+ }
+ };
+ });
+ response(names);
+ }
+ $('.ui-autocomplete a').attr('data-ajaxify', 'false');
+ });
+ }
+ });
+ };
+
return module;
});
diff --git a/src/views/admin/manage/category.tpl b/src/views/admin/manage/category.tpl
index 80b5dbe694..48d07b0e6c 100644
--- a/src/views/admin/manage/category.tpl
+++ b/src/views/admin/manage/category.tpl
@@ -86,9 +86,9 @@
these settings.
</p>
<hr />
- <input class="form-control privilege-search" type="text" placeholder="Add a user or group to this list..." />
- <hr />
- <!-- IMPORT admin/partials/categories/privileges.tpl -->
+ <div class="privilege-table-container">
+ <!-- IMPORT admin/partials/categories/privileges.tpl -->
+ </div>
</div>
</div>
</div>
diff --git a/src/views/admin/partials/categories/privileges.tpl b/src/views/admin/partials/categories/privileges.tpl
index 7e1f97b580..eb97e6bcac 100644
--- a/src/views/admin/partials/categories/privileges.tpl
+++ b/src/views/admin/partials/categories/privileges.tpl
@@ -1,51 +1,74 @@
- <div class="privilege-table-container">
- <table class="table table-striped table-hover privilege-table">
- <tr>
- <th colspan="2">User</th>
- <!-- BEGIN privileges.labels.users -->
- <th class="text-center">{privileges.labels.users.name}</th>
- <!-- END privileges.labels.users -->
- </tr>
- <!-- IF privileges.users.length -->
- <!-- BEGIN privileges.users -->
- <tr data-uid="{privileges.users.uid}">
- <td><img src="{privileges.users.picture}" title="{privileges.users.username}" /></td>
- <td>{privileges.users.username}</td>
- {function.spawnPrivilegeStates, privileges.users.username, privileges}
- </tr>
- <!-- END privileges.users -->
- <!-- ELSE -->
- <tr>
- <td colspan="{privileges.columnCount}">
- <div class="alert alert-info">No user-specific privileges in this category.</div>
- </td>
- </tr>
- <!-- ENDIF privileges.users.length -->
- </table>
+ <table class="table table-striped table-hover privilege-table">
+ <tr>
+ <th colspan="2">User</th>
+ <!-- BEGIN privileges.labels.users -->
+ <th class="text-center">{privileges.labels.users.name}</th>
+ <!-- END privileges.labels.users -->
+ </tr>
+ <!-- IF privileges.users.length -->
+ <!-- BEGIN privileges.users -->
+ <tr data-uid="{privileges.users.uid}">
+ <td><img src="{privileges.users.picture}" title="{privileges.users.username}" /></td>
+ <td>{privileges.users.username}</td>
+ {function.spawnPrivilegeStates, privileges.users.username, privileges}
+ </tr>
+ <!-- END privileges.users -->
+ <tr>
+ <td colspan="{privileges.columnCount}">
+ <button type="button" class="btn btn-primary btn-xs pull-right" data-ajaxify="false" data-action="search.user"><i class="fa fa-plus"></i> Add User</button>
+ </td>
+ </tr>
+ <!-- ELSE -->
+ <tr>
+ <td colspan="{privileges.columnCount}">
+ <div class="alert alert-info">
+ <button type="button" class="btn btn-primary btn-xs pull-right" data-ajaxify="false" data-action="search.user"><i class="fa fa-plus"></i> Add User</button>
+ No user-specific privileges in this category.
+ </div>
+ </td>
+ </tr>
+ <!-- ENDIF privileges.users.length -->
+ </table>
- <table class="table table-striped table-hover privilege-table">
- <tr>
- <th colspan="1">Group</th>
- <!-- BEGIN privileges.labels.groups -->
- <th class="text-center">{privileges.labels.groups.name}</th>
- <!-- END privileges.labels.groups -->
- </tr>
- <!-- BEGIN privileges.groups -->
- <tr data-group-name="{privileges.groups.name}" data-private="<!-- IF privileges.groups.isPrivate -->1<!-- ELSE -->0<!-- ENDIF privileges.groups.isPrivate -->">
- <td>
- <!-- 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>
- <!-- END privileges.groups -->
- </table>
- <div class="help-block">
- If the <code>registered-users</code> group is granted a specific privilege, all other groups receive an
- <strong>implicit privilege</strong>, even if they are not explicitly defined/checked. This implicit
- privilege is shown to you because all users are part of the <code>registered-users</code> user group,
- and so, privileges for additional groups need not be explicitly granted.
- </div>
- </div>
\ No newline at end of file
+ <table class="table table-striped table-hover privilege-table">
+ <tr>
+ <th colspan="2">Group</th>
+ <!-- BEGIN privileges.labels.groups -->
+ <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>
+ <!-- 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>
+ <td></td>
+ {function.spawnPrivilegeStates, name, privileges}
+ </tr>
+ <!-- END privileges.groups -->
+ <tr>
+ <td colspan="{privileges.columnCount}">
+ <button type="button" class="btn btn-primary btn-xs pull-right" data-ajaxify="false" data-action="search.group"><i class="fa fa-plus"></i> Add Group</button>
+ </td>
+ </tr>
+ <!-- ELSE -->
+ <tr>
+ <td colspan="{privileges.columnCount}">
+ <div class="alert alert-info">
+ <button type="button" class="btn btn-primary btn-xs pull-right" data-ajaxify="false" data-action="search.group"><i class="fa fa-plus"></i> Add Group</button>
+ No group-specific privileges in this category.
+ </div>
+ </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
+ <strong>implicit privilege</strong>, even if they are not explicitly defined/checked. This implicit
+ privilege is shown to you because all users are part of the <code>registered-users</code> user group,
+ and so, privileges for additional groups need not be explicitly granted.
+ </div>