Closes #700 - Subscribers can now be turned on and off
This commit is contained in:
36
app/Composers/AppComposer.php
Normal file
36
app/Composers/AppComposer.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Composers;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class AppComposer
|
||||
{
|
||||
/**
|
||||
* Index page view composer.
|
||||
*
|
||||
* @param \Illuminate\Contracts\View\View $view
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
$isEnabled = (bool) Setting::get('enable_subscribers', false);
|
||||
$mailAddress = env('MAIL_ADDRESS', false);
|
||||
$mailFrom = env('MAIL_NAME', false);
|
||||
|
||||
$withData = [
|
||||
'subscribersEnabled' => $isEnabled && $mailAddress && $mailFrom,
|
||||
];
|
||||
|
||||
$view->with($withData);
|
||||
}
|
||||
}
|
||||
@@ -44,5 +44,6 @@ class Kernel extends HttpKernel
|
||||
'login.throttling' => 'CachetHQ\Cachet\Http\Middleware\LoginThrottling',
|
||||
'app.isSetup' => 'CachetHQ\Cachet\Http\Middleware\AppIsSetup',
|
||||
'app.hasSetting' => 'CachetHQ\Cachet\Http\Middleware\HasSetting',
|
||||
'app.subscribers' => 'CachetHQ\Cachet\Http\Middleware\SubscribersConfigured',
|
||||
];
|
||||
}
|
||||
|
||||
40
app/Http/Middleware/SubscribersConfigured.php
Normal file
40
app/Http/Middleware/SubscribersConfigured.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class SubscribersConfigured
|
||||
{
|
||||
/**
|
||||
* We're verifying that subscribers is both enabled and configured.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$isEnabled = Setting::get('enable_subscribers', false);
|
||||
$mailAddress = env('MAIL_ADDRESS', false);
|
||||
$mailFrom = env('MAIL_NAME', false);
|
||||
|
||||
if (!($isEnabled && $mailAddress && $mailFrom)) {
|
||||
return Redirect::route('status-page');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,11 @@ class StatusPageRoutes
|
||||
'as' => 'status-page',
|
||||
'uses' => 'HomeController@showIndex',
|
||||
]);
|
||||
|
||||
$router->get('/atom/{component_group?}', 'AtomController@feedAction');
|
||||
$router->get('/rss/{component_group?}', 'RssController@feedAction');
|
||||
|
||||
$router->group(['middleware' => 'app.subscribers'], function ($router) {
|
||||
$router->get('subscribe', [
|
||||
'as' => 'subscribe-page',
|
||||
'uses' => 'SubscribeController@showSubscribe',
|
||||
@@ -44,8 +49,7 @@ class StatusPageRoutes
|
||||
'as' => 'unsubscribe',
|
||||
'uses' => 'SubscribeController@getUnsubscribe',
|
||||
]);
|
||||
$router->get('/atom/{component_group?}', 'AtomController@feedAction');
|
||||
$router->get('/rss/{component_group?}', 'RssController@feedAction');
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use CachetHQ\Cachet\Composers\AppComposer;
|
||||
use CachetHQ\Cachet\Composers\DashboardComposer;
|
||||
use CachetHQ\Cachet\Composers\IndexComposer;
|
||||
use CachetHQ\Cachet\Composers\LoggedUserComposer;
|
||||
@@ -27,6 +28,7 @@ class ComposerServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->view->composer('*', AppComposer::class);
|
||||
$this->app->view->composer('*', LoggedUserComposer::class);
|
||||
$this->app->view->composer(['index', 'subscribe'], IndexComposer::class);
|
||||
$this->app->view->composer(['index', 'subscribe'], ThemeComposer::class);
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Cachet HQ <support@cachethq.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class ViewComposerServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->view->composer('*', 'CachetHQ\Cachet\Composers\LoggedUserComposer');
|
||||
$this->app->view->composer('index', 'CachetHQ\Cachet\Composers\IndexComposer');
|
||||
$this->app->view->composer('index', 'CachetHQ\Cachet\Composers\ThemeComposer');
|
||||
$this->app->view->composer('subscribe', 'CachetHQ\Cachet\Composers\ThemeComposer');
|
||||
$this->app->view->composer('dashboard.*', 'CachetHQ\Cachet\Composers\DashboardComposer');
|
||||
$this->app->view->composer([
|
||||
'setup',
|
||||
'dashboard.settings.app-setup',
|
||||
], 'CachetHQ\Cachet\Composers\TimezoneLocaleComposer');
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,15 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.settings.app-setup.subscribers') }}</label>
|
||||
<input type="hidden" value="0" name="enable_subscribers">
|
||||
<input type="checkbox" value="1" name="enable_subscribers" class="form-control" {{ Setting::get('enable_subscribers') ? 'checked' : null }}>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="form-group">
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
@extends('layout.master')
|
||||
|
||||
@section('content')
|
||||
@if($subscribersEnabled)
|
||||
<div class="pull-right">
|
||||
<p><a class="btn btn-success btn-outline" href="{{ route('subscribe') }}">{{ trans('cachet.subscriber.button') }}</a></p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="clearfix"></div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user