This commit is contained in:
Andras Bacsai
2023-06-20 19:08:43 +02:00
parent f648ab49f7
commit 9f0ca1cc2e
19 changed files with 226 additions and 197 deletions

View File

@@ -1,23 +0,0 @@
<?php
namespace App\Data;
use Spatie\LaravelData\Data;
class SmtpConfiguration extends Data
{
public function __construct(
public bool $smtp_enabled = false,
public string $smtp_host,
public int $smtp_port,
public ?string $smtp_encryption,
public ?string $smtp_username,
public ?string $smtp_password,
public ?int $smtp_timeout,
public string $smtp_from_address,
public string $smtp_from_name,
public ?string $smtp_recipients,
public ?string $smtp_test_recipients,
) {
}
}

View File

@@ -10,20 +10,21 @@ class DiscordSettings extends Component
{ {
public Team $model; public Team $model;
protected $rules = [ protected $rules = [
'model.extra_attributes.discord_enabled' => 'nullable|boolean', 'model.discord.enabled' => 'nullable|boolean',
'model.extra_attributes.discord_webhook_url' => 'required|url', 'model.discord.webhook_url' => 'required|url',
'model.extra_attributes.notifications_discord_test' => 'nullable|boolean', 'model.discord_notifications.test' => 'nullable|boolean',
'model.extra_attributes.notifications_discord_deployments' => 'nullable|boolean', 'model.discord_notifications.deployments' => 'nullable|boolean',
]; ];
protected $validationAttributes = [ protected $validationAttributes = [
'model.extra_attributes.discord_webhook_url' => 'Discord Webhook', 'model.discord.webhook_url' => 'Discord Webhook',
]; ];
public function instantSave() public function instantSave()
{ {
try { try {
$this->submit(); $this->submit();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->model->extra_attributes->discord_enabled = false; $this->model->discord->enabled = false;
$this->validate(); $this->validate();
} }
} }

View File

@@ -12,53 +12,55 @@ class EmailSettings extends Component
public Team $model; public Team $model;
protected $rules = [ protected $rules = [
'model.extra_attributes.smtp_enabled' => 'nullable|boolean', 'model.smtp.enabled' => 'nullable|boolean',
'model.extra_attributes.smtp_from_address' => 'required|email', 'model.smtp.from_address' => 'required|email',
'model.extra_attributes.smtp_from_name' => 'required', 'model.smtp.from_name' => 'required',
'model.extra_attributes.smtp_recipients' => 'nullable', 'model.smtp.recipients' => 'nullable',
'model.extra_attributes.smtp_host' => 'required', 'model.smtp.host' => 'required',
'model.extra_attributes.smtp_port' => 'required', 'model.smtp.port' => 'required',
'model.extra_attributes.smtp_encryption' => 'nullable', 'model.smtp.encryption' => 'nullable',
'model.extra_attributes.smtp_username' => 'nullable', 'model.smtp.username' => 'nullable',
'model.extra_attributes.smtp_password' => 'nullable', 'model.smtp.password' => 'nullable',
'model.extra_attributes.smtp_timeout' => 'nullable', 'model.smtp.timeout' => 'nullable',
'model.extra_attributes.smtp_test_recipients' => 'nullable', 'model.smtp.test_recipients' => 'nullable',
'model.extra_attributes.notifications_smtp_test' => 'nullable|boolean', 'model.smtp_notifications.test' => 'nullable|boolean',
'model.extra_attributes.notifications_email_deployments' => 'nullable|boolean', 'model.smtp_notifications.deployments' => 'nullable|boolean',
'model.discord_notifications.test' => 'nullable|boolean',
'model.discord_notifications.deployments' => 'nullable|boolean',
]; ];
protected $validationAttributes = [ protected $validationAttributes = [
'model.extra_attributes.smtp_from_address' => 'From Address', 'model.smtp.from_address' => 'From Address',
'model.extra_attributes.smtp_from_name' => 'From Name', 'model.smtp.from_name' => 'From Name',
'model.extra_attributes.smtp_recipients' => 'Recipients', 'model.smtp.recipients' => 'Recipients',
'model.extra_attributes.smtp_host' => 'Host', 'model.smtp.host' => 'Host',
'model.extra_attributes.smtp_port' => 'Port', 'model.smtp.port' => 'Port',
'model.extra_attributes.smtp_encryption' => 'Encryption', 'model.smtp.encryption' => 'Encryption',
'model.extra_attributes.smtp_username' => 'Username', 'model.smtp.username' => 'Username',
'model.extra_attributes.smtp_password' => 'Password', 'model.smtp.password' => 'Password',
'model.extra_attributes.smtp_test_recipients' => 'Test Recipients', 'model.smtp.test_recipients' => 'Test Recipients',
]; ];
public function copySMTP() public function copyFromInstanceSettings()
{ {
$settings = InstanceSettings::get(); $settings = InstanceSettings::get();
$this->model->extra_attributes->smtp_enabled = true; $this->model->smtp->enabled = true;
$this->model->extra_attributes->smtp_from_address = $settings->extra_attributes->smtp_from_address; $this->model->smtp->from_address = $settings->smtp->from_address;
$this->model->extra_attributes->smtp_from_name = $settings->extra_attributes->smtp_from_name; $this->model->smtp->from_name = $settings->smtp->from_name;
$this->model->extra_attributes->smtp_recipients = $settings->extra_attributes->smtp_recipients; $this->model->smtp->recipients = $settings->smtp->recipients;
$this->model->extra_attributes->smtp_host = $settings->extra_attributes->smtp_host; $this->model->smtp->host = $settings->smtp->host;
$this->model->extra_attributes->smtp_port = $settings->extra_attributes->smtp_port; $this->model->smtp->port = $settings->smtp->port;
$this->model->extra_attributes->smtp_encryption = $settings->extra_attributes->smtp_encryption; $this->model->smtp->encryption = $settings->smtp->encryption;
$this->model->extra_attributes->smtp_username = $settings->extra_attributes->smtp_username; $this->model->smtp->username = $settings->smtp->username;
$this->model->extra_attributes->smtp_password = $settings->extra_attributes->smtp_password; $this->model->smtp->password = $settings->smtp->password;
$this->model->extra_attributes->smtp_timeout = $settings->extra_attributes->smtp_timeout; $this->model->smtp->timeout = $settings->smtp->timeout;
$this->model->extra_attributes->smtp_test_recipients = $settings->extra_attributes->smtp_test_recipients; $this->model->smtp->test_recipients = $settings->smtp->test_recipients;
$this->saveModel(); $this->saveModel();
} }
public function submit() public function submit()
{ {
$this->resetErrorBag(); $this->resetErrorBag();
$this->validate(); $this->validate();
$this->model->extra_attributes->smtp_recipients = str_replace(' ', '', $this->model->extra_attributes->smtp_recipients); $this->model->smtp->recipients = str_replace(' ', '', $this->model->smtp->recipients);
$this->model->extra_attributes->smtp_test_recipients = str_replace(' ', '', $this->model->extra_attributes->smtp_test_recipients); $this->model->smtp->test_recipients = str_replace(' ', '', $this->model->smtp->test_recipients);
$this->saveModel(); $this->saveModel();
} }
public function saveModel() public function saveModel()
@@ -79,7 +81,7 @@ class EmailSettings extends Component
try { try {
$this->submit(); $this->submit();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->model->extra_attributes->smtp_enabled = false; $this->model->smtp->enabled = false;
$this->validate(); $this->validate();
} }
} }

View File

@@ -12,34 +12,34 @@ class Email extends Component
public InstanceSettings $settings; public InstanceSettings $settings;
protected $rules = [ protected $rules = [
'settings.extra_attributes.smtp_enabled' => 'nullable|boolean', 'settings.smtp.enabled' => 'nullable|boolean',
'settings.extra_attributes.smtp_host' => 'required', 'settings.smtp.host' => 'required',
'settings.extra_attributes.smtp_port' => 'required|numeric', 'settings.smtp.port' => 'required|numeric',
'settings.extra_attributes.smtp_encryption' => 'nullable', 'settings.smtp.encryption' => 'nullable',
'settings.extra_attributes.smtp_username' => 'nullable', 'settings.smtp.username' => 'nullable',
'settings.extra_attributes.smtp_password' => 'nullable', 'settings.smtp.password' => 'nullable',
'settings.extra_attributes.smtp_timeout' => 'nullable', 'settings.smtp.timeout' => 'nullable',
'settings.extra_attributes.smtp_test_recipients' => 'nullable', 'settings.smtp.test_recipients' => 'nullable',
'settings.extra_attributes.smtp_from_address' => 'required|email', 'settings.smtp.from_address' => 'required|email',
'settings.extra_attributes.smtp_from_name' => 'required', 'settings.smtp.from_name' => 'required',
]; ];
protected $validationAttributes = [ protected $validationAttributes = [
'settings.extra_attributes.smtp_from_address' => 'From Address', 'settings.smtp.from_address' => 'From Address',
'settings.extra_attributes.smtp_from_name' => 'From Name', 'settings.smtp.from_name' => 'From Name',
'settings.extra_attributes.smtp_recipients' => 'Recipients', 'settings.smtp.recipients' => 'Recipients',
'settings.extra_attributes.smtp_host' => 'Host', 'settings.smtp.host' => 'Host',
'settings.extra_attributes.smtp_port' => 'Port', 'settings.smtp.port' => 'Port',
'settings.extra_attributes.smtp_encryption' => 'Encryption', 'settings.smtp.encryption' => 'Encryption',
'settings.extra_attributes.smtp_username' => 'Username', 'settings.smtp.username' => 'Username',
'settings.extra_attributes.smtp_password' => 'Password', 'settings.smtp.password' => 'Password',
'settings.extra_attributes.smtp_test_recipients' => 'Test Recipients', 'settings.smtp.test_recipients' => 'Test Recipients',
]; ];
public function instantSave() public function instantSave()
{ {
try { try {
$this->submit(); $this->submit();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->settings->extra_attributes->smtp_enabled = false; $this->settings->smtp->enabled = false;
$this->validate(); $this->validate();
} }
} }
@@ -51,7 +51,7 @@ class Email extends Component
public function submit() public function submit()
{ {
$this->validate(); $this->validate();
$this->settings->extra_attributes->smtp_test_recipients = str_replace(' ', '', $this->settings->extra_attributes->smtp_test_recipients); $this->settings->smtp->test_recipients = str_replace(' ', '', $this->settings->smtp->test_recipients);
$this->settings->save(); $this->settings->save();
} }
} }

View File

@@ -7,20 +7,24 @@ use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes; use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
class InstanceSettings extends Model implements SendsEmail class InstanceSettings extends Model implements SendsEmail
{ {
use Notifiable; use Notifiable, SchemalessAttributesTrait;
protected $casts = [ protected $schemalessAttributes = [
'extra_attributes' => SchemalessAttributes::class, 'smtp',
]; ];
public function scopeWithExtraAttributes(): Builder protected $casts = [
'smtp' => SchemalessAttributes::class,
];
public function scopeWithSmtp(): Builder
{ {
return $this->extra_attributes->modelScope(); return $this->smtp->modelScope();
} }
public function routeNotificationForEmail(string $attribute = 'smtp_test_recipients') public function routeNotificationForEmail(string $attribute = 'test_recipients')
{ {
$recipients = $this->extra_attributes->get($attribute, ''); $recipients = $this->smtp->get($attribute, '');
if (is_null($recipients) || $recipients === '') { if (is_null($recipients) || $recipients === '') {
return []; return [];
} }

View File

@@ -8,40 +8,64 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes; use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
class Team extends Model implements SendsDiscord, SendsEmail class Team extends Model implements SendsDiscord, SendsEmail
{ {
use Notifiable; use Notifiable, SchemalessAttributesTrait;
protected $schemalessAttributes = [
'smtp',
'discord',
'smtp_notifications',
'discord_notifications',
];
protected $casts = [ protected $casts = [
'extra_attributes' => SchemalessAttributes::class, 'smtp' => SchemalessAttributes::class,
'discord' => SchemalessAttributes::class,
'smtp_notifications' => SchemalessAttributes::class,
'discord_notifications' => SchemalessAttributes::class,
'personal_team' => 'boolean', 'personal_team' => 'boolean',
]; ];
public function scopeWithSmtp(): Builder
{
return $this->smtp->modelScope();
}
public function scopeWithDiscord(): Builder
{
return $this->discord->modelScope();
}
public function scopeWithSmtpNotifications(): Builder
{
return $this->smtp_notifications->modelScope();
}
public function scopeWithDiscordNotifications(): Builder
{
return $this->discord_notifications->modelScope();
}
protected $fillable = [ protected $fillable = [
'id', 'id',
'name', 'name',
'description', 'description',
'personal_team', 'personal_team',
'extra_attributes', 'smtp',
'discord'
]; ];
public function routeNotificationForDiscord() public function routeNotificationForDiscord()
{ {
return $this->extra_attributes->get('discord_webhook_url'); return $this->discord->get('webhook_url');
} }
public function routeNotificationForEmail(string $attribute = 'smtp_recipients') public function routeNotificationForEmail(string $attribute = 'recipients')
{ {
$recipients = $this->extra_attributes->get($attribute, ''); $recipients = $this->smtp->get($attribute, '');
if (is_null($recipients) || $recipients === '') { if (is_null($recipients) || $recipients === '') {
return []; return [];
} }
return explode(',', $recipients); return explode(',', $recipients);
} }
public function scopeWithExtraAttributes(): Builder
{
return $this->extra_attributes->modelScope();
}
public function projects() public function projects()
{ {

View File

@@ -34,10 +34,20 @@ class User extends Authenticatable implements SendsEmail
$team = [ $team = [
'name' => $user->name . "'s Team", 'name' => $user->name . "'s Team",
'personal_team' => true, 'personal_team' => true,
'extra_attributes' => [ 'smtp' => [
'notifications_smtp_test' => true, 'enabled' => false,
'notifications_discord_test' => true, ],
] 'smtp_notifications' => [
'test' => true,
'deployments' => false,
],
'discord' => [
'enabled' => false,
],
'discord_notifications' => [
'test' => true,
'deployments' => false,
],
]; ];
if ($user->id === 0) { if ($user->id === 0) {
$team['id'] = 0; $team['id'] = 0;

View File

@@ -12,7 +12,7 @@ class EmailChannel
{ {
$this->bootConfigs($notifiable); $this->bootConfigs($notifiable);
$bcc = $notifiable->routeNotificationForEmail('smtp_test_recipients'); $bcc = $notifiable->routeNotificationForEmail('test_recipients');
if (count($bcc) === 0) { if (count($bcc) === 0) {
if ($notifiable instanceof \App\Models\Team) { if ($notifiable instanceof \App\Models\Team) {
$bcc = $notifiable->members()->pluck('email')->toArray(); $bcc = $notifiable->members()->pluck('email')->toArray();
@@ -24,8 +24,8 @@ class EmailChannel
[], [],
fn (Message $message) => $message fn (Message $message) => $message
->from( ->from(
$notifiable->extra_attributes?->get('smtp_from_address'), data_get($notifiable, 'smtp.from_address'),
$notifiable->extra_attributes?->get('smtp_from_name') data_get($notifiable, 'smtp.from_name'),
) )
->bcc($bcc) ->bcc($bcc)
->subject($mailMessage->subject) ->subject($mailMessage->subject)
@@ -38,12 +38,12 @@ class EmailChannel
config()->set('mail.default', 'smtp'); config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [ config()->set('mail.mailers.smtp', [
"transport" => "smtp", "transport" => "smtp",
"host" => $notifiable->extra_attributes?->get('smtp_host'), "host" => data_get($notifiable, 'smtp.host'),
"port" => $notifiable->extra_attributes?->get('smtp_port'), "port" => data_get($notifiable, 'smtp.port'),
"encryption" => $notifiable->extra_attributes?->get('smtp_encryption'), "encryption" => data_get($notifiable, 'smtp.encryption'),
"username" => $notifiable->extra_attributes?->get('smtp_username'), "username" => data_get($notifiable, 'smtp.username'),
"password" => $notifiable->extra_attributes?->get('smtp_password'), "password" => data_get($notifiable, 'smtp.password'),
"timeout" => $notifiable->extra_attributes?->get('smtp_timeout'), "timeout" => data_get($notifiable, 'smtp.timeout'),
"local_domain" => null, "local_domain" => null,
]); ]);
} }

View File

@@ -13,23 +13,22 @@ class TransactionalEmailChannel
public function send(User $notifiable, Notification $notification): void public function send(User $notifiable, Notification $notification): void
{ {
$settings = InstanceSettings::get(); $settings = InstanceSettings::get();
if ($settings->extra_attributes?->get('smtp_enabled') !== true) { if (data_get($settings, 'smtp.enabled') !== true) {
return; return;
} }
$email = $notifiable->email; $email = $notifiable->email;
if (!$email) { if (!$email) {
return; return;
} }
$this->bootConfigs($settings); $this->bootConfigs();
$mailMessage = $notification->toMail($notifiable); $mailMessage = $notification->toMail($notifiable);
Mail::send( Mail::send(
[], [],
[], [],
fn (Message $message) => $message fn (Message $message) => $message
->from( ->from(
$settings->extra_attributes?->get('smtp_from_address'), data_get($settings, 'smtp.from_address'),
$settings->extra_attributes?->get('smtp_from_name') data_get($settings, 'smtp.from_name')
) )
->to($email) ->to($email)
->subject($mailMessage->subject) ->subject($mailMessage->subject)
@@ -37,7 +36,7 @@ class TransactionalEmailChannel
); );
} }
private function bootConfigs(InstanceSettings $settings): void private function bootConfigs(): void
{ {
set_transanctional_email_settings(); set_transanctional_email_settings();
} }

View File

@@ -43,10 +43,15 @@ class DeployedSuccessfullyNotification extends Notification implements ShouldQue
public function via(object $notifiable): array public function via(object $notifiable): array
{ {
$channels = []; $channels = [];
if ($notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_email_deployments')) { $isEmailEnabled = data_get($notifiable, 'smtp.enabled');
$isDiscordEnabled = data_get($notifiable, 'discord.enabled');
$isSubscribedToEmailDeployments = data_get($notifiable, 'smtp_notifications.deployments');
$isSubscribedToDiscordDeployments = data_get($notifiable, 'discord_notifications.deployments');
if ($isEmailEnabled && $isSubscribedToEmailDeployments) {
$channels[] = EmailChannel::class; $channels[] = EmailChannel::class;
} }
if ($notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) { if ($isDiscordEnabled && $isSubscribedToDiscordDeployments) {
$channels[] = DiscordChannel::class; $channels[] = DiscordChannel::class;
} }
return $channels; return $channels;

View File

@@ -44,10 +44,15 @@ class DeployedWithErrorNotification extends Notification implements ShouldQueue
public function via(object $notifiable): array public function via(object $notifiable): array
{ {
$channels = []; $channels = [];
if ($notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_email_deployments')) { $isEmailEnabled = data_get($notifiable, 'smtp.enabled');
$isDiscordEnabled = data_get($notifiable, 'discord.enabled');
$isSubscribedToEmailDeployments = data_get($notifiable, 'smtp_notifications.deployments');
$isSubscribedToDiscordDeployments = data_get($notifiable, 'discord_notifications.deployments');
if ($isEmailEnabled && $isSubscribedToEmailDeployments) {
$channels[] = EmailChannel::class; $channels[] = EmailChannel::class;
} }
if ($notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_deployments')) { if ($isDiscordEnabled && $isSubscribedToDiscordDeployments) {
$channels[] = DiscordChannel::class; $channels[] = DiscordChannel::class;
} }
return $channels; return $channels;

View File

@@ -20,12 +20,21 @@ class TestNotification extends Notification implements ShouldQueue
public function via(object $notifiable): array public function via(object $notifiable): array
{ {
$channels = []; $channels = [];
if (($this->type === 'smtp' || is_null($this->type)) && $notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_smtp_test')) {
$isSmtp = $this->type === 'smtp' || is_null($this->type);
$isDiscord = $this->type === 'discord' || is_null($this->type);
$isEmailEnabled = data_get($notifiable, 'smtp.enabled');
$isDiscordEnabled = data_get($notifiable, 'discord.enabled');
$isSubscribedToEmailTests = data_get($notifiable, 'smtp_notifications.test');
$isSubscribedToDiscordTests = data_get($notifiable, 'discord_notifications.test');
if ($isEmailEnabled && $isSubscribedToEmailTests && $isSmtp) {
$channels[] = EmailChannel::class; $channels[] = EmailChannel::class;
} }
if (($this->type === 'discord' || is_null($this->type)) && $notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_test')) { if ($isDiscordEnabled && $isSubscribedToDiscordTests && $isDiscord) {
$channels[] = DiscordChannel::class; $channels[] = DiscordChannel::class;
} }
return $channels; return $channels;
} }
public function toMail(): MailMessage public function toMail(): MailMessage
@@ -39,7 +48,7 @@ class TestNotification extends Notification implements ShouldQueue
public function toDiscord(): string public function toDiscord(): string
{ {
return 'This is a test Discord notification from Coolify. return 'This is a test Discord notification from Coolify.
[Go to your dashboard](' . base_url() . ')'; [Go to your dashboard](' . base_url() . ')';
} }
} }

View File

@@ -69,7 +69,7 @@ function generate_application_name(string $git_repository, string $git_branch)
function is_transactional_emails_active() function is_transactional_emails_active()
{ {
return data_get(InstanceSettings::get(), 'extra_attributes.smtp_enabled'); return data_get(InstanceSettings::get(), 'smtp.enabled');
} }
function set_transanctional_email_settings() function set_transanctional_email_settings()
@@ -78,12 +78,12 @@ function set_transanctional_email_settings()
config()->set('mail.default', 'smtp'); config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [ config()->set('mail.mailers.smtp', [
"transport" => "smtp", "transport" => "smtp",
"host" => $settings->extra_attributes?->get('smtp_host'), "host" => data_get($settings, 'smtp.host'),
"port" => $settings->extra_attributes?->get('smtp_port'), "port" => data_get($settings, 'smtp.port'),
"encryption" => $settings->extra_attributes?->get('smtp_encryption'), "encryption" => data_get($settings, 'smtp.encryption'),
"username" => $settings->extra_attributes?->get('smtp_username'), "username" => data_get($settings, 'smtp.username'),
"password" => $settings->extra_attributes?->get('smtp_password'), "password" => data_get($settings, 'smtp.password'),
"timeout" => $settings->extra_attributes?->get('smtp_timeout'), "timeout" => data_get($settings, 'smtp.timeout'),
"local_domain" => null, "local_domain" => null,
]); ]);
} }

View File

@@ -16,7 +16,10 @@ return new class extends Migration
$table->string('name'); $table->string('name');
$table->string('description')->nullable(); $table->string('description')->nullable();
$table->boolean('personal_team')->default(false); $table->boolean('personal_team')->default(false);
$table->schemalessAttributes('extra_attributes'); $table->schemalessAttributes('smtp');
$table->schemalessAttributes('smtp_notifications');
$table->schemalessAttributes('discord');
$table->schemalessAttributes('discord_notifications');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@@ -23,7 +23,7 @@ return new class extends Migration
$table->boolean('do_not_track')->default(false); $table->boolean('do_not_track')->default(false);
$table->boolean('is_auto_update_enabled')->default(true); $table->boolean('is_auto_update_enabled')->default(true);
$table->boolean('is_registration_enabled')->default(true); $table->boolean('is_registration_enabled')->default(true);
$table->schemalessAttributes('extra_attributes'); $table->schemalessAttributes('smtp');
// $table->string('custom_dns_servers')->default('1.1.1.1,8.8.8.8'); // $table->string('custom_dns_servers')->default('1.1.1.1,8.8.8.8');
// $table->boolean('is_dns_check_enabled')->default(true); // $table->boolean('is_dns_check_enabled')->default(true);
$table->timestamps(); $table->timestamps();

View File

@@ -2,7 +2,6 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Data\SmtpConfiguration;
use App\Models\InstanceSettings; use App\Models\InstanceSettings;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Process;
@@ -17,14 +16,14 @@ class InstanceSettingsSeeder extends Seeder
InstanceSettings::create([ InstanceSettings::create([
'id' => 0, 'id' => 0,
'is_registration_enabled' => true, 'is_registration_enabled' => true,
'extra_attributes' => SmtpConfiguration::from([ 'smtp' => [
'smtp_enabled' => true, 'enabled' => true,
'smtp_test_recipients' => 'test@example.com,test2@example.com', 'test_recipients' => 'test@example.com,test2@example.com',
'smtp_host' => 'coolify-mail', 'host' => 'coolify-mail',
'smtp_port' => 1025, 'port' => 1025,
'smtp_from_address' => 'hi@localhost.com', 'from_address' => 'hi@localhost.com',
'smtp_from_name' => 'Coolify', 'from_name' => 'Coolify',
]) ]
]); ]);
try { try {
$ipv4 = Process::run('curl -4s https://ifconfig.io')->output(); $ipv4 = Process::run('curl -4s https://ifconfig.io')->output();

View File

@@ -5,7 +5,7 @@
<x-forms.button type="submit"> <x-forms.button type="submit">
Save Save
</x-forms.button> </x-forms.button>
@if ($model->extra_attributes->discord_enabled) @if ($model->discord->enabled)
<x-forms.button class="text-white normal-case btn btn-xs no-animation btn-primary" <x-forms.button class="text-white normal-case btn btn-xs no-animation btn-primary"
wire:click="sendTestNotification"> wire:click="sendTestNotification">
Send Test Notifications Send Test Notifications
@@ -13,20 +13,20 @@
@endif @endif
</div> </div>
<div class="w-48"> <div class="w-48">
<x-forms.checkbox instantSave id="model.extra_attributes.discord_enabled" label="Notification Enabled" /> <x-forms.checkbox instantSave id="model.discord.enabled" label="Notification Enabled" />
</div> </div>
<x-forms.input type="string" <x-forms.input type="string"
helper="Generate a webhook in Discord.<br>Example: https://discord.com/api/webhooks/...." required helper="Generate a webhook in Discord.<br>Example: https://discord.com/api/webhooks/...." required
id="model.extra_attributes.discord_webhook_url" label="Webhook" /> id="model.discord.webhook_url" label="Webhook" />
</form> </form>
@if (data_get($model, 'extra_attributes.discord_enabled')) @if (data_get($model, 'discord.enabled'))
<h4 class="mt-4">Subscribe to events</h4> <h4 class="mt-4">Subscribe to events</h4>
<div class="w-64 "> <div class="w-64 ">
@if (isDev()) @if (isDev())
<x-forms.checkbox instantSave="saveModel" id="model.extra_attributes.notifications_discord_test" <x-forms.checkbox instantSave="saveModel" id="model.discord_notifications.test"
label="Test Notifications" /> label="Test Notifications" />
@endif @endif
<x-forms.checkbox instantSave="saveModel" id="model.extra_attributes.notifications_discord_deployments" <x-forms.checkbox instantSave="saveModel" id="model.discord_notifications.deployments"
label="New Deployments" /> label="New Deployments" />
</div> </div>
@endif @endif

View File

@@ -6,11 +6,11 @@
Save Save
</x-forms.button> </x-forms.button>
@if (auth()->user()->isInstanceAdmin()) @if (auth()->user()->isInstanceAdmin())
<x-forms.button wire:click='copySMTP'> <x-forms.button wire:click='copyFromInstanceSettings'>
Copy from Instance Settings Copy from Instance Settings
</x-forms.button> </x-forms.button>
@endif @endif
@if ($model->extra_attributes->smtp_enabled) @if ($model->smtp->enabled)
<x-forms.button class="text-white normal-case btn btn-xs no-animation btn-primary" <x-forms.button class="text-white normal-case btn btn-xs no-animation btn-primary"
wire:click="sendTestNotification"> wire:click="sendTestNotification">
Send Test Notifications Send Test Notifications
@@ -18,49 +18,44 @@
@endif @endif
</div> </div>
<div class="w-48"> <div class="w-48">
<x-forms.checkbox instantSave id="model.extra_attributes.smtp_enabled" label="Notification Enabled" /> <x-forms.checkbox instantSave id="model.smtp.enabled" label="Notification Enabled" />
</div> </div>
<div class="flex flex-col gap-2 xl:flex-row"> <div class="flex flex-col gap-2 xl:flex-row">
<x-forms.input id="model.extra_attributes.smtp_recipients" <x-forms.input id="model.smtp.recipients" placeholder="If empty, all users will be notified in the team."
placeholder="If empty, all users will be notified in the team."
helper="Email list to send the all notifications to, separated by comma." label="Recipients" /> helper="Email list to send the all notifications to, separated by comma." label="Recipients" />
<x-forms.input id="model.extra_attributes.smtp_test_recipients" label="Test Notification Recipients" <x-forms.input id="model.smtp.test_recipients" label="Test Notification Recipients"
placeholder="If empty, all users will be notified in the team." placeholder="If empty, all users will be notified in the team."
helper="Email list to send the test notification to, separated by comma." /> helper="Email list to send the test notification to, separated by comma." />
</div> </div>
<div class="flex flex-col gap-2 xl:flex-row"> <div class="flex flex-col gap-2 xl:flex-row">
<x-forms.input required id="model.extra_attributes.smtp_host" helper="SMTP Hostname" <x-forms.input required id="model.smtp.host" helper="SMTP Hostname" placeholder="smtp.mailgun.org"
placeholder="smtp.mailgun.org" label="Host" /> label="Host" />
<x-forms.input required id="model.extra_attributes.smtp_port" helper="SMTP Port" placeholder="587" <x-forms.input required id="model.smtp.port" helper="SMTP Port" placeholder="587" label="Port" />
label="Port" /> <x-forms.input helper="If SMTP through SSL, set it to 'tls'." placeholder="tls" id="model.smtp.encryption"
<x-forms.input helper="If SMTP through SSL, set it to 'tls'." placeholder="tls" label="Encryption" />
id="model.extra_attributes.smtp_encryption" label="Encryption" />
</div> </div>
<div class="flex flex-col"> <div class="flex flex-col">
<div class="flex flex-col gap-2 xl:flex-row"> <div class="flex flex-col gap-2 xl:flex-row">
<x-forms.input id="model.extra_attributes.smtp_username" helper="SMTP Username" label="Username" /> <x-forms.input id="model.smtp.username" helper="SMTP Username" label="Username" />
<x-forms.input type="password" helper="SMTP Password" id="model.extra_attributes.smtp_password" <x-forms.input type="password" helper="SMTP Password" id="model.smtp.password" label="Password" />
label="Password" />
</div> </div>
<x-forms.input id="model.extra_attributes.smtp_timeout" helper="Timeout value for sending emails." <x-forms.input id="model.smtp.timeout" helper="Timeout value for sending emails." label="Timeout" />
label="Timeout" />
<div class="flex flex-col gap-2 xl:flex-row"> <div class="flex flex-col gap-2 xl:flex-row">
<x-forms.input required id="model.extra_attributes.smtp_from_name" helper="Name used in emails." <x-forms.input required id="model.smtp.from_name" helper="Name used in emails." label="From Name" />
label="From Name" /> <x-forms.input required id="model.smtp.from_address" helper="Email address used in emails."
<x-forms.input required id="model.extra_attributes.smtp_from_address" label="From Address" />
helper="Email address used in emails." label="From Address" />
</div> </div>
</div> </div>
</form> </form>
@if (data_get($model, 'extra_attributes.smtp_enabled')) @if (data_get($model, 'smtp.enabled'))
<h4 class="mt-4">Subscribe to events</h4> <h4 class="mt-4">Subscribe to events</h4>
<div class="w-64 "> <div class="w-64">
@if (isDev()) @if (isDev())
<x-forms.checkbox instantSave="saveModel" id="model.extra_attributes.notifications_smtp_test" <x-forms.checkbox instantSave="saveModel" id="model.smtp_notifications.test"
label="Test Notifications" /> label="Test Notifications" />
@endif @endif
<x-forms.checkbox instantSave="saveModel" id="model.extra_attributes.notifications_email_deployments" <x-forms.checkbox instantSave="saveModel" id="model.smtp_notifications.deployments"
label="New Deployments" /> label="New Deployments" />
</div> </div>
@endif @endif

View File

@@ -8,12 +8,12 @@
</div> </div>
<div class="pt-2 pb-4 ">SMTP settings for password resets, invitations, etc.</div> <div class="pt-2 pb-4 ">SMTP settings for password resets, invitations, etc.</div>
<div class="flex flex-col"> <div class="flex flex-col">
<x-forms.checkbox instantSave id="settings.extra_attributes.smtp_enabled" label="Enabled" /> <x-forms.checkbox instantSave id="settings.smtp.enabled" label="Enabled" />
</div> </div>
<div class="flex items-end gap-2"> <div class="flex items-end gap-2">
<x-forms.input id="settings.extra_attributes.smtp_test_recipients" label="Test Recipients" <x-forms.input id="settings.smtp.test_recipients" label="Test Recipients"
helper="Email list to send a test email to, separated by comma." /> helper="Email list to send a test email to, separated by comma." />
@if ($settings->extra_attributes->smtp_enabled) @if ($settings->smtp->enabled)
<x-forms.button wire:click='test_email'> <x-forms.button wire:click='test_email'>
Send Test Email Send Test Email
</x-forms.button> </x-forms.button>
@@ -21,26 +21,22 @@
</div> </div>
<div class="flex flex-col gap-2 xl:flex-row"> <div class="flex flex-col gap-2 xl:flex-row">
<div class="flex flex-col w-full"> <div class="flex flex-col w-full">
<x-forms.input required id="settings.extra_attributes.smtp_host" helper="SMTP Hostname" <x-forms.input required id="settings.smtp.host" helper="SMTP Hostname" placeholder="smtp.mailgun.org"
placeholder="smtp.mailgun.org" label="Host" /> label="Host" />
<x-forms.input required id="settings.extra_attributes.smtp_port" helper="SMTP Port" placeholder="587" <x-forms.input required id="settings.smtp.port" helper="SMTP Port" placeholder="587" label="Port" />
label="Port" /> <x-forms.input id="settings.smtp.encryption" helper="If SMTP through SSL, set it to 'tls'."
<x-forms.input id="settings.extra_attributes.smtp_encryption" placeholder="tls" label="Encryption" />
helper="If SMTP through SSL, set it to 'tls'." placeholder="tls" label="Encryption" />
</div> </div>
<div class="flex flex-col w-full"> <div class="flex flex-col w-full">
<x-forms.input id="settings.extra_attributes.smtp_username" helper="SMTP Username" <x-forms.input id="settings.smtp.username" helper="SMTP Username" label="SMTP Username" />
label="SMTP Username" /> <x-forms.input id="settings.smtp.password" type="password" helper="SMTP Password"
<x-forms.input id="settings.extra_attributes.smtp_password" type="password" helper="SMTP Password"
label="SMTP Password" /> label="SMTP Password" />
<x-forms.input id="settings.extra_attributes.smtp_timeout" helper="Timeout value for sending emails." <x-forms.input id="settings.smtp.timeout" helper="Timeout value for sending emails." label="Timeout" />
label="Timeout" />
</div> </div>
<div class="flex flex-col w-full"> <div class="flex flex-col w-full">
<x-forms.input required id="settings.extra_attributes.smtp_from_name" helper="Name used in emails." <x-forms.input required id="settings.smtp.from_name" helper="Name used in emails." label="From Name" />
label="From Name" /> <x-forms.input required id="settings.smtp.from_address" helper="Email address used in emails."
<x-forms.input required id="settings.extra_attributes.smtp_from_address" label="From Address" />
helper="Email address used in emails." label="From Address" />
</div> </div>
</div> </div>
</form> </form>