Moved user retrieval to API

This commit is contained in:
Marcin Kurczewski 2014-05-04 12:45:26 +02:00
parent 9e2e3ceb7f
commit 816859c3e3
2 changed files with 23 additions and 12 deletions

View file

@ -0,0 +1,17 @@
<?php
class GetUserJob extends AbstractUserJob
{
public function execute()
{
return $this->user;
}
public function requiresPrivilege()
{
return
[
Privilege::ViewUser,
Access::getIdentity($this->user)
];
}
}

View file

@ -19,7 +19,12 @@ class UserController
public function genericView($name, $tab = 'favs', $page = 1)
{
$user = UserModel::findByNameOrEmail($name);
$user = Api::run(
new GetUserJob(),
[
GetUserJob::USER_NAME => $name,
]);
$flagged = in_array(TextHelper::reprUser($user), SessionHelper::get('flagged', []));
$context = getContext();
@ -47,10 +52,6 @@ class UserController
$context->transport->paginator = $ret;
$context->transport->lastSearchQuery = $query;
}
Access::assert(
Privilege::ViewUser,
Access::getIdentity($user));
}
public function settingsAction($name)
@ -59,9 +60,6 @@ class UserController
$user = getContext()->transport->user;
Access::assert(
Privilege::ViewUser,
Access::getIdentity($user));
Access::assert(
Privilege::ChangeUserSettings,
Access::getIdentity($user));
@ -91,10 +89,6 @@ class UserController
$user = getContext()->transport->user;
Access::assert(
Privilege::ViewUser,
Access::getIdentity($user));
$suppliedCurrentPassword = InputHelper::get('current-password');
$suppliedName = InputHelper::get('name');
$suppliedPassword1 = InputHelper::get('password1');