mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Clean up code.
This commit is contained in:
@@ -25,7 +25,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\User;
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Support\Notifications\UrlValidator;
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
@@ -52,58 +52,55 @@ class BillReminder extends Notification
|
||||
}
|
||||
|
||||
|
||||
public function toArray($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toArray(User $notifiable)
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toMail($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toMail(User $notifiable)
|
||||
{
|
||||
$subject = (string)trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||
$subject = (string) trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||
if (0 === $this->diff) {
|
||||
$subject = (string)trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||
$subject = (string) trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||
}
|
||||
|
||||
return (new MailMessage())
|
||||
->markdown('emails.bill-warning', ['field' => $this->field, 'diff' => $this->diff, 'bill' => $this->bill])
|
||||
->subject($subject)
|
||||
;
|
||||
->subject($subject);
|
||||
}
|
||||
|
||||
|
||||
public function toSlack($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toSlack(User $notifiable)
|
||||
{
|
||||
$message = (string)trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||
$message = (string) trans(sprintf('email.bill_warning_subject_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||
if (0 === $this->diff) {
|
||||
$message = (string)trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||
$message = (string) trans(sprintf('email.bill_warning_subject_now_%s', $this->field), ['diff' => $this->diff, 'name' => $this->bill->name]);
|
||||
}
|
||||
$bill = $this->bill;
|
||||
$url = route('bills.show', [$bill->id]);
|
||||
$bill = $this->bill;
|
||||
$url = route('bills.show', [$bill->id]);
|
||||
|
||||
return (new SlackMessage())
|
||||
->warning()
|
||||
->attachment(static function ($attachment) use ($bill, $url): void {
|
||||
$attachment->title((string)trans('firefly.visit_bill', ['name' => $bill->name]), $url);
|
||||
$attachment->title((string) trans('firefly.visit_bill', ['name' => $bill->name]), $url);
|
||||
})
|
||||
->content($message)
|
||||
;
|
||||
->content($message);
|
||||
}
|
||||
|
||||
|
||||
public function via($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function via(User $notifiable)
|
||||
{
|
||||
/** @var null|User $user */
|
||||
$user = auth()->user();
|
||||
$slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (is_array($slackUrl)) {
|
||||
$slackUrl = '';
|
||||
}
|
||||
if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {
|
||||
return ['mail', 'slack'];
|
||||
}
|
||||
|
||||
return ['mail'];
|
||||
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Notifications\User;
|
||||
|
||||
use FireflyIII\Support\Notifications\UrlValidator;
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
@@ -42,40 +42,35 @@ class NewAccessToken extends Notification
|
||||
public function __construct() {}
|
||||
|
||||
|
||||
public function toArray($notifiable)
|
||||
public function toArray(User $notifiable)
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toMail($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toMail(User $notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('emails.token-created')
|
||||
->subject((string)trans('email.access_token_created_subject'))
|
||||
;
|
||||
->subject((string) trans('email.access_token_created_subject'));
|
||||
}
|
||||
|
||||
|
||||
public function toSlack($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toSlack(User $notifiable)
|
||||
{
|
||||
return (new SlackMessage())->content((string)trans('email.access_token_created_body'));
|
||||
return (new SlackMessage())->content((string) trans('email.access_token_created_body'));
|
||||
}
|
||||
|
||||
|
||||
public function via($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function via(User $notifiable)
|
||||
{
|
||||
/** @var null|User $user */
|
||||
$user = auth()->user();
|
||||
$slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (is_array($slackUrl)) {
|
||||
$slackUrl = '';
|
||||
}
|
||||
if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {
|
||||
return ['mail', 'slack'];
|
||||
}
|
||||
|
||||
return ['mail'];
|
||||
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
|
||||
}
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Notifications\User;
|
||||
|
||||
use FireflyIII\Support\Notifications\UrlValidator;
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
@@ -47,22 +47,26 @@ class RuleActionFailed extends Notification
|
||||
public function __construct(array $params)
|
||||
{
|
||||
[$mainMessage, $groupTitle, $groupLink, $ruleTitle, $ruleLink] = $params;
|
||||
$this->message = $mainMessage;
|
||||
$this->groupTitle = $groupTitle;
|
||||
$this->groupLink = $groupLink;
|
||||
$this->ruleTitle = $ruleTitle;
|
||||
$this->ruleLink = $ruleLink;
|
||||
$this->message = $mainMessage;
|
||||
$this->groupTitle = $groupTitle;
|
||||
$this->groupLink = $groupLink;
|
||||
$this->ruleTitle = $ruleTitle;
|
||||
$this->ruleLink = $ruleLink;
|
||||
}
|
||||
|
||||
|
||||
public function toArray($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toArray(User $notifiable)
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toSlack($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toSlack(User $notifiable)
|
||||
{
|
||||
$groupTitle = $this->groupTitle;
|
||||
$groupLink = $this->groupLink;
|
||||
@@ -70,28 +74,19 @@ class RuleActionFailed extends Notification
|
||||
$ruleLink = $this->ruleLink;
|
||||
|
||||
return (new SlackMessage())->content($this->message)->attachment(static function ($attachment) use ($groupTitle, $groupLink): void {
|
||||
$attachment->title((string)trans('rules.inspect_transaction', ['title' => $groupTitle]), $groupLink);
|
||||
$attachment->title((string) trans('rules.inspect_transaction', ['title' => $groupTitle]), $groupLink);
|
||||
})->attachment(static function ($attachment) use ($ruleTitle, $ruleLink): void {
|
||||
$attachment->title((string)trans('rules.inspect_rule', ['title' => $ruleTitle]), $ruleLink);
|
||||
$attachment->title((string) trans('rules.inspect_rule', ['title' => $ruleTitle]), $ruleLink);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function via($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function via(User $notifiable)
|
||||
{
|
||||
/** @var null|User $user */
|
||||
$user = auth()->user();
|
||||
$slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (is_array($slackUrl)) {
|
||||
$slackUrl = '';
|
||||
}
|
||||
if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {
|
||||
app('log')->debug('Will send ruleActionFailed through Slack or Discord!');
|
||||
|
||||
return ['slack'];
|
||||
}
|
||||
app('log')->debug('Will NOT send ruleActionFailed through Slack or Discord');
|
||||
|
||||
return [];
|
||||
// todo disable mail channel
|
||||
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Notifications\User;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
@@ -43,25 +45,33 @@ class TransactionCreation extends Notification
|
||||
$this->collection = $collection;
|
||||
}
|
||||
|
||||
|
||||
public function toArray($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toArray(User $notifiable)
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
|
||||
public function toMail($notifiable)
|
||||
public function toMail(User $notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('emails.report-new-journals', ['transformed' => $this->collection])
|
||||
->subject(trans_choice('email.new_journals_subject', count($this->collection)))
|
||||
;
|
||||
->subject(trans_choice('email.new_journals_subject', count($this->collection)));
|
||||
}
|
||||
|
||||
|
||||
public function via($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function via(User $notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
// todo only over email?
|
||||
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\User;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Support\Notifications\UrlValidator;
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
@@ -48,16 +48,18 @@ class UserLogin extends Notification
|
||||
}
|
||||
|
||||
|
||||
public function toArray($notifiable)
|
||||
public function toArray(User $notifiable)
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toMail($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toMail(User $notifiable)
|
||||
{
|
||||
$time = now(config('app.timezone'))->isoFormat((string)trans('config.date_time_js'));
|
||||
$time = now(config('app.timezone'))->isoFormat((string) trans('config.date_time_js'));
|
||||
$host = '';
|
||||
|
||||
try {
|
||||
@@ -72,12 +74,13 @@ class UserLogin extends Notification
|
||||
|
||||
return (new MailMessage())
|
||||
->markdown('emails.new-ip', ['time' => $time, 'ipAddress' => $this->ip, 'host' => $host])
|
||||
->subject((string)trans('email.login_from_new_ip'))
|
||||
;
|
||||
->subject((string) trans('email.login_from_new_ip'));
|
||||
}
|
||||
|
||||
|
||||
public function toSlack($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toSlack(User $notifiable)
|
||||
{
|
||||
$host = '';
|
||||
|
||||
@@ -91,22 +94,14 @@ class UserLogin extends Notification
|
||||
$host = $hostName;
|
||||
}
|
||||
|
||||
return (new SlackMessage())->content((string)trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));
|
||||
return (new SlackMessage())->content((string) trans('email.slack_login_from_new_ip', ['host' => $host, 'ip' => $this->ip]));
|
||||
}
|
||||
|
||||
|
||||
public function via($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function via(User $notifiable)
|
||||
{
|
||||
/** @var null|User $user */
|
||||
$user = auth()->user();
|
||||
$slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (is_array($slackUrl)) {
|
||||
$slackUrl = '';
|
||||
}
|
||||
if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {
|
||||
return ['mail', 'slack'];
|
||||
}
|
||||
|
||||
return ['mail'];
|
||||
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Notifications\User;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
@@ -43,25 +45,30 @@ class UserNewPassword extends Notification
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
|
||||
public function toArray($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toArray(User $notifiable)
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toMail($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toMail(User $notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('emails.password', ['url' => $this->url])
|
||||
->subject((string)trans('email.reset_pw_subject'))
|
||||
;
|
||||
->subject((string) trans('email.reset_pw_subject'));
|
||||
}
|
||||
|
||||
|
||||
public function via($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function via(User $notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Notifications\User;
|
||||
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
@@ -38,25 +40,30 @@ class UserRegistration extends Notification
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
|
||||
public function toArray($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toArray(User $notifiable)
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toMail($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toMail(User $notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('emails.registered', ['address' => route('index')])
|
||||
->subject((string)trans('email.registered_subject'))
|
||||
;
|
||||
->subject((string) trans('email.registered_subject'));
|
||||
}
|
||||
|
||||
|
||||
public function via($notifiable)
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function via(User $notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user