diff --git a/app/Controller/UsersController.php b/app/Controller/UsersController.php index 2d8075908..4f9de9c49 100644 --- a/app/Controller/UsersController.php +++ b/app/Controller/UsersController.php @@ -45,7 +45,7 @@ class UsersController extends AppController public function view($id = null) { - if ("me" == $id) { + if ("me" === $id) { $id = $this->Auth->user('id'); } if (!$this->_isSiteAdmin() && $this->Auth->user('id') != $id) { @@ -72,13 +72,6 @@ class UsersController extends AppController $user['User']['fingerprint'] = !empty($pgpDetails[4]) ? $pgpDetails[4] : 'N/A'; } if ($this->_isRest()) { - unset($user['User']['server_id']); - $user['User']['password'] = '*****'; - $temp = array(); - foreach ($user['UserSetting'] as $k => $v) { - $temp[$v['setting']] = $v['value']; - } - $user['UserSetting'] = $temp; return $this->RestResponse->viewData($this->__massageUserObject($user), $this->response->type()); } else { $this->set('user', $user); @@ -86,13 +79,19 @@ class UsersController extends AppController } } - private function __massageUserObject($user) + /** + * @param array $user + * @return array + */ + private function __massageUserObject(array $user) { + $user['UserSetting'] = array_column($user['UserSetting'], 'value', 'setting'); unset($user['User']['server_id']); if (!empty(Configure::read('Security.advanced_authkeys'))) { unset($user['User']['authkey']); } $user['User']['password'] = '*****'; + $temp = []; $objectsToInclude = array('User', 'Role', 'UserSetting', 'Organisation'); foreach ($objectsToInclude as $objectToInclude) { if (isset($user[$objectToInclude])) { @@ -2324,9 +2323,6 @@ class UsersController extends AppController public function verifyGPG($full = false) { - if (!self::_isSiteAdmin()) { - throw new NotFoundException(); - } $user_results = $this->User->verifyGPG($full); $this->set('users', $user_results); } diff --git a/app/Model/User.php b/app/Model/User.php index 98fb96961..d184730f3 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -530,12 +530,12 @@ class User extends AppModel $sortedKeys['valid']++; } if (!$sortedKeys['valid']) { - $result[2] = 'The user\'s GnuPG key does not include a valid subkey that could be used for encryption.'; + $result[2] = 'The user\'s PGP key does not include a valid subkey that could be used for encryption.'; if ($sortedKeys['expired']) { - $result[2] .= ' Found ' . $sortedKeys['expired'] . ' subkey(s) that have expired.'; + $result[2] .= ' ' . __n('Found %s subkey that have expired.', 'Found %s subkeys that have expired.', $sortedKeys['expired'], $sortedKeys['expired']); } if ($sortedKeys['noEncrypt']) { - $result[2] .= ' Found ' . $sortedKeys['noEncrypt'] . ' subkey(s) that are sign only.'; + $result[2] .= ' ' . __n('Found %s subkey that is sign only.', 'Found %s subkeys that are sign only.', $sortedKeys['noEncrypt'], $sortedKeys['noEncrypt']); } } else { $result[0] = true; @@ -555,6 +555,7 @@ class User extends AppModel } $users = $this->find('all', array( 'conditions' => $conditions, + 'fields' => ['id', 'email', 'gpgkey'], 'recursive' => -1, )); if (empty($users)) { @@ -565,7 +566,7 @@ class User extends AppModel return []; } $results = []; - foreach ($users as $k => $user) { + foreach ($users as $user) { $results[$user['User']['id']] = $this->verifySingleGPG($user); } return $results; diff --git a/app/View/Users/view.ctp b/app/View/Users/view.ctp index 44a6482cf..45aef9c3f 100755 --- a/app/View/Users/view.ctp +++ b/app/View/Users/view.ctp @@ -84,12 +84,12 @@ if (!empty($user['User']['gpgkey'])) { $table_data[] = array( 'key' => __('PGP key fingerprint'), - 'class_value' => "quickSelect bold " . $user['User']['gpgkey'] ? 'green' : 'bold red', + 'value_class' => 'quickSelect', 'value' => $user['User']['fingerprint'] ? chunk_split($user['User']['fingerprint'], 4, ' ') : 'N/A' ); $table_data[] = array( 'key' => __('PGP key status'), - 'class_value' => "bold" . (empty($user['User']['pgp_status']) || $user['User']['pgp_status'] != 'OK') ? 'red': 'green', + 'value_class' => (empty($user['User']['pgp_status']) || $user['User']['pgp_status'] !== 'OK') ? 'red': '', 'value' => !empty($user['User']['pgp_status']) ? $user['User']['pgp_status'] : 'N/A' ); }