wip
This commit is contained in:
@@ -7,7 +7,7 @@ use Spatie\LaravelData\Data;
|
||||
class SmtpConfiguration extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public bool $smtp_active = false,
|
||||
public bool $smtp_enabled = false,
|
||||
public string $smtp_host,
|
||||
public int $smtp_port,
|
||||
public ?string $smtp_encryption,
|
||||
|
||||
@@ -2,31 +2,28 @@
|
||||
|
||||
namespace App\Http\Livewire\Notifications;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\Team;
|
||||
use App\Notifications\Notifications\TestNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Livewire\Component;
|
||||
|
||||
class DiscordSettings extends Component
|
||||
{
|
||||
public Team $model;
|
||||
|
||||
protected $rules = [
|
||||
'model.extra_attributes.discord_active' => 'nullable|boolean',
|
||||
'model.extra_attributes.discord_webhook' => 'required|url',
|
||||
'model.extra_attributes.discord_enabled' => 'nullable|boolean',
|
||||
'model.extra_attributes.discord_webhook_url' => 'required|url',
|
||||
'model.extra_attributes.notifications_discord_test' => 'nullable|boolean',
|
||||
'model.extra_attributes.notifications_discord_deployments' => 'nullable|boolean',
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
'model.extra_attributes.discord_webhook' => 'Discord Webhook',
|
||||
'model.extra_attributes.discord_webhook_url' => 'Discord Webhook',
|
||||
];
|
||||
public function instantSave()
|
||||
{
|
||||
try {
|
||||
$this->submit();
|
||||
} catch (\Exception $e) {
|
||||
$this->model->extra_attributes->discord_active = false;
|
||||
$this->model->extra_attributes->discord_enabled = false;
|
||||
$this->validate();
|
||||
}
|
||||
}
|
||||
@@ -46,6 +43,7 @@ class DiscordSettings extends Component
|
||||
}
|
||||
public function sendTestNotification()
|
||||
{
|
||||
Notification::send($this->model, new TestNotification);
|
||||
$this->model->notify(new TestNotification('discord'));
|
||||
$this->emit('success', 'Test notification sent.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Http\Livewire\Notifications;
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\Team;
|
||||
use App\Notifications\Notifications\TestNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Livewire\Component;
|
||||
|
||||
class EmailSettings extends Component
|
||||
@@ -13,7 +12,7 @@ class EmailSettings extends Component
|
||||
public Team $model;
|
||||
|
||||
protected $rules = [
|
||||
'model.extra_attributes.smtp_active' => 'nullable|boolean',
|
||||
'model.extra_attributes.smtp_enabled' => 'nullable|boolean',
|
||||
'model.extra_attributes.smtp_from_address' => 'required|email',
|
||||
'model.extra_attributes.smtp_from_name' => 'required',
|
||||
'model.extra_attributes.smtp_recipients' => 'nullable',
|
||||
@@ -24,7 +23,7 @@ class EmailSettings extends Component
|
||||
'model.extra_attributes.smtp_password' => 'nullable',
|
||||
'model.extra_attributes.smtp_timeout' => 'nullable',
|
||||
'model.extra_attributes.smtp_test_recipients' => 'nullable',
|
||||
'model.extra_attributes.notifications_email_test' => 'nullable|boolean',
|
||||
'model.extra_attributes.notifications_smtp_test' => 'nullable|boolean',
|
||||
'model.extra_attributes.notifications_email_deployments' => 'nullable|boolean',
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
@@ -41,7 +40,7 @@ class EmailSettings extends Component
|
||||
public function copySMTP()
|
||||
{
|
||||
$settings = InstanceSettings::get();
|
||||
$this->model->extra_attributes->smtp_active = true;
|
||||
$this->model->extra_attributes->smtp_enabled = true;
|
||||
$this->model->extra_attributes->smtp_from_address = $settings->extra_attributes->smtp_from_address;
|
||||
$this->model->extra_attributes->smtp_from_name = $settings->extra_attributes->smtp_from_name;
|
||||
$this->model->extra_attributes->smtp_recipients = $settings->extra_attributes->smtp_recipients;
|
||||
@@ -72,7 +71,7 @@ class EmailSettings extends Component
|
||||
}
|
||||
public function sendTestNotification()
|
||||
{
|
||||
Notification::send($this->model, new TestNotification);
|
||||
$this->model->notify(new TestNotification('smtp'));
|
||||
$this->emit('success', 'Test notification sent.');
|
||||
}
|
||||
public function instantSave()
|
||||
@@ -80,7 +79,7 @@ class EmailSettings extends Component
|
||||
try {
|
||||
$this->submit();
|
||||
} catch (\Exception $e) {
|
||||
$this->model->extra_attributes->smtp_active = false;
|
||||
$this->model->extra_attributes->smtp_enabled = false;
|
||||
$this->validate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class Email extends Component
|
||||
public InstanceSettings $settings;
|
||||
|
||||
protected $rules = [
|
||||
'settings.extra_attributes.smtp_active' => 'nullable|boolean',
|
||||
'settings.extra_attributes.smtp_enabled' => 'nullable|boolean',
|
||||
'settings.extra_attributes.smtp_host' => 'required',
|
||||
'settings.extra_attributes.smtp_port' => 'required|numeric',
|
||||
'settings.extra_attributes.smtp_encryption' => 'nullable',
|
||||
@@ -39,7 +39,7 @@ class Email extends Component
|
||||
try {
|
||||
$this->submit();
|
||||
} catch (\Exception $e) {
|
||||
$this->settings->extra_attributes->smtp_active = false;
|
||||
$this->settings->extra_attributes->smtp_enabled = false;
|
||||
$this->validate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class Team extends Model implements SendsDiscord, SendsEmail
|
||||
|
||||
public function routeNotificationForDiscord()
|
||||
{
|
||||
return $this->extra_attributes->get('discord_webhook');
|
||||
return $this->extra_attributes->get('discord_webhook_url');
|
||||
}
|
||||
public function routeNotificationForEmail(string $attribute = 'smtp_recipients')
|
||||
{
|
||||
|
||||
@@ -34,6 +34,10 @@ class User extends Authenticatable implements SendsEmail
|
||||
$team = [
|
||||
'name' => $user->name . "'s Team",
|
||||
'personal_team' => true,
|
||||
'extra_attributes' => [
|
||||
'notifications_smtp_test' => true,
|
||||
'notifications_discord_test' => true,
|
||||
]
|
||||
];
|
||||
if ($user->id === 0) {
|
||||
$team['id'] = 0;
|
||||
|
||||
@@ -13,7 +13,7 @@ class TransactionalEmailChannel
|
||||
public function send(User $notifiable, Notification $notification): void
|
||||
{
|
||||
$settings = InstanceSettings::get();
|
||||
if ($settings->extra_attributes?->get('smtp_active') !== true) {
|
||||
if ($settings->extra_attributes?->get('smtp_enabled') !== true) {
|
||||
return;
|
||||
}
|
||||
$email = $notifiable->email;
|
||||
|
||||
@@ -44,10 +44,10 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
$channels = [];
|
||||
if ($notifiable->extra_attributes?->get('smtp_active') && $notifiable->extra_attributes?->get('notifications_email_deployments')) {
|
||||
if ($notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_email_deployments')) {
|
||||
$channels[] = EmailChannel::class;
|
||||
}
|
||||
if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) {
|
||||
if ($notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) {
|
||||
$channels[] = DiscordChannel::class;
|
||||
}
|
||||
return $channels;
|
||||
|
||||
@@ -44,10 +44,10 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
$channels = [];
|
||||
if ($notifiable->extra_attributes?->get('smtp_active') && $notifiable->extra_attributes?->get('notifications_email_deployments')) {
|
||||
if ($notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_email_deployments')) {
|
||||
$channels[] = EmailChannel::class;
|
||||
}
|
||||
if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) {
|
||||
if ($notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) {
|
||||
$channels[] = DiscordChannel::class;
|
||||
}
|
||||
return $channels;
|
||||
|
||||
@@ -12,13 +12,18 @@ use Illuminate\Notifications\Notification;
|
||||
class TestNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public string|null $type = null;
|
||||
public function __construct(string|null $type = null)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
$channels = [];
|
||||
if ($notifiable->extra_attributes?->get('smtp_active') && $notifiable->extra_attributes?->get('notifications_email_test')) {
|
||||
if (($this->type === 'smtp' || is_null($this->type)) && $notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_smtp_test')) {
|
||||
$channels[] = EmailChannel::class;
|
||||
}
|
||||
if ($notifiable->extra_attributes?->get('discord_active') && $notifiable->extra_attributes?->get('notifications_discord_test')) {
|
||||
if (($this->type === 'discord' || is_null($this->type)) && $notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_test')) {
|
||||
$channels[] = DiscordChannel::class;
|
||||
}
|
||||
return $channels;
|
||||
|
||||
Reference in New Issue
Block a user