added pointer interfaces for jobs
This commit is contained in:
@ -3,34 +3,14 @@
|
||||
namespace App\Jobs\Auth;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Interfaces\Job\ShouldUpdate;
|
||||
use App\Events\Auth\UserUpdated;
|
||||
use App\Events\Auth\UserUpdating;
|
||||
use App\Models\Auth\User;
|
||||
|
||||
class UpdateUser extends Job
|
||||
class UpdateUser extends Job implements ShouldUpdate
|
||||
{
|
||||
protected $user;
|
||||
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $user
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($user, $request)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->request = $this->getRequestInstance($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): User
|
||||
{
|
||||
$this->authorize();
|
||||
|
||||
@ -40,25 +20,25 @@ class UpdateUser extends Job
|
||||
unset($this->request['password_confirmation']);
|
||||
}
|
||||
|
||||
event(new UserUpdating($this->user, $this->request));
|
||||
event(new UserUpdating($this->model, $this->request));
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->user->update($this->request->input());
|
||||
$this->model->update($this->request->input());
|
||||
|
||||
// Upload picture
|
||||
if ($this->request->file('picture')) {
|
||||
$media = $this->getMedia($this->request->file('picture'), 'users');
|
||||
|
||||
$this->user->attachMedia($media, 'picture');
|
||||
$this->model->attachMedia($media, 'picture');
|
||||
}
|
||||
|
||||
if ($this->request->has('roles')) {
|
||||
$this->user->roles()->sync($this->request->get('roles'));
|
||||
$this->model->roles()->sync($this->request->get('roles'));
|
||||
}
|
||||
|
||||
if ($this->request->has('companies')) {
|
||||
if (app()->runningInConsole() || request()->isInstall()) {
|
||||
$this->user->companies()->sync($this->request->get('companies'));
|
||||
$this->model->companies()->sync($this->request->get('companies'));
|
||||
} else {
|
||||
$user = user();
|
||||
|
||||
@ -67,30 +47,28 @@ class UpdateUser extends Job
|
||||
});
|
||||
|
||||
if ($companies->isNotEmpty()) {
|
||||
$this->user->companies()->sync($companies->toArray());
|
||||
$this->model->companies()->sync($companies->toArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->user->contact) {
|
||||
$this->user->contact->update($this->request->input());
|
||||
if ($this->model->contact) {
|
||||
$this->model->contact->update($this->request->input());
|
||||
}
|
||||
});
|
||||
|
||||
event(new UserUpdated($this->user, $this->request));
|
||||
event(new UserUpdated($this->model, $this->request));
|
||||
|
||||
return $this->user;
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this action is applicable.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authorize()
|
||||
public function authorize(): void
|
||||
{
|
||||
// Can't disable yourself
|
||||
if (($this->request->get('enabled', 1) == 0) && ($this->user->id == user()->id)) {
|
||||
if (($this->request->get('enabled', 1) == 0) && ($this->model->id == user()->id)) {
|
||||
$message = trans('auth.error.self_disable');
|
||||
|
||||
throw new \Exception($message);
|
||||
|
Reference in New Issue
Block a user