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

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

View File

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