new: [UI] Make possible to filter users by active/disabled

pull/6744/head
Jakub Onderka 2020-12-11 16:01:19 +01:00
parent d8f103361f
commit 583314bc02
6 changed files with 81 additions and 69 deletions

View File

@ -341,7 +341,7 @@ class UsersController extends AppController
$this->User->virtualFields['org_ci'] = 'UPPER(Organisation.name)';
$urlParams = "";
$passedArgsArray = array();
$booleanFields = array('autoalert', 'contactalert', 'termsaccepted');
$booleanFields = array('autoalert', 'contactalert', 'termsaccepted', 'disabled');
$textFields = array('role', 'email', 'all', 'authkey');
// org admins can't see users of other orgs
if ($this->_isSiteAdmin()) {
@ -494,8 +494,11 @@ class UsersController extends AppController
public function admin_filterUserIndex()
{
$passedArgsArray = array();
$booleanFields = array('autoalert', 'contactalert', 'termsaccepted');
$textFields = array('role', 'email', 'authkey');
$booleanFields = array('autoalert', 'contactalert', 'termsaccepted', 'disabled');
$textFields = array('role', 'email');
if (empty(Configure::read('Security.advanced_authkeys'))) {
$textFields[] = 'authkey';
}
$showOrg = 0;
// org admins can't see users of other orgs
if ($this->_isSiteAdmin()) {
@ -542,17 +545,15 @@ class UsersController extends AppController
$roleNames[$v['Role']['id']] = $v['Role']['name'];
$roleJSON[] = array('id' => $v['Role']['id'], 'value' => $v['Role']['name']);
}
$temp = $this->User->Organisation->find('all', array(
'conditions' => array('local' => 1),
'recursive' => -1,
'fields' => array('id', 'name'),
'order' => array('LOWER(name) ASC')
));
$orgs = array();
foreach ($temp as $org) {
$orgs[$org['Organisation']['id']] = $org['Organisation']['name'];
if ($showOrg) {
$orgs = $this->User->Organisation->find('list', array(
'conditions' => array('local' => 1),
'recursive' => -1,
'fields' => array('id', 'name'),
'order' => array('LOWER(name) ASC')
));
$this->set('orgs', $orgs);
}
$this->set('orgs', $orgs);
$this->set('roles', $roleNames);
$this->set('roleJSON', json_encode($roleJSON));
$rules = $this->_arrayToValuesIndexArray($rules);
@ -563,29 +564,21 @@ class UsersController extends AppController
public function admin_view($id = null)
{
$contain = [
'UserSetting',
'Role',
'Organisation'
];
if (!empty(Configure::read('Security.advanced_authkeys'))) {
$contain['AuthKey'] = [
'conditions' => [
'OR' => [
'AuthKey.expiration' => 0,
'AuthKey.expiration <' => time()
]
]
];
}
$user = $this->User->find('first', array(
'recursive' => -1,
'conditions' => array('User.id' => $id),
'contain' => $contain
'contain' => [
'UserSetting',
'Role',
'Organisation'
]
));
if (empty($user)) {
throw new NotFoundException(__('Invalid user'));
}
if (!$this->_isSiteAdmin() && !($this->_isAdmin() && $this->Auth->user('org_id') == $user['User']['org_id'])) {
throw new MethodNotAllowedException();
}
if (!empty($user['User']['gpgkey'])) {
$pgpDetails = $this->User->verifySingleGPG($user);
$user['User']['pgp_status'] = isset($pgpDetails[2]) ? $pgpDetails[2] : 'OK';
@ -598,10 +591,6 @@ class UsersController extends AppController
if (!empty(Configure::read('Security.advanced_authkeys'))) {
unset($user['User']['authkey']);
}
$this->set('user', $user);
if (!$this->_isSiteAdmin() && !($this->_isAdmin() && $this->Auth->user('org_id') == $user['User']['org_id'])) {
throw new MethodNotAllowedException();
}
if ($this->_isRest()) {
$user['User']['password'] = '*****';
$temp = array();
@ -614,14 +603,13 @@ class UsersController extends AppController
'Role' => $user['Role'],
'UserSetting' => $user['UserSetting']
), $this->response->type());
return $this->RestResponse->viewData(array('User' => $user['User']), $this->response->type());
} else {
$user2 = $this->User->find('first', array('conditions' => array('User.id' => $user['User']['invited_by']), 'recursive' => -1));
$this->set('id', $id);
$this->set('user2', $user2);
$this->set('admin_view', true);
$this->render('view');
}
$this->set('user', $user);
$user2 = $this->User->find('first', array('conditions' => array('User.id' => $user['User']['invited_by']), 'recursive' => -1));
$this->set('id', $id);
$this->set('user2', $user2);
$this->set('admin_view', true);
$this->render('view');
}
public function admin_add()

View File

@ -11,9 +11,13 @@
}
}
}
$data = h($data);
if (empty($data) && !empty($field['empty'])) {
$data = $field['empty'];
}
if (is_numeric($data)) {
$data = date('Y-m-d H:i:s', $data);
} else {
$data = h($data);
}
if (!empty($field['onClick'])) {
$data = sprintf(
@ -23,4 +27,4 @@
);
}
echo $data;
?>

View File

@ -60,5 +60,4 @@
)
);
}
echo ($rowHtml);
?>
echo $rowHtml;

View File

@ -122,19 +122,19 @@ var filtering = <?php echo $filtering; ?>;
var operators = ["OR", "NOT"];
var differentFilters = ["autoalert", "contactalert", "termsaccepted"];
var differentFilters = <?= json_encode($differentFilters) ?>;
var simpleFilters = <?php echo json_encode($simpleFilters, true); ?>;
var simpleFilters = <?php echo json_encode($simpleFilters); ?>;
var typedFields = ["role"];
var orgs = <?php echo json_encode($orgs, true); ?>
var orgs = <?= isset($orgs) ? json_encode($orgs) : '[]'; ?>;
var allFields = simpleFilters.concat(differentFilters);
var baseurl = "<?php echo $baseurl; ?>";
$(document).ready(function() {
$(function() {
indexRuleChange();
indexSetTableVisibility();
indexEvaluateFiltering();

View File

@ -30,12 +30,31 @@
)
)
),
array(
'type' => 'simple',
'children' => array(
array(
'url' => $baseurl . '/admin/users/index',
'text' => __('All'),
'active' => !isset($passedArgsArray['disabled']),
),
array(
'url' => $baseurl . '/admin/users/index/searchdisabled:0',
'text' => __('Active'),
'active' => isset($passedArgsArray['disabled']) && $passedArgsArray['disabled'] === "0",
),
array(
'url' => $baseurl . '/admin/users/index/searchdisabled:1',
'text' => __('Disabled'),
'active' => isset($passedArgsArray['disabled']) && $passedArgsArray['disabled'] === "1",
)
)
),
array(
'type' => 'search',
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'searchKey' => 'value'
'searchKey' => 'value',
)
)
),
@ -118,6 +137,7 @@
'name' => __('Last Login'),
'sort' => 'User.current_login',
'element' => 'datetime',
'empty' => __('Never'),
'class' => 'short',
'data_path' => 'User.current_login'
),
@ -216,15 +236,3 @@
));
echo '</div>';
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'admin', 'menuItem' => 'indexUser'));
?>
<script type="text/javascript">
var passedArgsArray = <?php echo $passedArgs; ?>;
if (passedArgsArray['context'] === undefined) {
passedArgsArray['context'] = 'pending';
}
$(document).ready(function() {
$('#quickFilterButton').click(function() {
runIndexQuickFilter('/context:' + passedArgsArray['context']);
});
});
</script>

View File

@ -2207,26 +2207,38 @@ function runIndexFilter(element) {
}
function runIndexQuickFilter(preserveParams, url, target) {
if (!passedArgsArray) {
if (typeof passedArgsArray === "undefined") {
var passedArgsArray = [];
}
var searchKey = 'searchall';
if ($('#quickFilterField').data('searchkey')) {
searchKey = $('#quickFilterField').data('searchkey');
var $quickFilterField = $('#quickFilterField');
var searchKey;
if ($quickFilterField.data('searchkey')) {
searchKey = $quickFilterField.data('searchkey');
} else {
searchKey = 'searchall';
}
if ( $('#quickFilterField').val().trim().length > 0){
passedArgsArray[searchKey] = encodeURIComponent($('#quickFilterField').val().trim());
if ($quickFilterField.val().trim().length > 0) {
passedArgsArray[searchKey] = encodeURIComponent($quickFilterField.val().trim());
}
if (typeof url === "undefined") {
url = here;
}
if (typeof preserveParams !== "undefined") {
if (typeof preserveParams === "string") {
preserveParams = String(preserveParams);
if (!preserveParams.startsWith('/')) {
preserveParams = '/' + preserveParams;
}
url += preserveParams;
} else if (typeof preserveParams === "object") {
for (var key in preserveParams) {
if (typeof key == 'number') {
url += "/" + preserveParams[key];
} else if (key !== 'page') {
url += "/" + key + ":" + preserveParams[key];
}
}
}
for (var key in passedArgsArray) {
if (typeof key == 'number') {
url += "/" + passedArgsArray[key];
@ -2234,6 +2246,7 @@ function runIndexQuickFilter(preserveParams, url, target) {
url += "/" + key + ":" + passedArgsArray[key];
}
}
if (target !== undefined) {
$.ajax({
beforeSend: function () {