Fixes #759. First pass at subscriber administration
This commit is contained in:
118
app/Http/Controllers/Admin/SubscriberController.php
Normal file
118
app/Http/Controllers/Admin/SubscriberController.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?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\Http\Controllers\Admin;
|
||||
|
||||
use CachetHQ\Cachet\Events\CustomerHasSubscribedEvent;
|
||||
use CachetHQ\Cachet\Http\Controllers\AbstractController;
|
||||
use CachetHQ\Cachet\Models\Subscriber;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class SubscriberController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Shows the subscribers view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showSubscribers()
|
||||
{
|
||||
$subscribers = Subscriber::all();
|
||||
|
||||
return View::make('dashboard.subscribers.index')
|
||||
->with([
|
||||
'page_title' => trans('dashboard.subscribers.subscribers').' - '.trans('dashboard.dashboard'),
|
||||
'subscribers' => $subscribers,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the add subscriber view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function showAddSubscriber()
|
||||
{
|
||||
return View::make('dashboard.subscribers.add')
|
||||
->with([
|
||||
'page_title' => trans('dashboard.subscribers.add.title').' - '.trans('dashboard.dashboard'),
|
||||
'incidentTemplates' => Subscriber::all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new subscriber.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function createSubscriberAction()
|
||||
{
|
||||
$email = Binput::get('email');
|
||||
|
||||
$subscriber = Subscriber::create([
|
||||
'email' => $email,
|
||||
]);
|
||||
|
||||
if (!$subscriber->isValid()) {
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Subscriber',
|
||||
'success' => false,
|
||||
]);
|
||||
|
||||
return Redirect::back()
|
||||
->withInput(Binput::all())
|
||||
->with('title', sprintf(
|
||||
'%s %s',
|
||||
trans('dashboard.notifications.whoops'),
|
||||
trans('dashboard.subscribers.add.failure')
|
||||
))
|
||||
->with('errors', $subscriber->getErrors());
|
||||
}
|
||||
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Created Subscriber',
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$successMsg = sprintf(
|
||||
'%s %s',
|
||||
trans('dashboard.notifications.awesome'),
|
||||
trans('dashboard.subscribers.add.success')
|
||||
);
|
||||
|
||||
event(new CustomerHasSubscribedEvent($subscriber));
|
||||
|
||||
return Redirect::back()
|
||||
->with('success', $successMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a subscriber.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteSubscriberAction(Subscriber $subscriber)
|
||||
{
|
||||
segment_track('Dashboard', [
|
||||
'event' => 'Deleted Subscriber',
|
||||
]);
|
||||
|
||||
$subscriber->delete();
|
||||
|
||||
return Redirect::back();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use CachetHQ\Cachet\Facades\Setting;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
@@ -27,11 +26,7 @@ class SubscribersConfigured
|
||||
*/
|
||||
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)) {
|
||||
if (!subscribers_enabled()) {
|
||||
return Redirect::route('status-page');
|
||||
}
|
||||
|
||||
|
||||
@@ -121,6 +121,22 @@ class AdminRoutes
|
||||
$router->delete('{incident_template}/delete', 'IncidentController@deleteTemplateAction');
|
||||
});
|
||||
|
||||
// Subscribers
|
||||
$router->group(['prefix' => 'subscribers'], function ($router) {
|
||||
$router->get('/', [
|
||||
'as' => 'dashboard.subscribers',
|
||||
'uses' => 'SubscriberController@showSubscribers',
|
||||
]);
|
||||
|
||||
$router->get('add', [
|
||||
'as' => 'dashboard.subscribers.add',
|
||||
'uses' => 'SubscriberController@showAddSubscriber',
|
||||
]);
|
||||
$router->post('add', 'SubscriberController@createSubscriberAction');
|
||||
|
||||
$router->delete('{subscriber}/delete', 'SubscriberController@deleteSubscriberAction');
|
||||
});
|
||||
|
||||
// Metrics
|
||||
$router->group(['prefix' => 'metrics'], function ($router) {
|
||||
$router->get('/', [
|
||||
|
||||
@@ -153,3 +153,19 @@ if (!function_exists('formatted_date')) {
|
||||
return (new Date($date))->format($dateFormat);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('subscribers_enabled')) {
|
||||
/**
|
||||
* Is the subscriber functionality enabled and configured.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function subscribers_enabled()
|
||||
{
|
||||
$isEnabled = Setting::get('enable_subscribers', false);
|
||||
$mailAddress = env('MAIL_ADDRESS', false);
|
||||
$mailFrom = env('MAIL_NAME', false);
|
||||
|
||||
return $isEnabled && $mailAddress && $mailFrom;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||
$this->app->router->model('metric', 'CachetHQ\Cachet\Models\Metric');
|
||||
$this->app->router->model('metric_point', 'CachetHQ\Cachet\Models\MetricPoint');
|
||||
$this->app->router->model('setting', 'CachetHQ\Cachet\Models\Setting');
|
||||
$this->app->router->model('subscriber', 'CachetHQ\Cachet\Models\Subscriber');
|
||||
$this->app->router->model('user', 'CachetHQ\Cachet\Models\User');
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,23 @@ return [
|
||||
'failure' => 'Something went wrong with the metric.',
|
||||
],
|
||||
],
|
||||
// Subscribers
|
||||
'subscribers' => [
|
||||
'subscribers' => 'Subscribers',
|
||||
'description' => 'Subscribers will receive email updates when incidents are created.',
|
||||
'verified' => 'Verified',
|
||||
'not_verified' => 'Not Verified',
|
||||
'add' => [
|
||||
'title' => 'Add a new subscriber',
|
||||
'success' => 'Subscriber added.',
|
||||
'failure' => 'Something went wrong with the component.',
|
||||
],
|
||||
'edit' => [
|
||||
'title' => 'Update subscriber',
|
||||
'success' => 'Subscriber updated.',
|
||||
'failure' => 'Something went wrong when updating.',
|
||||
],
|
||||
],
|
||||
|
||||
// Team
|
||||
'team' => [
|
||||
|
||||
32
resources/views/dashboard/subscribers/add.blade.php
Normal file
32
resources/views/dashboard/subscribers/add.blade.php
Normal file
@@ -0,0 +1,32 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
<div class="header">
|
||||
<div class="sidebar-toggler visible-xs">
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon ion-person"></i> {{ trans('dashboard.subscribers.subscribers') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
@include('partials.dashboard.errors')
|
||||
<form name="SubscriberForm" class="form-vertical" role="form" action="/dashboard/subscribers/add" method="POST">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
<label>{{ trans('forms.user.email') }}</label>
|
||||
<input type="email" class="form-control" name="email" value="{{ Input::old('email') }}" required>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-success">{{ trans('forms.add') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
48
resources/views/dashboard/subscribers/index.blade.php
Normal file
48
resources/views/dashboard/subscribers/index.blade.php
Normal file
@@ -0,0 +1,48 @@
|
||||
@extends('layout.dashboard')
|
||||
|
||||
@section('content')
|
||||
<div class="header fixed">
|
||||
<div class="sidebar-toggler visible-xs">
|
||||
<i class="icon ion-navicon"></i>
|
||||
</div>
|
||||
<span class="uppercase">
|
||||
<i class="icon icon ion-android-alert"></i> {{ trans('dashboard.subscribers.subscribers') }}
|
||||
</span>
|
||||
@if($loggedUser->isAdmin)
|
||||
<a class="btn btn-sm btn-success pull-right" href="{{ route('dashboard.subscribers.add') }}">
|
||||
{{ trans('dashboard.subscribers.add.title') }}
|
||||
</a>
|
||||
@endif
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="content-wrapper header-fixed">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<p class="lead">{{ trans('dashboard.subscribers.description') }}</p>
|
||||
|
||||
<div class="striped-list">
|
||||
@foreach($subscribers as $subscriber)
|
||||
<div class="row striped-list-item">
|
||||
<div class="col-xs-3">
|
||||
<p>{{ $subscriber->email }}</p>
|
||||
</div>
|
||||
<div class="col-xs-3">
|
||||
<p>{{ $subscriber->created_at->format('Y-m-d H:i:s') }}</p>
|
||||
</div>
|
||||
<div class="col-xs-3">
|
||||
@if(is_null($subscriber->verified_at))
|
||||
<b class="text-danger">{{ trans('dashboard.subscribers.not_verified') }}</b>
|
||||
@else
|
||||
<b class="text-success">{{ trans('dashboard.subscribers.verified') }}</b>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-xs-3 text-right">
|
||||
<a href="/dashboard/subscribers/{{ $subscriber->id }}/delete" class="btn btn-danger confirm-action" data-method='DELETE'>{{ trans('forms.delete') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@stop
|
||||
@@ -63,6 +63,14 @@
|
||||
<span>{{ trans('dashboard.metrics.metrics') }}</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li {{ set_active('dashboard/subscribers*') }}>
|
||||
<a href="{{ route('dashboard.subscribers') }}">
|
||||
<i class="icons ion-email"></i>
|
||||
<span>{{ trans('dashboard.subscribers.subscribers') }}</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li {{ set_active('dashboard/settings*') }}>
|
||||
<a href="{{ route('dashboard.settings.setup') }}">
|
||||
<i class="icon ion-gear-a"></i>
|
||||
|
||||
Reference in New Issue
Block a user