fix: make pushover settings more clear

- Rename User to User Key
- Rename Token to API Token
- fix: helper and docs links
This commit is contained in:
peaklabs-dev
2024-12-11 19:18:39 +01:00
parent ebfc8a1094
commit 92fec9582c
6 changed files with 38 additions and 40 deletions

View File

@@ -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) {

View File

@@ -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',
@@ -33,8 +33,8 @@ class PushoverNotificationSettings extends Model
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',

View File

@@ -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;
@@ -160,8 +160,8 @@ class Team extends Model implements SendsDiscord, SendsEmail, SendsSlack, SendsP
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),
];
}

View File

@@ -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);
}
}

View File

@@ -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');
}
};

View File

@@ -23,12 +23,12 @@
<div class="w-32">
<x-forms.checkbox instantSave="instantSavePushoverEnabled" id="pushoverEnabled" label="Enabled" />
</div>
<x-forms.input type="text"
helper="Get your user key in Pushover.<br><a href='https://pushover.net' target='_blank'>Pushover</a>" required
id="pushoverUser" label="User" />
<x-forms.input type="password"
helper="Generate a token in Pushover.<br>Example: https://pushover.net/apps/build/...." required
id="pushoverToken" label="Token" />
helper="Get your User Key in Pushover. You need to be logged in to Pushover to see your user key in the top right corner. <br><a class='inline-block underline dark:text-white' href='https://pushover.net/' target='_blank'>Pushover Dashboard</a>" required
id="pushoverUserKey" label="User Key" />
<x-forms.input type="password"
helper="Generate an API Token/Key in Pushover by creating a new application. <br><a class='inline-block underline dark:text-white' href='https://pushover.net/apps/build' target='_blank'>Create Pushover Application</a>" required
id="pushoverApiToken" label="API Token" />
</form>
<h2 class="mt-4">Notification Settings</h2>
<p class="mb-4">