2023-03-24 14:54:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-06-01 12:15:33 +02:00
|
|
|
use App\Notifications\Channels\SendsEmail;
|
2023-05-25 17:27:52 +01:00
|
|
|
use App\Notifications\Channels\SendsDiscord;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2023-06-15 09:15:41 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-05-25 17:27:52 +01:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
|
2023-06-20 19:08:43 +02:00
|
|
|
use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
|
2023-05-25 17:27:52 +01:00
|
|
|
|
2023-06-15 09:15:41 +02:00
|
|
|
class Team extends Model implements SendsDiscord, SendsEmail
|
2023-03-24 14:54:17 +01:00
|
|
|
{
|
2023-07-27 21:26:15 +02:00
|
|
|
use Notifiable;
|
2023-05-25 17:27:52 +01:00
|
|
|
|
2023-07-27 21:26:15 +02:00
|
|
|
protected $guarded = [];
|
2023-03-24 14:54:17 +01:00
|
|
|
protected $casts = [
|
|
|
|
'personal_team' => 'boolean',
|
|
|
|
];
|
2023-05-25 17:27:52 +01:00
|
|
|
|
|
|
|
public function routeNotificationForDiscord()
|
|
|
|
{
|
2023-07-27 21:26:15 +02:00
|
|
|
return data_get($this, 'discord_webhook_url', null);
|
2023-05-25 17:27:52 +01:00
|
|
|
}
|
2023-06-20 19:08:43 +02:00
|
|
|
public function routeNotificationForEmail(string $attribute = 'recipients')
|
2023-05-25 17:27:52 +01:00
|
|
|
{
|
2023-07-27 21:26:15 +02:00
|
|
|
$recipients = data_get($this, 'smtp_recipients', '');
|
2023-06-01 13:24:20 +02:00
|
|
|
if (is_null($recipients) || $recipients === '') {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return explode(',', $recipients);
|
2023-05-25 17:27:52 +01:00
|
|
|
}
|
|
|
|
|
2023-07-13 15:07:42 +02:00
|
|
|
public function subscription()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Subscription::class);
|
|
|
|
}
|
2023-04-26 15:38:50 +02:00
|
|
|
public function projects()
|
|
|
|
{
|
2023-03-27 10:44:31 +02:00
|
|
|
return $this->hasMany(Project::class);
|
|
|
|
}
|
2023-05-25 17:27:52 +01:00
|
|
|
|
2023-04-26 15:38:50 +02:00
|
|
|
public function servers()
|
|
|
|
{
|
2023-03-27 14:31:42 +02:00
|
|
|
return $this->hasMany(Server::class);
|
|
|
|
}
|
2023-05-25 17:27:52 +01:00
|
|
|
|
2023-04-26 15:38:50 +02:00
|
|
|
public function applications()
|
|
|
|
{
|
2023-03-30 19:50:27 +02:00
|
|
|
return $this->hasManyThrough(Application::class, Project::class);
|
|
|
|
}
|
2023-05-25 17:27:52 +01:00
|
|
|
|
2023-05-03 12:38:57 +02:00
|
|
|
public function privateKeys()
|
|
|
|
{
|
|
|
|
return $this->hasMany(PrivateKey::class);
|
|
|
|
}
|
2023-06-02 12:34:45 +02:00
|
|
|
public function members()
|
|
|
|
{
|
2023-06-09 15:55:21 +02:00
|
|
|
return $this->belongsToMany(User::class, 'team_user', 'team_id', 'user_id')->withPivot('role');
|
|
|
|
}
|
|
|
|
public function invitations()
|
|
|
|
{
|
|
|
|
return $this->hasMany(TeamInvitation::class);
|
2023-06-02 12:34:45 +02:00
|
|
|
}
|
2023-06-12 22:02:10 +02:00
|
|
|
public function sources()
|
|
|
|
{
|
|
|
|
$sources = collect([]);
|
|
|
|
$github_apps = $this->hasMany(GithubApp::class)->whereisPublic(false)->get();
|
|
|
|
$gitlab_apps = $this->hasMany(GitlabApp::class)->whereisPublic(false)->get();
|
|
|
|
// $bitbucket_apps = $this->hasMany(BitbucketApp::class)->get();
|
|
|
|
$sources = $sources->merge($github_apps)->merge($gitlab_apps);
|
|
|
|
return $sources;
|
|
|
|
}
|
2023-06-16 15:56:25 +02:00
|
|
|
public function isEmpty()
|
|
|
|
{
|
|
|
|
if ($this->projects()->count() === 0 && $this->servers()->count() === 0 && $this->privateKeys()->count() === 0 && $this->sources()->count() === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2023-07-27 21:26:15 +02:00
|
|
|
}
|