2023-03-24 13:54:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-05-25 16:27:52 +00:00
|
|
|
use App\Notifications\Channels\SendsDiscord;
|
2023-08-08 09:51:36 +00:00
|
|
|
use App\Notifications\Channels\SendsEmail;
|
2023-06-15 07:15:41 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-05-25 16:27:52 +00:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
2023-06-15 07:15:41 +00:00
|
|
|
class Team extends Model implements SendsDiscord, SendsEmail
|
2023-03-24 13:54:17 +00:00
|
|
|
{
|
2023-07-27 19:26:15 +00:00
|
|
|
use Notifiable;
|
2023-05-25 16:27:52 +00:00
|
|
|
|
2023-07-27 19:26:15 +00:00
|
|
|
protected $guarded = [];
|
2023-03-24 13:54:17 +00:00
|
|
|
protected $casts = [
|
|
|
|
'personal_team' => 'boolean',
|
|
|
|
];
|
2023-05-25 16:27:52 +00:00
|
|
|
|
|
|
|
public function routeNotificationForDiscord()
|
|
|
|
{
|
2023-07-27 19:26:15 +00:00
|
|
|
return data_get($this, 'discord_webhook_url', null);
|
2023-05-25 16:27:52 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-28 08:55:26 +00:00
|
|
|
public function getRecepients($notification)
|
2023-05-25 16:27:52 +00:00
|
|
|
{
|
2023-08-08 09:51:36 +00:00
|
|
|
$recipients = data_get($notification, 'emails', null);
|
2023-07-28 08:55:26 +00:00
|
|
|
if (is_null($recipients)) {
|
|
|
|
$recipients = $this->members()->pluck('email')->toArray();
|
|
|
|
return $recipients;
|
2023-06-01 11:24:20 +00:00
|
|
|
}
|
|
|
|
return explode(',', $recipients);
|
2023-05-25 16:27:52 +00:00
|
|
|
}
|
|
|
|
|
2023-08-08 09:51:36 +00:00
|
|
|
public function members()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(User::class, 'team_user', 'team_id', 'user_id')->withPivot('role');
|
|
|
|
}
|
|
|
|
|
2023-07-13 13:07:42 +00:00
|
|
|
public function subscription()
|
|
|
|
{
|
|
|
|
return $this->hasOne(Subscription::class);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function applications()
|
2023-04-26 13:38:50 +00:00
|
|
|
{
|
2023-08-08 09:51:36 +00:00
|
|
|
return $this->hasManyThrough(Application::class, Project::class);
|
2023-03-27 08:44:31 +00:00
|
|
|
}
|
2023-05-25 16:27:52 +00:00
|
|
|
|
2023-08-08 09:51:36 +00:00
|
|
|
public function invitations()
|
2023-04-26 13:38:50 +00:00
|
|
|
{
|
2023-08-08 09:51:36 +00:00
|
|
|
return $this->hasMany(TeamInvitation::class);
|
2023-03-27 12:31:42 +00:00
|
|
|
}
|
2023-05-25 16:27:52 +00:00
|
|
|
|
2023-08-08 09:51:36 +00:00
|
|
|
public function isEmpty()
|
2023-04-26 13:38:50 +00:00
|
|
|
{
|
2023-08-08 09:51:36 +00:00
|
|
|
if ($this->projects()->count() === 0 && $this->servers()->count() === 0 && $this->privateKeys()->count() === 0 && $this->sources()->count() === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2023-03-30 17:50:27 +00:00
|
|
|
}
|
2023-05-25 16:27:52 +00:00
|
|
|
|
2023-08-08 09:51:36 +00:00
|
|
|
public function projects()
|
2023-05-03 10:38:57 +00:00
|
|
|
{
|
2023-08-08 09:51:36 +00:00
|
|
|
return $this->hasMany(Project::class);
|
2023-05-03 10:38:57 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function servers()
|
2023-06-02 10:34:45 +00:00
|
|
|
{
|
2023-08-08 09:51:36 +00:00
|
|
|
return $this->hasMany(Server::class);
|
2023-06-09 13:55:21 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function privateKeys()
|
2023-06-09 13:55:21 +00:00
|
|
|
{
|
2023-08-08 09:51:36 +00:00
|
|
|
return $this->hasMany(PrivateKey::class);
|
2023-06-02 10:34:45 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-12 20:02:10 +00: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-08-09 12:44:36 +00:00
|
|
|
|
2023-08-11 14:13:53 +00:00
|
|
|
public function s3s()
|
2023-08-09 12:44:36 +00:00
|
|
|
{
|
2023-08-11 14:13:53 +00:00
|
|
|
return $this->hasMany(S3Storage::class);
|
2023-08-09 12:44:36 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|