Merge branch 'v4-next' into notifications

This commit is contained in:
Andras Bacsai
2023-06-01 08:22:07 +02:00
204 changed files with 5744 additions and 2545 deletions

View File

@@ -41,14 +41,6 @@ class Application extends BaseModel
'private_key_id'
];
public $casts = [
'previews' => SchemalessAttributes::class,
'limits_memory_oom_kill' => 'boolean',
];
public function scopeWithExtraAttributes(): Builder
{
return $this->previews->modelScope();
}
public function publishDirectory(): Attribute
{
return Attribute::make(
@@ -131,6 +123,10 @@ class Application extends BaseModel
{
return $this->belongsTo(Environment::class);
}
public function previews()
{
return $this->hasMany(ApplicationPreview::class);
}
public function settings()
{
return $this->hasOne(ApplicationSetting::class);
@@ -148,9 +144,15 @@ class Application extends BaseModel
return $this->morphMany(LocalPersistentVolume::class, 'resource');
}
public function deployments()
public function deployments(int $skip = 0, int $take = 10)
{
return Activity::where('subject_id', $this->id)->where('properties->type', '=', 'deployment')->orderBy('created_at', 'desc')->get();
$deployments = ApplicationDeploymentQueue::where('application_id', $this->id)->orderBy('created_at', 'desc');
$count = $deployments->count();
$deployments = $deployments->skip($skip)->take($take)->get();
return [
'count' => $count,
'deployments' => $deployments
];
}
public function get_deployment(string $deployment_uuid)
{
@@ -158,7 +160,14 @@ class Application extends BaseModel
}
public function isDeployable(): bool
{
if ($this->settings->is_auto_deploy) {
if ($this->settings->is_auto_deploy_enabled) {
return true;
}
return false;
}
public function isPRDeployable(): bool
{
if ($this->settings->is_preview_deployments_enabled) {
return true;
}
return false;

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
class ApplicationDeploymentQueue extends Model
{
protected $fillable = [
'application_id',
'deployment_uuid',
'pull_request_id',
'force_rebuild',
'commit',
'status',
'is_webhook',
];
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
class ApplicationPreview extends BaseModel
{
protected $fillable = [
'uuid',
'pull_request_id',
'pull_request_html_url',
'fqdn',
'status',
'application_id',
];
public function application()
{
return $this->belongsTo(Application::class);
}
static function findPreviewByApplicationAndPullId(int $application_id, int $pull_request_id)
{
return self::where('application_id', $application_id)->where('pull_request_id', $pull_request_id)->firstOrFail();
}
}

View File

@@ -7,21 +7,37 @@ use Illuminate\Database\Eloquent\Model;
class ApplicationSetting extends Model
{
protected $cast = [
'is_static' => 'boolean',
'is_auto_deploy_enabled' => 'boolean',
'is_force_https_enabled' => 'boolean',
'is_debug_enabled' => 'boolean',
'is_preview_deployments_enabled' => 'boolean',
'is_git_submodules_enabled' => 'boolean',
'is_git_lfs_enabled' => 'boolean',
];
protected $fillable = [
'application_id',
'is_git_submodules_allowed',
'is_git_lfs_allowed',
'is_static',
'is_auto_deploy_enabled',
'is_force_https_enabled',
'is_debug_enabled',
'is_preview_deployments_enabled',
'is_git_submodules_enabled',
'is_git_lfs_enabled',
];
public function isStatic(): Attribute
{
return Attribute::make(
set: function ($value) {
if ($value) {
$this->application->ports_exposes = '80';
} else {
$this->application->ports_exposes = '3000';
if (is_null($this->application->ports_exposes)) {
if ($value) {
$this->application->ports_exposes = '80';
} else {
$this->application->ports_exposes = '3000';
}
$this->application->save();
}
$this->application->save();
return $value;
}
);

View File

@@ -12,8 +12,4 @@ class Database extends BaseModel
{
return $this->morphTo();
}
public function deployments()
{
return $this->morphMany(Deployment::class, 'type');
}
}

View File

@@ -28,6 +28,11 @@ class Server extends BaseModel
'extra_attributes' => SchemalessAttributes::class,
];
public function scopeWithExtraAttributes(): Builder
{
return $this->extra_attributes->modelScope();
}
public function standaloneDockers()
{
return $this->hasMany(StandaloneDocker::class);
@@ -38,10 +43,7 @@ class Server extends BaseModel
return $this->hasMany(SwarmDocker::class);
}
public function scopeWithExtraAttributes(): Builder
{
return $this->extra_attributes->modelScope();
}
public function privateKey()
{

View File

@@ -12,38 +12,19 @@ use Visus\Cuid2\Cuid2;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'id',
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
protected static function boot()
{
parent::boot();
@@ -52,9 +33,15 @@ class User extends Authenticatable
$model->uuid = (string) new Cuid2(7);
});
}
public function isRoot()
public function isPartOfRootTeam()
{
return $this->id == 0;
$found_root_team = auth()->user()->teams->filter(function ($team) {
if ($team->id == 0) {
return true;
}
return false;
});
return $found_root_team->count() > 0;
}
public function teams()
{
@@ -68,15 +55,14 @@ class User extends Authenticatable
public function otherTeams()
{
$team_id = data_get(session('currentTeam'), 'id');
$team_id = session('currentTeam')->id;
return auth()->user()->teams->filter(function ($team) use ($team_id) {
return $team->id != $team_id;
});
}
public function resources()
{
$team_id = data_get(session('currentTeam'), 'id');
$team_id = session('currentTeam')->id;
$data = Application::where('team_id', $team_id)->get();
return $data;
}