Welcome all users to their status page

This commit is contained in:
James Brooks
2016-08-23 13:09:47 +01:00
parent 1b96420fc9
commit 6685ae96d8
13 changed files with 312 additions and 25 deletions
@@ -0,0 +1,41 @@
<?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\Bus\Commands\User;
use CachetHQ\Cachet\Models\User;
/**
* This is the welcome user command.
*
* @author James Brooks <james@alt-three.com>
*/
final class WelcomeUserCommand
{
/**
* The user.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new welcome user command instance.
*
* @param \CachetHQ\Cachet\Models\User $user
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
}
@@ -0,0 +1,41 @@
<?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\Bus\Events\User;
use CachetHQ\Cachet\Models\User;
/**
* This is the user was welcomed event.
*
* @author James Brooks <james@alt-three.com>
*/
final class UserWasWelcomedEvent implements UserEventInterface
{
/**
* The user.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new user was welcomed event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
}
@@ -0,0 +1,37 @@
<?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\Bus\Handlers\Commands\User;
use CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand;
use CachetHQ\Cachet\Bus\Events\User\UserWasWelcomedEvent;
/**
* This is the welcome user command handler.
*
* @author James Brooks <james@alt-three.com>
*/
class WelcomeUserCommandHandler
{
/**
* Handle the welcome user command.
*
* @param \CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand $command
*
* @return void
*/
public function handle(WelcomeUserCommand $command)
{
$command->user->update(['welcomed' => true]);
event(new UserWasWelcomedEvent($command->user));
}
}
@@ -138,5 +138,8 @@ class EventServiceProvider extends ServiceProvider
'CachetHQ\Cachet\Bus\Events\User\UserWasRemovedEvent' => [ 'CachetHQ\Cachet\Bus\Events\User\UserWasRemovedEvent' => [
// //
], ],
'CachetHQ\Cachet\Bus\Events\User\UserWasWelcomedEvent' => [
//
],
]; ];
} }
@@ -11,17 +11,24 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard; namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand;
use CachetHQ\Cachet\Integrations\Contracts\Feed; use CachetHQ\Cachet\Integrations\Contracts\Feed;
use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup; use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\Subscriber; use CachetHQ\Cachet\Models\Subscriber;
use Illuminate\Routing\Controller; use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date; use Jenssegers\Date\Date;
/**
* This is the dashboard controller class.
*
* @author James Brooks <james@alt-three.com>
*/
class DashboardController extends Controller class DashboardController extends Controller
{ {
/** /**
@@ -83,6 +90,11 @@ class DashboardController extends Controller
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get(); $componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
$ungroupedComponents = Component::enabled()->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get(); $ungroupedComponents = Component::enabled()->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
$welcomeUser = !Auth::user()->welcomed;
if ($welcomeUser) {
dispatch(new WelcomeUserCommand(Auth::user()));
}
$entries = null; $entries = null;
if ($feed = $this->feed->latest()) { if ($feed = $this->feed->latest()) {
$entries = array_slice($feed->channel->item, 0, 5); $entries = array_slice($feed->channel->item, 0, 5);
@@ -95,7 +107,8 @@ class DashboardController extends Controller
->withSubscribers($subscribers) ->withSubscribers($subscribers)
->withEntries($entries) ->withEntries($entries)
->withComponentGroups($componentGroups) ->withComponentGroups($componentGroups)
->withUngroupedComponents($ungroupedComponents); ->withUngroupedComponents($ungroupedComponents)
->withWelcomeUser($welcomeUser);
} }
/** /**
-3
View File
@@ -22,7 +22,6 @@ use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Response; use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
@@ -217,8 +216,6 @@ class SetupController extends Controller
$this->writeEnv($envKey, $envValue); $this->writeEnv($envKey, $envValue);
} }
Session::flash('setup.done', true);
if (Request::ajax()) { if (Request::ajax()) {
return Response::json(['status' => 1]); return Response::json(['status' => 1]);
} }
+31
View File
@@ -21,6 +21,11 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
/**
* This is the user model.
*
* @author James Brooks <james@alt-three.com>
*/
class User extends Model implements AuthenticatableContract, CanResetPasswordContract class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{ {
use Authenticatable, CanResetPassword, ValidatingTrait; use Authenticatable, CanResetPassword, ValidatingTrait;
@@ -39,6 +44,15 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*/ */
const LEVEL_USER = 2; const LEVEL_USER = 2;
/**
* The model's attributes.
*
* @var string[]
*/
protected $attributes = [
'welcomed' => false,
];
/** /**
* The attributes that should be casted to native types. * The attributes that should be casted to native types.
* *
@@ -51,6 +65,23 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
'api_key' => 'string', 'api_key' => 'string',
'active' => 'bool', 'active' => 'bool',
'level' => 'int', 'level' => 'int',
'welcomed' => 'bool',
];
/**
* The fillable properties.
*
* @var string[]
*/
protected $fillable = [
'username',
'password',
'google_2fa_secret',
'email',
'api_key',
'active',
'level',
'welcomed',
]; ];
/** /**
@@ -0,0 +1,41 @@
<?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.
*/
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AlterTableUsersAddWelcomedColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->boolean('welcomed')->default(false)->after('level');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('welcomed');
});
}
}
+10 -10
View File
@@ -233,7 +233,7 @@ return [
'login' => [ 'login' => [
'login' => 'Login', 'login' => 'Login',
'logged_in' => 'You\'re logged in.', 'logged_in' => 'You\'re logged in.',
'welcome' => 'Welcome Back!', 'welcome' => 'Welcome back!',
'two-factor' => 'Please enter your token.', 'two-factor' => 'Please enter your token.',
], ],
@@ -259,16 +259,16 @@ return [
// Welcome modal // Welcome modal
'welcome' => [ 'welcome' => [
'welcome' => 'Welcome to your new Status page!', 'welcome' => 'Welcome to your new status page, :username!',
'message' => 'Your status page is almost ready! You might want to configure these extra settings', 'message' => 'You\'re almost ready but you might want to configure these extra settings first...',
'close' => 'Take me straight to my dashboard', 'close' => 'I\'m good thanks!',
'steps' => [ 'steps' => [
'component' => 'Create components', 'component' => 'Add your components',
'incident' => 'Create incidents', 'incident' => 'Create an incident',
'customize' => 'Customize', 'customize' => 'Customize your page',
'team' => 'Add users', 'team' => 'Add your team',
'api' => 'Generate API token', 'api' => 'Generate an API token',
'two-factor' => 'Two Factor Authentication', 'two-factor' => 'Setup Two Factor Authentication',
], ],
], ],
+1 -6
View File
@@ -87,12 +87,7 @@
@endif @endif
</div> </div>
</div> </div>
@if(Session::get('setup.done')) @if ($welcome_user)
@include('dashboard.partials.welcome-modal') @include('dashboard.partials.welcome-modal')
<script>
(function() {
$('#welcome-modal').modal('show');
}());
</script>
@endif @endif
@stop @stop
@@ -1,4 +1,3 @@
<!-- First time welcome Modal -->
<div class="modal fade" id="welcome-modal" tabindex="-1" role="dialog"> <div class="modal fade" id="welcome-modal" tabindex="-1" role="dialog">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
@@ -7,7 +6,7 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<header> <header>
{{ trans('dashboard.welcome.welcome') }} {{ trans('dashboard.welcome.welcome', ['username' => $current_user->username]) }}
</header> </header>
<p> <p>
@@ -38,18 +37,18 @@
<div class="row"> <div class="row">
<div class="col-md-4 animated fadeInDown"> <div class="col-md-4 animated fadeInDown">
<a href="{{ route('dashboard.team.add') }}"> <a href="{{ route('dashboard.team.add') }}">
<i class="ion ion-ios-people"></i> <i class="ion ion-ios-people"></i>
{{ trans('dashboard.welcome.steps.team') }} {{ trans('dashboard.welcome.steps.team') }}
</a> </a>
</div> </div>
<div class="col-md-4 animated fadeInDown two"> <div class="col-md-4 animated fadeInDown two">
<a href="{{ route('dashboard.user') }}"> <a href="{{ route('dashboard.user.user') }}">
<i class="ion ion-code-working"></i> <i class="ion ion-code-working"></i>
{{ trans('dashboard.welcome.steps.api') }} {{ trans('dashboard.welcome.steps.api') }}
</a> </a>
</div> </div>
<div class="col-md-4 animated fadeInDown three"> <div class="col-md-4 animated fadeInDown three">
<a href="{{ route('dashboard.user') }}"> <a href="{{ route('dashboard.user.user') }}">
<i class="ion ion-unlocked"></i> <i class="ion ion-unlocked"></i>
{{ trans('dashboard.welcome.steps.two-factor') }} {{ trans('dashboard.welcome.steps.two-factor') }}
</a> </a>
@@ -65,3 +64,9 @@
</div> </div>
</div> </div>
</div> </div>
<script>
(function() {
$('#welcome-modal').modal('show');
}());
</script>
@@ -0,0 +1,47 @@
<?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\Tests\Cachet\Bus\Commands\User;
use AltThree\TestBench\CommandTrait;
use CachetHQ\Cachet\Bus\Commands\User\WelcomeUserCommand;
use CachetHQ\Cachet\Bus\Handlers\Commands\User\WelcomeUserCommandHandler;
use CachetHQ\Cachet\Models\User;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the welcome user command test class.
*
* @author James Brooks <james@alt-three.com>
*/
class WelcomeUserCommandTest extends AbstractTestCase
{
use CommandTrait;
protected function getObjectAndParams()
{
$params = ['user' => new User()];
$object = new WelcomeUserCommand($params['user']);
return compact('params', 'object');
}
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass()
{
return WelcomeUserCommandHandler::class;
}
}
@@ -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\Tests\Cachet\Bus\Events\User;
use CachetHQ\Cachet\Bus\Events\User\UserWasWelcomedEvent;
use CachetHQ\Cachet\Models\User;
/**
* This is the user was welcomed event test class.
*
* @author James Brooks <james@alt-three.com>
*/
class UserWasWelcomedEventTest extends AbstractUserEventTestCase
{
protected function objectHasHandlers()
{
return false;
}
protected function getObjectAndParams()
{
$params = ['user' => new User()];
$object = new UserWasWelcomedEvent($params['user']);
return compact('params', 'object');
}
}