Added more user and system events

This commit is contained in:
James Brooks
2016-08-03 12:26:23 +01:00
parent b3cc8f7031
commit 6b6eeb9a3e
12 changed files with 262 additions and 4 deletions

View File

@@ -0,0 +1,22 @@
<?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\System;
/**
* This is the system checked for updates event class.
*
* @author James Brooks <james@alt-three.com>
*/
final class SystemCheckedForUpdatesEvent implements SystemEventInterface
{
//
}

View File

@@ -0,0 +1,24 @@
<?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\System;
use CachetHQ\Cachet\Bus\Events\EventInterface;
/**
* This is the system event interface.
*
* @author James Brooks <james@alt-three.com>
*/
interface SystemEventInterface extends EventInterface
{
//
}

View File

@@ -0,0 +1,22 @@
<?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\System;
/**
* This is the system was installed event class.
*
* @author James Brooks <james@alt-three.com>
*/
final class SystemWasInstalledEvent implements SystemEventInterface
{
//
}

View File

@@ -0,0 +1,22 @@
<?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\System;
/**
* This is the system was updated event class.
*
* @author James Brooks <james@alt-three.com>
*/
final class SystemWasUpdatedEvent implements SystemEventInterface
{
//
}

View File

@@ -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 disabled two auth event class.
*
* @author James Brooks <james@alt-three.com>
*/
final class UserDisabledTwoAuthEvent implements UserEventInterface
{
/**
* The user that disabled two auth.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new user disabled two auth event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
}

View File

@@ -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 enabled two auth event class.
*
* @author James Brooks <james@alt-three.com>
*/
final class UserEnabledTwoAuthEvent implements UserEventInterface
{
/**
* The user that enabled two auth.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new user enabled two auth event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
}

View File

@@ -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 regenerated api token event class.
*
* @author James Brooks <james@alt-three.com>
*/
final class UserRegeneratedApiTokenEvent implements UserEventInterface
{
/**
* The user that regenerated their api token.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;
/**
* Create a new user regenerated api token event instance.
*
* @param \CachetHQ\Cachet\Models\User $user
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
}

View File

@@ -87,6 +87,21 @@ class EventServiceProvider extends ServiceProvider
'CachetHQ\Cachet\Bus\Events\Subscriber\SubscriberHasVerifiedEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\System\SystemCheckedForUpdatesEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\System\SystemWasInstalledEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\System\SystemWasUpdatedEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\User\UserDisabledTwoAuthEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\User\UserEnabledTwoAuthEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\User\UserFailedTwoAuthEvent' => [
//
],
@@ -99,6 +114,9 @@ class EventServiceProvider extends ServiceProvider
'CachetHQ\Cachet\Bus\Events\User\UserPassedTwoAuthEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\User\UserRegeneratedApiTokenEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\User\UserWasAddedEvent' => [
//
],

View File

@@ -12,6 +12,9 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use AltThree\Validator\ValidationException;
use CachetHQ\Cachet\Bus\Events\User\UserDisabledTwoAuthEvent;
use CachetHQ\Cachet\Bus\Events\User\UserEnabledTwoAuthEvent;
use CachetHQ\Cachet\Bus\Events\User\UserRegeneratedApiTokenEvent;
use CachetHQ\Cachet\Models\User;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
@@ -46,8 +49,10 @@ class UserController extends Controller
// Let's enable/disable auth
if ($enable2FA && !Auth::user()->hasTwoFactor) {
event(new UserEnabledTwoAuthEvent(Auth::user()));
$userData['google_2fa_secret'] = Google2FA::generateSecretKey();
} elseif (!$enable2FA) {
event(new UserDisabledTwoAuthEvent(Auth::user()));
$userData['google_2fa_secret'] = '';
}
@@ -76,6 +81,8 @@ class UserController extends Controller
$user->api_key = User::generateApiKey();
$user->save();
event(new UserRegeneratedApiTokenEvent($user));
return Redirect::route('dashboard.user');
}
}

View File

@@ -24,4 +24,11 @@ interface System
* @return array
*/
public function getStatus();
/**
* Get the cachet version.
*
* @return string
*/
public function getVersion();
}

View File

@@ -30,8 +30,8 @@ class System implements SystemContract
public function getStatus()
{
$enabledScope = Component::enabled();
$totalComponents = Component::enabled()->count();
$majorOutages = Component::enabled()->status(4)->count();
$totalComponents = $enabledScope->count();
$majorOutages = $enabledScope->status(4)->count();
$isMajorOutage = $totalComponents ? ($majorOutages / $totalComponents) >= 0.5 : false;
// Default data
@@ -47,7 +47,7 @@ class System implements SystemContract
'system_message' => trans_choice('cachet.service.major', $totalComponents),
'favicon' => 'favicon-high-alert',
];
} elseif (Component::enabled()->notStatus(1)->count() === 0) {
} elseif ($enabledScope->notStatus(1)->count() === 0) {
// If all our components are ok, do we have any non-fixed incidents?
$incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get()->filter(function ($incident) {
return $incident->status > 0;
@@ -61,10 +61,20 @@ class System implements SystemContract
'favicon' => 'favicon',
];
}
} elseif (Component::enabled()->whereIn('status', [2, 3])->count() > 0) {
} elseif ($enabledScope->whereIn('status', [2, 3])->count() > 0) {
$status['favicon'] = 'favicon-medium-alert';
}
return $status;
}
/**
* Get the cachet version.
*
* @return string
*/
public function getVersion()
{
return CACHET_VERSION;
}
}

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Integrations\GitHub;
use CachetHQ\Cachet\Bus\Events\System\SystemCheckedForUpdatesEvent;
use CachetHQ\Cachet\Integrations\Contracts\Releases as ReleasesContract;
use GuzzleHttp\Client;
use Illuminate\Contracts\Cache\Repository;
@@ -82,6 +83,8 @@ class Releases implements ReleasesContract
$headers['OAUTH-TOKEN'] = $this->token;
}
event(new SystemCheckedForUpdatesEvent());
return json_decode((new Client())->get($this->url, [
'headers' => $headers,
])->getBody(), true);