Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications #2295

Merged
merged 27 commits into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
056b80a
Require Nexmo dependency
jbrooksuk Dec 29, 2016
b8a9f41
Integrate Mail, Nexmo and Slack notifications into Cachet
jbrooksuk Dec 30, 2016
4ab133c
Remove redundant email layout
jbrooksuk Jan 2, 2017
e8ce42b
Publish the notifications table
jbrooksuk Jan 3, 2017
ce577fb
Include unsubscribe link in Slack footer
jbrooksuk Jan 3, 2017
42f3350
Apply theme composer to emails too
jbrooksuk Jan 3, 2017
51864f3
Don't need to have notifications enabled for Slack etc...
jbrooksuk Jan 3, 2017
6dc56de
Add unsub links to all Slack notifications
jbrooksuk Jan 3, 2017
2da2ab8
Apply fixes from StyleCI
jbrooksuk Jan 3, 2017
f1ac112
Remove CSS inline
jbrooksuk Jan 4, 2017
f03d557
Be sure to make email nullable
jbrooksuk Jan 4, 2017
3ff497c
Re-enable Bootstrap close component
jbrooksuk Jan 4, 2017
1116262
Rebuild assets
jbrooksuk Jan 4, 2017
4334bab
Re-enable the Bootstrap labels components
jbrooksuk Jan 4, 2017
87ed6f0
Rebuilt assets
jbrooksuk Jan 4, 2017
a77c03d
Don't use status
jbrooksuk Jan 4, 2017
a7f06b5
Don't use status
jbrooksuk Jan 4, 2017
38773c8
Update all email notifications
jbrooksuk Jan 4, 2017
1b5ddc6
Update subscriber model
jbrooksuk Jan 4, 2017
c20a66e
Fix tests
jbrooksuk Jan 4, 2017
12b93e1
Use each instead of map
jbrooksuk Jan 4, 2017
a003fce
Expect events for auto-verifying subscribers
jbrooksuk Jan 4, 2017
4d89119
Use each and always fire the event
jbrooksuk Jan 4, 2017
49dac9b
Add rules to subscriber
jbrooksuk Jan 4, 2017
a38acf1
IncidentUpdateWasReportedEvent has handlers
jbrooksuk Jan 4, 2017
1e9161c
Fake notifications
jbrooksuk Jan 4, 2017
7269dd1
More test fixes
jbrooksuk Jan 4, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ REDIS_DATABASE=null
REDIS_PORT=null

GITHUB_TOKEN=null

NEXMO_KEY=null
NEXMO_SECRET=null
NEXMO_SMS_FROM=Cachet
41 changes: 0 additions & 41 deletions app/Bus/Commands/System/Mail/TestMailCommand.php

This file was deleted.

11 changes: 10 additions & 1 deletion app/Bus/Events/Incident/IncidentWasReportedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ final class IncidentWasReportedEvent implements IncidentEventInterface
*/
public $incident;

/**
* Whether to notify that the incident was reported.
*
* @var bool
*/
public $notify;

/**
* Create a new incident has reported event instance.
*
* @param \CachetHQ\Cachet\Models\Incident $incident
* @param bool $notify
*
* @return void
*/
public function __construct(Incident $incident)
public function __construct(Incident $incident, $notify)
{
$this->incident = $incident;
$this->notify = $notify;
}
}
50 changes: 50 additions & 0 deletions app/Bus/Events/User/UserAcceptedInviteEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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 accepted invite event class.
*
* @author James Brooks <[email protected]>
*/
final class UserAcceptedInviteEvent implements UserEventInterface
{
/**
* The user that accepted the invite.
*
* @var \CachetHQ\Cachet\Models\User
*/
public $user;

/**
* The invite that the user accepted.
*
* @var \CachetHQ\Cachet\Models\Invite
*/
public $invite;

/**
* Create a new user accepted invite event class.
*
* @param \CachetHQ\Cachet\Models\User $user
* @param \CachetHQ\Cachet\Models\Invite $invite
*
* @return void
*/
public function __construct(User $user, Invite $invite)
{
$this->user = $user;
$this->invite = $invite;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ public function handle(ReportIncidentCommand $command)
));
}

$incident->update(['notify' => (bool) $command->notify]);

event(new IncidentWasReportedEvent($incident));
event(new IncidentWasReportedEvent($incident, (bool) $command->notify));

return $incident;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Models\Subscription;
use CachetHQ\Cachet\Notifications\Subscriber\VerifySubscriptionNotification;

/**
* This is the subscribe subscriber command handler.
Expand Down Expand Up @@ -59,6 +60,8 @@ public function handle(SubscribeSubscriberCommand $command)
if ($command->verified) {
dispatch(new VerifySubscriberCommand($subscriber));
} else {
$subscriber->notify(new VerifySubscriptionNotification());

event(new SubscriberHasSubscribedEvent($subscriber));
}

Expand Down
64 changes: 0 additions & 64 deletions app/Bus/Handlers/Commands/System/Mail/TestMailCommandHandler.php

This file was deleted.

3 changes: 3 additions & 0 deletions app/Bus/Handlers/Commands/User/InviteUserCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use CachetHQ\Cachet\Bus\Commands\User\InviteUserCommand;
use CachetHQ\Cachet\Bus\Events\User\UserWasInvitedEvent;
use CachetHQ\Cachet\Models\Invite;
use CachetHQ\Cachet\Notifications\User\InviteUserNotification;

/**
* This is the invite user command handler.
Expand All @@ -36,6 +37,8 @@ public function handle(InviteUserCommand $command)
'email' => $email,
]);

$invite->notify(new InviteUserNotification());

event(new UserWasInvitedEvent($invite));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@
use CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasUpdatedEvent;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Subscriber;
use Illuminate\Contracts\Mail\MailQueue;
use McCool\LaravelAutoPresenter\Facades\AutoPresenter;
use CachetHQ\Cachet\Notifications\Component\ComponentStatusChangedNotification;

class SendComponentUpdateEmailNotificationHandler
{
/**
* The mailer instance.
*
* @var \Illuminate\Contracts\Mail\Mailer
*/
protected $mailer;

/**
* The subscriber instance.
*
Expand All @@ -36,14 +28,12 @@ class SendComponentUpdateEmailNotificationHandler
/**
* Create a new send incident email notification handler.
*
* @param \Illuminate\Contracts\Mail\Mailer $mailer
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
*
* @return void
*/
public function __construct(MailQueue $mailer, Subscriber $subscriber)
public function __construct(Subscriber $subscriber)
{
$this->mailer = $mailer;
$this->subscriber = $subscriber;
}

Expand All @@ -66,9 +56,9 @@ public function handle(ComponentStatusWasUpdatedEvent $event)
// First notify all global subscribers.
$globalSubscribers = $this->subscriber->isVerified()->isGlobal()->get();

foreach ($globalSubscribers as $subscriber) {
$this->notify($component, $subscriber);
}
$globalSubscribers->map(function ($subscriber) use ($component, $event) {
$subscriber->notify(new ComponentStatusChangedNotification($component, $event->new_status));
});

$notified = $globalSubscribers->pluck('id')->all();

Expand All @@ -81,37 +71,8 @@ public function handle(ComponentStatusWasUpdatedEvent $event)
return in_array($subscriber->id, $notified);
});

foreach ($componentSubscribers as $subscriber) {
$this->notify($component, $subscriber);
}
}

/**
* Send notification to subscriber.
*
* @param \CachetHQ\Cachet\Models\Component $component
* @param \CachetHQ\Cachet\Models\Subscriber $subscriber
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function notify(Component $component, Subscriber $subscriber)
{
$component = AutoPresenter::decorate($component);

$mail = [
'subject' => trans('cachet.subscriber.email.component.subject'),
'component_name' => $component->name,
'component_human_status' => $component->human_status,
];

$mail['email'] = $subscriber->email;
$mail['manage_link'] = cachet_route('subscribe.manage', [$subscriber->verify_code]);

$this->mailer->queue([
'html' => 'emails.components.update-html',
'text' => 'emails.components.update-text',
], $mail, function ($message) use ($mail) {
$message->to($mail['email'])->subject($mail['subject']);
$componentSubscribers->map(function ($subscriber) use ($component, $event) {
$subscriber->notify(new ComponentStatusChangedNotification($component, $event->new_status));
});
}
}
Loading