Add tenant lifecycle view and limit controls
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-01 19:36:51 +01:00
parent 117250879b
commit da06db2d3b
22 changed files with 1312 additions and 148 deletions

View File

@@ -31,8 +31,11 @@ class Tenant extends Model
'total_revenue' => 'decimal:2',
'settings_updated_at' => 'datetime',
'subscription_expires_at' => 'datetime',
'grace_period_ends_at' => 'datetime',
'credit_warning_sent_at' => 'datetime',
'credit_warning_threshold' => 'integer',
'max_photos_per_event' => 'integer',
'max_storage_mb' => 'integer',
];
public function events(): HasMany
@@ -84,6 +87,11 @@ class Tenant extends Model
return $this->hasMany(TenantNotificationLog::class);
}
public function lifecycleEvents(): HasMany
{
return $this->hasMany(TenantLifecycleEvent::class);
}
public function canCreateEvent(): bool
{
return $this->hasEventAllowance();
@@ -174,4 +182,20 @@ class Tenant extends Model
{
return $this->belongsTo(User::class);
}
public function getStorageQuotaAttribute(): int
{
$limitMb = (int) ($this->max_storage_mb ?? 0);
return max(0, $limitMb) * 1024 * 1024;
}
public function isInGracePeriod(): bool
{
if (! $this->grace_period_ends_at) {
return false;
}
return now()->lessThanOrEqualTo($this->grace_period_ends_at);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class TenantLifecycleEvent extends Model
{
use HasFactory;
protected $guarded = [];
protected $casts = [
'payload' => 'array',
'occurred_at' => 'datetime',
];
public function tenant(): BelongsTo
{
return $this->belongsTo(Tenant::class);
}
public function actor(): BelongsTo
{
return $this->belongsTo(User::class, 'actor_id');
}
}