diff --git a/app/Livewire/Notifications/Pushover.php b/app/Livewire/Notifications/Pushover.php index 7a3b294a2..2e8205f5e 100644 --- a/app/Livewire/Notifications/Pushover.php +++ b/app/Livewire/Notifications/Pushover.php @@ -18,10 +18,10 @@ class Pushover extends Component public bool $pushoverEnabled = false; #[Validate(['string', 'nullable'])] - public ?string $pushoverToken = null; - + public ?string $pushoverUserKey = null; + #[Validate(['string', 'nullable'])] - public ?string $pushoverUser = null; + public ?string $pushoverApiToken = null; #[Validate(['boolean'])] public bool $deploymentSuccessPushoverNotifications = false; @@ -59,7 +59,6 @@ class Pushover extends Component #[Validate(['boolean'])] public bool $serverUnreachablePushoverNotifications = true; - public function mount() { try { @@ -76,8 +75,8 @@ class Pushover extends Component if ($toModel) { $this->validate(); $this->settings->pushover_enabled = $this->pushoverEnabled; - $this->settings->pushover_user = $this->pushoverUser; - $this->settings->pushover_token = $this->pushoverToken; + $this->settings->pushover_user_key_key = $this->pushoverUserKey; + $this->settings->pushover_api_token = $this->pushoverApiToken; $this->settings->deployment_success_pushover_notifications = $this->deploymentSuccessPushoverNotifications; $this->settings->deployment_failure_pushover_notifications = $this->deploymentFailurePushoverNotifications; @@ -96,8 +95,8 @@ class Pushover extends Component refreshSession(); } else { $this->pushoverEnabled = $this->settings->pushover_enabled; - $this->pushoverUser = $this->settings->pushover_user; - $this->pushoverToken = $this->settings->pushover_token; + $this->pushoverUserKey = $this->settings->pushover_user_key_key; + $this->pushoverApiToken = $this->settings->pushover_api_token; $this->deploymentSuccessPushoverNotifications = $this->settings->deployment_success_pushover_notifications; $this->deploymentFailurePushoverNotifications = $this->settings->deployment_failure_pushover_notifications; @@ -118,11 +117,11 @@ class Pushover extends Component { try { $this->validate([ - 'pushoverUser' => 'required', - 'pushoverToken' => 'required', + 'pushoverUserKey' => 'required', + 'pushoverApiToken' => 'required', ], [ - 'pushoverUser.required' => 'Pushover User is required.', - 'pushoverToken.required' => 'Pushover Token is required.', + 'pushoverUserKey.required' => 'Pushover User Key is required.', + 'pushoverApiToken.required' => 'Pushover API Token is required.', ]); $this->saveModel(); } catch (\Throwable $e) { diff --git a/app/Models/PushoverNotificationSettings.php b/app/Models/PushoverNotificationSettings.php index 7576a6040..7deeadedc 100644 --- a/app/Models/PushoverNotificationSettings.php +++ b/app/Models/PushoverNotificationSettings.php @@ -15,8 +15,8 @@ class PushoverNotificationSettings extends Model 'team_id', 'pushover_enabled', - 'pushover_user', - 'pushover_token', + 'pushover_user_key_key', + 'pushover_api_token', 'deployment_success_pushover_notifications', 'deployment_failure_pushover_notifications', @@ -29,12 +29,12 @@ class PushoverNotificationSettings extends Model 'server_disk_usage_pushover_notifications', 'server_reachable_pushover_notifications', 'server_unreachable_pushover_notifications', - ]; + ]; protected $casts = [ 'pushover_enabled' => 'boolean', - 'pushover_user' => 'encrypted', - 'pushover_token' => 'encrypted', + 'pushover_user_key_key' => 'encrypted', + 'pushover_api_token' => 'encrypted', 'deployment_success_pushover_notifications' => 'boolean', 'deployment_failure_pushover_notifications' => 'boolean', diff --git a/app/Models/Team.php b/app/Models/Team.php index fc10892a4..174137840 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -4,8 +4,8 @@ namespace App\Models; use App\Notifications\Channels\SendsDiscord; use App\Notifications\Channels\SendsEmail; -use App\Notifications\Channels\SendsSlack; use App\Notifications\Channels\SendsPushover; +use App\Notifications\Channels\SendsSlack; use App\Traits\HasNotificationSettings; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; @@ -33,7 +33,7 @@ use OpenApi\Attributes as OA; ] )] -class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack, SendsPushover +class Team extends Model implements SendsDiscord, SendsEmail, SendsPushover, SendsSlack { use HasNotificationSettings, Notifiable; @@ -156,12 +156,12 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack, SendsP { return data_get($this, 'slack_webhook_url', null); } - + public function routeNotificationForPushover() { return [ - 'user' => data_get($this, 'pushover_user', null), - 'token' => data_get($this, 'pushover_token', null), + 'user' => data_get($this, 'pushover_user_key_key', null), + 'token' => data_get($this, 'pushover_api_token', null), ]; } @@ -287,7 +287,7 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack, SendsP { return $this->hasOne(SlackNotificationSettings::class); } - + public function pushoverNotificationSettings() { return $this->hasOne(PushoverNotificationSettings::class); diff --git a/app/Notifications/Channels/PushoverChannel.php b/app/Notifications/Channels/PushoverChannel.php index 56d3cb03d..3d3728d01 100644 --- a/app/Notifications/Channels/PushoverChannel.php +++ b/app/Notifications/Channels/PushoverChannel.php @@ -7,15 +7,15 @@ use Illuminate\Notifications\Notification; class PushoverChannel { - public function send(SendsPushover $notifiable, Notification $notification): void - { - $message = $notification->toPushover(); - $pushoverSettings = $notifiable->pushoverNotificationSettings; + public function send(SendsPushover $notifiable, Notification $notification): void + { + $message = $notification->toPushover(); + $pushoverSettings = $notifiable->pushoverNotificationSettings; - if (! $pushoverSettings || ! $pushoverSettings->isEnabled() || ! $pushoverSettings->pushover_user || ! $pushoverSettings->pushover_token) { - return; + if (! $pushoverSettings || ! $pushoverSettings->isEnabled() || ! $pushoverSettings->pushover_user_key || ! $pushoverSettings->pushover_api_token) { + return; + } + + SendMessageToPushoverJob::dispatch($message, $pushoverSettings->pushover_api_token, $pushoverSettings->pushover_user_key); } - - SendMessageToPushoverJob::dispatch($message, $pushoverSettings->pushover_token, $pushoverSettings->pushover_user); - } } diff --git a/database/migrations/2024_12_11_135026_create_pushover_notification_settings_table.php b/database/migrations/2024_12_11_135026_create_pushover_notification_settings_table.php index 907f7a052..8c317d997 100644 --- a/database/migrations/2024_12_11_135026_create_pushover_notification_settings_table.php +++ b/database/migrations/2024_12_11_135026_create_pushover_notification_settings_table.php @@ -16,8 +16,8 @@ return new class extends Migration $table->foreignId('team_id')->constrained()->cascadeOnDelete(); $table->boolean('pushover_enabled')->default(false); - $table->text('pushover_user')->nullable(); - $table->text('pushover_token')->nullable(); + $table->text('pushover_user_key')->nullable(); + $table->text('pushover_api_token')->nullable(); $table->boolean('deployment_success_pushover_notifications')->default(false); $table->boolean('deployment_failure_pushover_notifications')->default(true); @@ -44,4 +44,3 @@ return new class extends Migration Schema::dropIfExists('pushover_notification_settings'); } }; - diff --git a/resources/views/livewire/notifications/pushover.blade.php b/resources/views/livewire/notifications/pushover.blade.php index 28a55516d..271af5367 100644 --- a/resources/views/livewire/notifications/pushover.blade.php +++ b/resources/views/livewire/notifications/pushover.blade.php @@ -23,12 +23,12 @@