Added RemoveUserCommand

This commit is contained in:
James Brooks
2015-08-26 13:28:10 +01:00
parent 7be3aa2552
commit c466620435
4 changed files with 108 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Commands\User;
use CachetHQ\Cachet\Models\User;
class RemoveUserCommand
{
/**
* The user to remove.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new remove user command instance.
*
* @param \CachetHQ\Cachet\Models\User $user
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Events\User;
use CachetHQ\Cachet\Models\User;
class UserWasRemovedEvent
{
/**
* The user that has been removed.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new user was removed event instance.
*/
public function __construct(User $user)
{
$this->user = $user;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Handlers\Commands\User;
use CachetHQ\Cachet\Commands\User\RemoveUserCommand;
use CachetHQ\Cachet\Events\User\UserWasRemovedEvent;
use CachetHQ\Cachet\Models\User;
class RemoveUserCommandHandler
{
/**
* Handle the remove user command.
*
* @param \CachetHQ\Cachet\Commands\User\RemoveUserCommand $command
*
* @return void
*/
public function handle(RemoveUserCommand $command)
{
$user = $command->user;
event(new UserWasRemovedEvent($user));
$user->delete();
}
}

View File

@@ -12,14 +12,18 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Commands\User\RemoveUserCommand;
use CachetHQ\Cachet\Models\User;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
class TeamController extends Controller
{
use DispatchesJobs;
/**
* Shows the team members view.
*
@@ -116,7 +120,7 @@ class TeamController extends Controller
*/
public function deleteUser(User $user)
{
$user->delete();
$this->dispatch(new RemoveUserCommand($user));
return Redirect::route('dashboard.team.index')
->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.delete.success')));