fix: migrate db schema for smtp + discord

This commit is contained in:
Andras Bacsai
2023-07-27 21:26:15 +02:00
parent d0a85713d2
commit 9c393ff6bc
21 changed files with 382 additions and 238 deletions

View File

@@ -7,26 +7,17 @@ use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
class InstanceSettings extends Model implements SendsEmail
{
use Notifiable, SchemalessAttributesTrait;
use Notifiable;
protected $guarded = [];
protected $schemalessAttributes = [
'smtp',
];
protected $casts = [
'smtp' => SchemalessAttributes::class,
'resale_license' => 'encrypted',
];
public function scopeWithSmtp(): Builder
{
return $this->smtp->modelScope();
}
public function routeNotificationForEmail(string $attribute = 'test_recipients')
{
$recipients = $this->smtp->get($attribute, '');
$recipients = data_get($this,'smtp','');
if (is_null($recipients) || $recipients === '') {
return [];
}
@@ -36,4 +27,4 @@ class InstanceSettings extends Model implements SendsEmail
{
return InstanceSettings::findOrFail(0);
}
}
}

View File

@@ -12,60 +12,26 @@ use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
class Team extends Model implements SendsDiscord, SendsEmail
{
use Notifiable, SchemalessAttributesTrait;
use Notifiable;
protected $schemalessAttributes = [
'smtp',
'discord',
'smtp_notifications',
'discord_notifications',
];
protected $guarded = [];
protected $casts = [
'smtp' => SchemalessAttributes::class,
'discord' => SchemalessAttributes::class,
'smtp_notifications' => SchemalessAttributes::class,
'discord_notifications' => SchemalessAttributes::class,
'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 = [
'id',
'name',
'description',
'personal_team',
'smtp',
'discord'
];
public function routeNotificationForDiscord()
{
return $this->discord->get('webhook_url');
return data_get($this, 'discord_webhook_url', null);
}
public function routeNotificationForEmail(string $attribute = 'recipients')
{
$recipients = $this->smtp->get($attribute, '');
$recipients = data_get($this, 'smtp_recipients', '');
if (is_null($recipients) || $recipients === '') {
return [];
}
return explode(',', $recipients);
}
public function subscription()
{
return $this->hasOne(Subscription::class);
@@ -113,4 +79,4 @@ class Team extends Model implements SendsDiscord, SendsEmail
}
return false;
}
}
}

View File

@@ -34,20 +34,6 @@ class User extends Authenticatable implements SendsEmail
$team = [
'name' => $user->name . "'s Team",
'personal_team' => true,
'smtp' => [
'enabled' => false,
],
'smtp_notifications' => [
'test' => true,
'deployments' => false,
],
'discord' => [
'enabled' => false,
],
'discord_notifications' => [
'test' => true,
'deployments' => false,
],
];
if ($user->id === 0) {
$team['id'] = 0;
@@ -124,4 +110,4 @@ class User extends Authenticatable implements SendsEmail
$data = Application::where('team_id', $team_id)->get();
return $data;
}
}
}