fixes
This commit is contained in:
parent
0aa816b4f2
commit
6e094eaf42
@ -13,11 +13,11 @@ class DiscordSettings extends Component
|
||||
public Team|Server $model;
|
||||
|
||||
protected $rules = [
|
||||
'model.smtp_attributes.discord_active' => 'nullable|boolean',
|
||||
'model.smtp_attributes.discord_webhook' => 'required|url',
|
||||
'model.extra_attributes.discord_active' => 'nullable|boolean',
|
||||
'model.extra_attributes.discord_webhook' => 'required|url',
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
'model.smtp_attributes.discord_webhook' => 'Discord Webhook',
|
||||
'model.extra_attributes.discord_webhook' => 'Discord Webhook',
|
||||
];
|
||||
public function mount($model)
|
||||
{
|
||||
@ -28,8 +28,8 @@ class DiscordSettings extends Component
|
||||
try {
|
||||
$this->submit();
|
||||
} catch (\Exception $e) {
|
||||
$this->model->smtp_attributes->discord_active = false;
|
||||
$this->addError('model.smtp_attributes.discord_webhook', $e->getMessage());
|
||||
$this->model->extra_attributes->discord_active = false;
|
||||
$this->validate();
|
||||
}
|
||||
}
|
||||
private function saveModel()
|
||||
|
@ -13,27 +13,27 @@ class EmailSettings extends Component
|
||||
public Team|Server $model;
|
||||
|
||||
protected $rules = [
|
||||
'model.smtp_attributes.smtp_active' => 'nullable|boolean',
|
||||
'model.smtp_attributes.from_address' => 'required',
|
||||
'model.smtp_attributes.from_name' => 'required',
|
||||
'model.smtp_attributes.recipients' => 'required',
|
||||
'model.smtp_attributes.smtp_host' => 'required',
|
||||
'model.smtp_attributes.smtp_port' => 'required',
|
||||
'model.smtp_attributes.smtp_encryption' => 'nullable',
|
||||
'model.smtp_attributes.smtp_username' => 'nullable',
|
||||
'model.smtp_attributes.smtp_password' => 'nullable',
|
||||
'model.smtp_attributes.smtp_timeout' => 'nullable',
|
||||
'model.smtp_attributes.test_address' => 'nullable',
|
||||
'model.extra_attributes.smtp_active' => 'nullable|boolean',
|
||||
'model.extra_attributes.from_address' => 'required|email',
|
||||
'model.extra_attributes.from_name' => 'required',
|
||||
'model.extra_attributes.recipients' => 'required',
|
||||
'model.extra_attributes.smtp_host' => 'required',
|
||||
'model.extra_attributes.smtp_port' => 'required',
|
||||
'model.extra_attributes.smtp_encryption' => 'nullable',
|
||||
'model.extra_attributes.smtp_username' => 'nullable',
|
||||
'model.extra_attributes.smtp_password' => 'nullable',
|
||||
'model.extra_attributes.smtp_timeout' => 'nullable',
|
||||
'model.extra_attributes.test_notification_email' => 'nullable|email',
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
'model.smtp_attributes.from_address' => 'From Address',
|
||||
'model.smtp_attributes.from_name' => 'From Name',
|
||||
'model.smtp_attributes.recipients' => 'Recipients',
|
||||
'model.smtp_attributes.smtp_host' => 'Host',
|
||||
'model.smtp_attributes.smtp_port' => 'Port',
|
||||
'model.smtp_attributes.smtp_encryption' => 'Encryption',
|
||||
'model.smtp_attributes.smtp_username' => 'Username',
|
||||
'model.smtp_attributes.smtp_password' => 'Password',
|
||||
'model.extra_attributes.from_address' => 'From Address',
|
||||
'model.extra_attributes.from_name' => 'From Name',
|
||||
'model.extra_attributes.recipients' => 'Recipients',
|
||||
'model.extra_attributes.smtp_host' => 'Host',
|
||||
'model.extra_attributes.smtp_port' => 'Port',
|
||||
'model.extra_attributes.smtp_encryption' => 'Encryption',
|
||||
'model.extra_attributes.smtp_username' => 'Username',
|
||||
'model.extra_attributes.smtp_password' => 'Password',
|
||||
];
|
||||
public function mount($model)
|
||||
{
|
||||
@ -54,6 +54,11 @@ class EmailSettings extends Component
|
||||
}
|
||||
public function instantSave()
|
||||
{
|
||||
$this->saveModel();
|
||||
try {
|
||||
$this->submit();
|
||||
} catch (\Exception $e) {
|
||||
$this->model->extra_attributes->smtp_active = false;
|
||||
$this->validate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,22 +23,16 @@ class Server extends BaseModel
|
||||
'team_id',
|
||||
'private_key_id',
|
||||
'extra_attributes',
|
||||
'smtp_attributes',
|
||||
];
|
||||
|
||||
public $casts = [
|
||||
'extra_attributes' => SchemalessAttributes::class,
|
||||
'smtp_attributes' => SchemalessAttributes::class,
|
||||
];
|
||||
|
||||
public function scopeWithExtraAttributes(): Builder
|
||||
{
|
||||
return $this->extra_attributes->modelScope();
|
||||
}
|
||||
public function scopeWithSmtpAttributes(): Builder
|
||||
{
|
||||
return $this->smtp_attributes->modelScope();
|
||||
}
|
||||
|
||||
public function standaloneDockers()
|
||||
{
|
||||
|
@ -13,30 +13,32 @@ class Team extends BaseModel implements SendsDiscord, SendsEmail
|
||||
use Notifiable;
|
||||
|
||||
protected $casts = [
|
||||
'smtp_attributes' => SchemalessAttributes::class,
|
||||
'extra_attributes' => SchemalessAttributes::class,
|
||||
'personal_team' => 'boolean',
|
||||
];
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'personal_team',
|
||||
'smtp_attributes',
|
||||
'extra_attributes',
|
||||
];
|
||||
|
||||
public function routeNotificationForDiscord()
|
||||
{
|
||||
return $this->smtp_attributes->get('discord_webhook');
|
||||
return $this->extra_attributes->get('discord_webhook');
|
||||
}
|
||||
|
||||
public function routeNotificationForEmail(string $attribute = 'recipients')
|
||||
{
|
||||
$recipients = $this->smtp_attributes->get($attribute, '');
|
||||
return explode(PHP_EOL, $recipients);
|
||||
$recipients = $this->extra_attributes->get($attribute, '');
|
||||
if (is_null($recipients) || $recipients === '') {
|
||||
return [];
|
||||
}
|
||||
return explode(',', $recipients);
|
||||
}
|
||||
|
||||
public function scopeWithExtraAttributes(): Builder
|
||||
{
|
||||
return $this->smtp_attributes->modelScope();
|
||||
return $this->extra_attributes->modelScope();
|
||||
}
|
||||
|
||||
public function projects()
|
||||
|
@ -15,8 +15,8 @@ class EmailChannel
|
||||
{
|
||||
$this->bootConfigs($notifiable);
|
||||
if ($notification instanceof \App\Notifications\TestNotification) {
|
||||
$bcc = $notifiable->routeNotificationForEmail('test_address');
|
||||
if (count($bcc) === 1) {
|
||||
$bcc = $notifiable->routeNotificationForEmail('test_notification_email');
|
||||
if (count($bcc) === 0) {
|
||||
$bcc = $notifiable->routeNotificationForEmail();
|
||||
}
|
||||
} else {
|
||||
@ -29,8 +29,8 @@ class EmailChannel
|
||||
[],
|
||||
fn (Message $message) => $message
|
||||
->from(
|
||||
$notifiable->smtp_attributes?->get('from_address'),
|
||||
$notifiable->smtp_attributes?->get('from_name')
|
||||
$notifiable->extra_attributes?->get('from_address'),
|
||||
$notifiable->extra_attributes?->get('from_name')
|
||||
)
|
||||
->cc($bcc)
|
||||
->bcc($bcc)
|
||||
@ -44,12 +44,12 @@ class EmailChannel
|
||||
config()->set('mail.default', 'smtp');
|
||||
config()->set('mail.mailers.smtp', [
|
||||
"transport" => "smtp",
|
||||
"host" => $notifiable->smtp_attributes?->get('smtp_host'),
|
||||
"port" => $notifiable->smtp_attributes?->get('smtp_port'),
|
||||
"encryption" => $notifiable->smtp_attributes?->get('smtp_encryption'),
|
||||
"username" => $notifiable->smtp_attributes?->get('smtp_username'),
|
||||
"password" => $notifiable->smtp_attributes?->get('smtp_password'),
|
||||
"timeout" => $notifiable->smtp_attributes?->get('smtp_timeout'),
|
||||
"host" => $notifiable->extra_attributes?->get('smtp_host'),
|
||||
"port" => $notifiable->extra_attributes?->get('smtp_port'),
|
||||
"encryption" => $notifiable->extra_attributes?->get('smtp_encryption'),
|
||||
"username" => $notifiable->extra_attributes?->get('smtp_username'),
|
||||
"password" => $notifiable->extra_attributes?->get('smtp_password'),
|
||||
"timeout" => $notifiable->extra_attributes?->get('smtp_timeout'),
|
||||
"local_domain" => null,
|
||||
]);
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ class TestNotification extends Notification implements ShouldQueue
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
$channels = [];
|
||||
$notifiable->smtp_attributes?->get('smtp_active') && $channels[] = EmailChannel::class;
|
||||
$notifiable->smtp_attributes?->get('discord_active') && $channels[] = DiscordChannel::class;
|
||||
$notifiable->extra_attributes?->get('smtp_active') && $channels[] = EmailChannel::class;
|
||||
$notifiable->extra_attributes?->get('discord_active') && $channels[] = DiscordChannel::class;
|
||||
return $channels;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ return new class extends Migration
|
||||
$table->string('uuid')->unique();
|
||||
$table->string('name');
|
||||
$table->boolean('personal_team')->default(false);
|
||||
$table->schemalessAttributes('smtp_attributes');
|
||||
$table->schemalessAttributes('extra_attributes');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ return new class extends Migration
|
||||
$table->foreignId('team_id');
|
||||
$table->foreignId('private_key_id');
|
||||
$table->schemalessAttributes('extra_attributes');
|
||||
$table->schemalessAttributes('smtp_attributes');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -7,10 +7,10 @@
|
||||
</x-forms.button>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 xl:flex-row w-96">
|
||||
<x-forms.checkbox instantSave id="model.smtp_attributes.discord_active" label="Notification Enabled" />
|
||||
<x-forms.checkbox instantSave id="model.extra_attributes.discord_active" label="Notification Enabled" />
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 xl:flex-row w-96">
|
||||
<x-forms.input required id="model.smtp_attributes.discord_webhook" label="Webhook" />
|
||||
<x-forms.input required id="model.extra_attributes.discord_webhook" label="Webhook" />
|
||||
</div>
|
||||
<div>
|
||||
|
||||
|
@ -7,28 +7,29 @@
|
||||
</x-forms.button>
|
||||
</div>
|
||||
<div class="flex flex-col w-96">
|
||||
<x-forms.checkbox instantSave id="model.smtp_attributes.smtp_active" label="Notification Enabled" />
|
||||
<x-forms.checkbox instantSave id="model.extra_attributes.smtp_active" label="Notification Enabled" />
|
||||
</div>
|
||||
<x-forms.input id="model.extra_attributes.test_notification_email" label="Test Notification Email" />
|
||||
<div class="flex flex-col gap-2 xl:flex-row">
|
||||
<div class="flex flex-col w-96">
|
||||
<x-forms.textarea required id="model.smtp_attributes.recipients" helper="E-mails, one per line"
|
||||
<x-forms.input required id="model.extra_attributes.recipients" helper="Emails separated by comma"
|
||||
label="Recipients" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2 xl:flex-row">
|
||||
<div class="flex flex-col w-96">
|
||||
<x-forms.input required id="model.smtp_attributes.smtp_host" label="Host" />
|
||||
<x-forms.input required id="model.smtp_attributes.smtp_port" label="Port" />
|
||||
<x-forms.input id="model.smtp_attributes.smtp_encryption" label="Encryption" />
|
||||
<x-forms.input required id="model.extra_attributes.smtp_host" label="Host" />
|
||||
<x-forms.input required id="model.extra_attributes.smtp_port" label="Port" />
|
||||
<x-forms.input id="model.extra_attributes.smtp_encryption" label="Encryption" />
|
||||
</div>
|
||||
<div class="flex flex-col w-96">
|
||||
<x-forms.input id="model.smtp_attributes.smtp_username" label="Username" />
|
||||
<x-forms.input id="model.smtp_attributes.smtp_password" label="Password" />
|
||||
<x-forms.input id="model.smtp_attributes.smtp_timeout" label="Timeout" />
|
||||
<x-forms.input id="model.extra_attributes.smtp_username" label="Username" />
|
||||
<x-forms.input id="model.extra_attributes.smtp_password" label="Password" />
|
||||
<x-forms.input id="model.extra_attributes.smtp_timeout" label="Timeout" />
|
||||
</div>
|
||||
<div class="flex flex-col w-96">
|
||||
<x-forms.input required id="model.smtp_attributes.from_address" label="From Address" />
|
||||
<x-forms.input required id="model.smtp_attributes.from_name" label="From Name" />
|
||||
<x-forms.input required id="model.extra_attributes.from_address" label="From Address" />
|
||||
<x-forms.input required id="model.extra_attributes.from_name" label="From Name" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user