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

Add bugsnag support for errors #20

Merged
merged 6 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -42,3 +42,7 @@ PLAID_CLIENT_ID=

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

SLACK_WEBHOOK_URL=
DISCORD_WEBHOOK_URL=

34 changes: 6 additions & 28 deletions app/Console/Commands/GenerateChannelsAndAlertsFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,32 @@ class GenerateChannelsAndAlertsFile extends Command
*/
protected $description = 'Build channels and alerts.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->writeToDisk('js/channels.js', [
[
'type' => SlackWebhookChannel::class,
'name' => 'Slack',
'service' => 'webhook',
'type' => SlackWebhookChannel::class,
],
[
'type' => DiscordChannel::class,
'name' => 'Discord',
'service' => 'webhook',
'type' => DiscordChannel::class,
],
[
'type' => WebhookChannel::class,
'name' => 'Webhook',
'service' => 'webhook',
'type' => WebhookChannel::class,
],
[
'type' => MailChannel::class,
'name' => 'Email',
'service' => 'email',
'type' => MailChannel::class,
],
[
'type' => NexmoSmsChannel::class,
'name' => 'Nexmo',
'service' => 'sms'
'type' => NexmoSmsChannel::class,
],
[
// BroadcastChannel::class
'type' => DatabaseChannel::class,
'name' => 'In-site notification',
'service' => 'in-site'
'type' => DatabaseChannel::class,
],
]);

Expand Down
6 changes: 6 additions & 0 deletions app/Http/Controllers/Api/AbstractResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Http\Controllers\Api;

use App\FailedJob;
use App\Http\Controllers\Controller;
use App\Models\Transaction;
use Exception;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
Expand Down Expand Up @@ -37,6 +39,10 @@ public function index(IndexRequest $request, AbstractEloquentModel $model)
->allowedIncludes($model->getAbstractAllowedRelationships())
->allowedSorts($model->getAbstractAllowedSorts());

if (!in_array(get_class($model), [FailedJob::class, Transaction::class])) {
$query->where('user_id', auth()->id());
}

return $this->json($action->execute($query));
}

Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Api/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function index(IndexRequest $request)
Filter::scope('q')
]))
->allowedIncludes($model->getAbstractAllowedRelationships())
->allowedSorts($model->getAbstractAllowedSorts());
->allowedSorts($model->getAbstractAllowedSorts())
->whereIn('access_token_id', $request->user()->accessTokens->map->id);

return $this->json($action->execute($query));
}
Expand All @@ -56,6 +57,7 @@ public function show(ViewRequest $request, Account $model)
->allowedFilters($model->getAbstractAllowedFilters())
->allowedIncludes($model->getAbstractAllowedRelationships())
->allowedSorts($model->getAbstractAllowedSorts())
->whereIn('access_token_id', $request->user()->accessTokens->map->id)
->find($model->id);

if (empty($result)) {
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Api/AlertController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function index(IndexRequest $request)
Filter::scope('q')
]))
->allowedIncludes($model->getAbstractAllowedRelationships())
->allowedSorts($model->getAbstractAllowedSorts());
->allowedSorts($model->getAbstractAllowedSorts())
->where('user_id', auth()->id());

return $this->json($action->execute($query));
}
Expand All @@ -54,6 +55,7 @@ public function show(ViewRequest $request, Alert $model)
->allowedFilters($model->getAbstractAllowedFilters())
->allowedIncludes($model->getAbstractAllowedRelationships())
->allowedSorts($model->getAbstractAllowedSorts())
->where('user_id', auth()->id())
->find($model->id);

if (empty($result)) {
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Api/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function index(IndexRequest $request)
Filter::scope('q')
]))
->allowedIncludes($model->getAbstractAllowedRelationships())
->allowedSorts($model->getAbstractAllowedSorts());
->allowedSorts($model->getAbstractAllowedSorts())
->where('user_id', auth()->id());

return $this->json($action->execute($query));
}
Expand All @@ -63,6 +64,7 @@ public function show(ViewRequest $request, Tag $model)
->allowedFilters($model->getAbstractAllowedFilters())
->allowedIncludes($model->getAbstractAllowedRelationships())
->allowedSorts($model->getAbstractAllowedSorts())
->where('user_id', auth()->id())
->find($model->id);

if (empty($result)) {
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/Api/TransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function index(IndexRequest $request)
Filter::scope('q')
]))
->allowedIncludes($model->getAbstractAllowedRelationships())
->allowedSorts($model->getAbstractAllowedSorts());
->allowedSorts($model->getAbstractAllowedSorts())
->whereHas('account', function ($query) use ($request) {
$query->whereIn('access_token_id', $request->user()->accessTokens->map->id);
});

return $this->json($action->execute($query));
}
Expand Down
9 changes: 7 additions & 2 deletions app/Listeners/CreateDefaultAlertsForUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ class CreateDefaultAlertsForUser
TransactionCreated::class,
],
'channels' => [
MailChannel::class,
DatabaseChannel::class,
]
],
[
'name' => 'Bill paid!',
'title' => 'You just paid your {{ transaction.name }} {{ tag.name }}!',
'title' => 'You just paid your {{ transaction.name }} {{ tag.name.en }}!',
'body' => 'This time around, you paid ${{ transaction.amount }}.',
'conditions' => [
[
Expand All @@ -53,7 +54,7 @@ class CreateDefaultAlertsForUser
],
[
'name' => 'Subscription paid!',
'title' => 'You just paid your {{ transaction.name }} {{ tag.name }}!',
'title' => 'You just paid your {{ transaction.name }} {{ tag.name.en }}!',
'body' => 'This time around, you paid ${{ transaction.amount }}.',
'conditions' => [
[
Expand Down Expand Up @@ -93,6 +94,10 @@ public function handle(Registered $event)
$conditions = $alertInfo['conditions'];
unset($alertInfo['conditions']);

if (isset($alertInfo['channels'][MailChannel::class]) && isset($alertInfo['channels'][MailChannel::class]['fields']['to'])) {
$alertInfo['channels'][MailChannel::class]['fields']['to'] = $user->email;
}

/** @var Alert $alert */
$alert = $user->alerts()->create($alertInfo);
foreach ($conditions as $condition) {
Expand Down
9 changes: 5 additions & 4 deletions app/Notifications/AlertNotiffication.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ protected function render($string, $data)

public function routeNotificationForDiscord()
{
return $this->alertLog->alert->messaging_service_channel;
return config('services.discord_webhook_url');
}

public function routeNotificationForSlack($notification)
{
return $this->alertLog->alert->webhook_url;
return config('services.slack_webhook_url');
}

public function toMail($notifiable)
Expand All @@ -80,9 +80,10 @@ public function toSlack($notifiable)
->warning();
}

public function toDiscord()
public function toDiscord($notifiable)
{
return new DiscordMessage(sprintf('We saw you were charged $%s by %s to your account %s', $this->alertLog->transaction->amount, $this->alertLog->transaction->name, $this->alertLog->transaction->account->name));
return (new DiscordMessage)
->body(sprintf('We saw you were charged $%s by %s to your account %s', $this->alertLog->transaction->amount, $this->alertLog->transaction->name, $this->alertLog->transaction->account->name));
}

public function toWebhook($notifiable)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"require": {
"php": "^7.4",
"barryvdh/laravel-debugbar": "^3.3",
"bugsnag/bugsnag-laravel": "^2.0",
"doctrine/dbal": "^2.9",
"fideloper/proxy": "^4.2",
"firebase/php-jwt": "^5.0",
Expand Down
Loading