chg: [internal] Do not fetch user settings for User::getAuthUser

pull/6581/head
Jakub Onderka 2020-11-16 09:46:26 +01:00
parent dbad8d545d
commit b7eef315df
1 changed files with 26 additions and 18 deletions

View File

@ -641,39 +641,50 @@ class User extends AppModel
// get the current user and rearrange it to be in the same format as in the auth component // get the current user and rearrange it to be in the same format as in the auth component
public function getAuthUser($id) public function getAuthUser($id)
{ {
$user = $this->getUserById($id); if (empty($id)) {
if (empty($user)) { throw new InvalidArgumentException('Invalid user ID.');
return $user;
} }
return $this->rearrangeToAuthForm($user); $conditions = ['User.id' => $id];
return $this->getAuthUserByConditions($conditions);
} }
// get the current user and rearrange it to be in the same format as in the auth component // get the current user and rearrange it to be in the same format as in the auth component
public function getAuthUserByAuthkey($id) public function getAuthUserByAuthkey($authkey)
{ {
$conditions = array('User.authkey' => $id); if (empty($authkey)) {
$user = $this->find('first', array('conditions' => $conditions, 'recursive' => -1,'contain' => array('Organisation', 'Role', 'Server'))); throw new InvalidArgumentException('Invalid user auth key.');
if (empty($user)) {
return $user;
} }
return $this->rearrangeToAuthForm($user); $conditions = array('User.authkey' => $authkey);
return $this->getAuthUserByConditions($conditions);
} }
public function getAuthUserByExternalAuth($auth_key) public function getAuthUserByExternalAuth($auth_key)
{ {
if (empty($auth_key)) {
throw new InvalidArgumentException('Invalid user external auth key.');
}
$conditions = array( $conditions = array(
'User.external_auth_key' => $auth_key, 'User.external_auth_key' => $auth_key,
'User.external_auth_required' => true 'User.external_auth_required' => true
); );
$user = $this->find('first', array( return $this->getAuthUserByConditions($conditions);
}
/**
* @param array $conditions
* @return array|null
*/
private function getAuthUserByConditions(array $conditions)
{
$user = $this->find('first', [
'conditions' => $conditions, 'conditions' => $conditions,
'recursive' => -1, 'recursive' => -1,
'contain' => array( 'contain' => [
'Organisation', 'Organisation',
'Role', 'Role',
'Server' 'Server',
) ],
)); ]);
if (empty($user)) { if (empty($user)) {
return $user; return $user;
} }
@ -696,9 +707,6 @@ class User extends AppModel
$user['User']['Role'] = $user['Role']; $user['User']['Role'] = $user['Role'];
$user['User']['Organisation'] = $user['Organisation']; $user['User']['Organisation'] = $user['Organisation'];
$user['User']['Server'] = $user['Server']; $user['User']['Server'] = $user['Server'];
if (isset($user['UserSetting'])) {
$user['User']['UserSetting'] = $user['UserSetting'];
}
return $user['User']; return $user['User'];
} }