System status now ignores hidden groups for guests - Fixes #2577

This commit is contained in:
James Brooks 2017-06-19 14:23:32 +01:00
parent 19ac600082
commit af3d5ab493
3 changed files with 36 additions and 6 deletions

View File

@ -97,8 +97,9 @@ class IntegrationServiceProvider extends ServiceProvider
{
$this->app->singleton(SystemContract::class, function (Container $app) {
$config = $app['config'];
$auth = $app['auth.driver'];
return new System($config);
return new System($config, $auth);
});
}

View File

@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Integrations\Core;
use CachetHQ\Cachet\Integrations\Contracts\System as SystemContract;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Config\Repository;
/**
@ -30,16 +31,25 @@ class System implements SystemContract
*/
protected $config;
/**
* The illuminate guard instance.
*
* @var \Illuminate\Contracts\Auth\Guard
*/
protected $auth;
/**
* Create a new system instance.
*
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Illuminate\Contracts\Auth\Guard. $auth
*
* @return void
*/
public function __construct(Repository $config)
public function __construct(Repository $config, Guard $auth)
{
$this->config = $config;
$this->auth = $auth;
}
/**
@ -49,8 +59,10 @@ class System implements SystemContract
*/
public function getStatus()
{
$totalComponents = Component::enabled()->count();
$majorOutages = Component::enabled()->status(4)->count();
$includePrivate = $this->auth->check();
$totalComponents = Component::enabled()->authenticated($includePrivate)->count();
$majorOutages = Component::enabled()->authenticated($includePrivate)->status(4)->count();
$isMajorOutage = $totalComponents ? ($majorOutages / $totalComponents) >= 0.5 : false;
// Default data
@ -66,7 +78,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 (Component::enabled()->authenticated($includePrivate)->notStatus(1)->count() === 0) {
// If all our components are ok, do we have any non-fixed incidents?
$incidents = Incident::orderBy('occurred_at', 'desc')->get()->filter(function ($incident) {
return $incident->status !== Incident::FIXED;
@ -83,7 +95,7 @@ class System implements SystemContract
'favicon' => 'favicon',
];
}
} elseif (Component::enabled()->whereIn('status', [2, 3])->count() > 0) {
} elseif (Component::enabled()->authenticated($includePrivate)->whereIn('status', [2, 3])->count() > 0) {
$status['favicon'] = 'favicon-medium-alert';
}

View File

@ -192,6 +192,23 @@ class Component extends Model implements HasPresenter
return $query->where('enabled', '=', true);
}
/**
* Find all components which are within visible groups.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param bool $authenticated
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeAuthenticated(Builder $query, $authenticated)
{
return $query->when(!$authenticated, function (Builder $query) {
return $query->whereDoesntHave('group', function (Builder $query) {
$query->where('visible', ComponentGroup::VISIBLE_AUTHENTICATED);
});
});
}
/**
* Finds all components which are disabled.
*