Skip to content

Commit

Permalink
a lot hehe
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Jun 1, 2023
1 parent c8f70a4 commit 0aa816b
Show file tree
Hide file tree
Showing 42 changed files with 568 additions and 247 deletions.
6 changes: 6 additions & 0 deletions .env.development.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ GROUPID=
PROJECT_PATH_ON_HOST=/Users/your-username-here/code/coollabsio/coolify
SERVEO_URL=<for receiving webhooks locally https://serveo.net/>
MUX_ENABLED=false
# If you are using the included Buggregator
[email protected]
RAY_PORT=8001
############################################################################################################

APP_NAME=Coolify
Expand All @@ -19,6 +21,10 @@ APP_DEBUG=true
APP_URL=http://localhost
APP_PORT=8000

MAIL_MAILER=smtp
MAIL_HOST=coolify-mail
MAIL_PORT=1025

SESSION_DRIVER=database
DUSK_DRIVER_URL=http://selenium:4444

Expand Down
2 changes: 1 addition & 1 deletion .env.secrets.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Secrets related to pushing to GH, Sync files to BunnyCDN etc.
# Secrets related to pushing to GH, Sync files to BunnyCDN etc. Only for maintainers.
# Not related to Coolify, but to how we publish new versions.

GITHUB_TOKEN=
Expand Down
33 changes: 21 additions & 12 deletions app/Http/Livewire/Notifications/DiscordSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Models\Server;
use App\Models\Team;
use App\Notifications\DemoNotification;
use App\Notifications\TestNotification;
use Illuminate\Support\Facades\Notification;
use Livewire\Component;

Expand All @@ -13,31 +13,40 @@ class DiscordSettings extends Component
public Team|Server $model;

protected $rules = [
'model.extra_attributes.discord_webhook' => 'nullable|url',
'model.extra_attributes.discord_active' => 'nullable|boolean',
'model.smtp_attributes.discord_active' => 'nullable|boolean',
'model.smtp_attributes.discord_webhook' => 'required|url',
];
protected $validationAttributes = [
'model.extra_attributes.discord_webhook' => 'Discord Webhook',
'model.smtp_attributes.discord_webhook' => 'Discord Webhook',
];
public function mount($model)
{
//
}
public function submit()
public function instantSave()
{
try {
$this->submit();
} catch (\Exception $e) {
$this->model->smtp_attributes->discord_active = false;
$this->addError('model.smtp_attributes.discord_webhook', $e->getMessage());
}
}
private function saveModel()
{
$this->resetErrorBag();
$this->validate();
$this->model->save();
if ( is_a($this->model, Team::class)) {
if (is_a($this->model, Team::class)) {
session(['currentTeam' => $this->model]);
}
}
public function sendTestNotification()
public function submit()
{
Notification::send($this->model, new DemoNotification);
$this->resetErrorBag();
$this->validate();
$this->saveModel();
}
public function render()
public function sendTestNotification()
{
return view('livewire.notifications.discord-settings');
Notification::send($this->model, new TestNotification);
}
}
54 changes: 27 additions & 27 deletions app/Http/Livewire/Notifications/EmailSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Models\Server;
use App\Models\Team;
use App\Notifications\DemoNotification;
use App\Notifications\TestNotification;
use Illuminate\Support\Facades\Notification;
use Livewire\Component;

Expand All @@ -13,27 +13,27 @@ class EmailSettings extends Component
public Team|Server $model;

protected $rules = [
'model.extra_attributes.smtp_active' => 'nullable|boolean',
'model.extra_attributes.from_address' => 'nullable',
'model.extra_attributes.from_name' => 'nullable',
'model.extra_attributes.recipients' => 'nullable',
'model.extra_attributes.smtp_host' => 'nullable',
'model.extra_attributes.smtp_port' => 'nullable',
'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.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',
];
protected $validationAttributes = [
'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',
'model.extra_attributes.smtp_timeout' => 'Timeout',
'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',
];
public function mount($model)
{
Expand All @@ -43,17 +43,17 @@ public function submit()
{
$this->resetErrorBag();
$this->validate();
$this->saveModel();
}
private function saveModel()
{
$this->model->save();
if ( is_a($this->model, Team::class)) {
if (is_a($this->model, Team::class)) {
session(['currentTeam' => $this->model]);
}
}
public function sendTestNotification()
{
Notification::send($this->model, new DemoNotification);
}
public function render()
public function instantSave()
{
return view('livewire.notifications.email-settings');
$this->saveModel();
}
}
19 changes: 19 additions & 0 deletions app/Http/Livewire/Notifications/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Livewire\Notifications;

use App\Models\Server;
use App\Models\Team;
use App\Notifications\TestNotification;
use Livewire\Component;
use Notification;

class Test extends Component
{
public Team|Server $model;
public function sendTestNotification()
{
Notification::send($this->model, new TestNotification);
$this->emit('saved', 'Test notification sent.');
}
}
41 changes: 41 additions & 0 deletions app/Http/Livewire/Settings/Email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Http\Livewire\Settings;

use App\Models\InstanceSettings;
use Livewire\Component;

class Email extends Component
{
public InstanceSettings $model;

protected $rules = [
'model.extra_attributes.from_address' => 'nullable',
'model.extra_attributes.from_name' => 'nullable',
'model.extra_attributes.recipients' => 'nullable',
'model.extra_attributes.smtp_host' => 'nullable',
'model.extra_attributes.smtp_port' => 'nullable',
'model.extra_attributes.smtp_encryption' => 'nullable',
'model.extra_attributes.smtp_username' => 'nullable',
'model.extra_attributes.smtp_password' => 'nullable',
'model.extra_attributes.smtp_timeout' => 'nullable',
];
protected $validationAttributes = [
'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)
{
//
}
public function render()
{
return view('livewire.settings.email');
}
}
9 changes: 7 additions & 2 deletions app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ protected static function booted()
'port',
'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()
{
Expand All @@ -43,8 +50,6 @@ public function swarmDockers()
return $this->hasMany(SwarmDocker::class);
}



public function privateKey()
{
return $this->belongsTo(PrivateKey::class);
Expand Down
17 changes: 8 additions & 9 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,41 @@

namespace App\Models;

use App\Notifications\Channels\SendsCoolifyEmail;
use App\Notifications\Channels\SendsEmail;
use App\Notifications\Channels\SendsDiscord;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Notifications\Notifiable;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;

class Team extends BaseModel implements SendsDiscord, SendsCoolifyEmail
class Team extends BaseModel implements SendsDiscord, SendsEmail
{
use Notifiable;

protected $casts = [
'extra_attributes' => SchemalessAttributes::class,
'smtp_attributes' => SchemalessAttributes::class,
'personal_team' => 'boolean',
];
protected $fillable = [
'id',
'name',
'personal_team',
'extra_attributes',
'smtp_attributes',
];

public function routeNotificationForDiscord()
{
return $this->extra_attributes->get('discord_webhook');
return $this->smtp_attributes->get('discord_webhook');
}

public function routeNotificationForCoolifyEmail()
public function routeNotificationForEmail(string $attribute = 'recipients')
{
$recipients = $this->extra_attributes->get('recipients', '');

$recipients = $this->smtp_attributes->get($attribute, '');
return explode(PHP_EOL, $recipients);
}

public function scopeWithExtraAttributes(): Builder
{
return $this->extra_attributes->modelScope();
return $this->smtp_attributes->modelScope();
}

public function projects()
Expand Down
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Visus\Cuid2\Cuid2;
use Laravel\Fortify\TwoFactorAuthenticatable;

class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
use HasApiTokens, HasFactory, Notifiable, TwoFactorAuthenticatable;
protected $fillable = [
'id',
'name',
Expand Down
44 changes: 0 additions & 44 deletions app/Notifications/Channels/CoolifyEmailChannel.php

This file was deleted.

2 changes: 0 additions & 2 deletions app/Notifications/Channels/DiscordChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class DiscordChannel
public function send(SendsDiscord $notifiable, Notification $notification): void
{
$message = $notification->toDiscord($notifiable);

$webhookUrl = $notifiable->routeNotificationForDiscord();

dispatch(new SendMessageToDiscordJob($message, $webhookUrl));
}
}
Loading

0 comments on commit 0aa816b

Please sign in to comment.