feat: complete Epic 0 — foundation migration & infrastructure setup
Stories 0.2-0.5: rename folders→declarations (backend+frontend), configure Redis for cache/queue/sessions, add foundation database migrations (permissions, archived_at), replace DeclarationStatus enum with architecture lifecycle values, create DeclarationObserver for status transition validation and auto-archive, fix controller status transitions to respect observer rules. 93 tests pass (240 assertions). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ use Spatie\Activitylog\Traits\LogsActivity;
|
||||
class Client extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ClientFactory> */
|
||||
use HasFactory, SoftDeletes, LogsActivity;
|
||||
use HasFactory, LogsActivity, SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -101,13 +101,13 @@ class Client extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folders for the client.
|
||||
* Get the declarations for the client.
|
||||
*
|
||||
* @return HasMany<Folder>
|
||||
* @return HasMany<Declaration>
|
||||
*/
|
||||
public function folders(): HasMany
|
||||
public function declarations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Folder::class);
|
||||
return $this->hasMany(Declaration::class);
|
||||
}
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\FolderPriority;
|
||||
use App\Enums\FolderStatus;
|
||||
use App\Enums\FolderType;
|
||||
use App\Enums\DeclarationPriority;
|
||||
use App\Enums\DeclarationStatus;
|
||||
use App\Enums\DeclarationType;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -15,11 +16,13 @@ use Spatie\Activitylog\Traits\LogsActivity;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
|
||||
class Folder extends Model implements HasMedia
|
||||
class Declaration extends Model implements HasMedia
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\FolderFactory> */
|
||||
/** @use HasFactory<\Database\Factories\DeclarationFactory> */
|
||||
use HasFactory, InteractsWithMedia, LogsActivity, SoftDeletes;
|
||||
|
||||
protected $table = 'declarations';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
@@ -49,6 +52,7 @@ class Folder extends Model implements HasMedia
|
||||
'refusal_reason',
|
||||
'notes_internal',
|
||||
'notes_client',
|
||||
'archived_at',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
@@ -60,13 +64,14 @@ class Folder extends Model implements HasMedia
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'type' => FolderType::class,
|
||||
'status' => FolderStatus::class,
|
||||
'priority' => FolderPriority::class,
|
||||
'type' => DeclarationType::class,
|
||||
'status' => DeclarationStatus::class,
|
||||
'priority' => DeclarationPriority::class,
|
||||
'validated_at' => 'datetime',
|
||||
'closed_at' => 'datetime',
|
||||
'confirmation_requested_at' => 'datetime',
|
||||
'refused_at' => 'datetime',
|
||||
'archived_at' => 'datetime',
|
||||
'due_date' => 'date',
|
||||
];
|
||||
}
|
||||
@@ -80,7 +85,7 @@ class Folder extends Model implements HasMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the workspace that owns the folder.
|
||||
* Get the workspace that owns the declaration.
|
||||
*
|
||||
* @return BelongsTo<Workspace, $this>
|
||||
*/
|
||||
@@ -90,7 +95,7 @@ class Folder extends Model implements HasMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the client that owns the folder.
|
||||
* Get the client that owns the declaration.
|
||||
*
|
||||
* @return BelongsTo<Client, $this>
|
||||
*/
|
||||
@@ -100,7 +105,7 @@ class Folder extends Model implements HasMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user who created the folder.
|
||||
* Get the user who created the declaration.
|
||||
*
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
@@ -110,7 +115,7 @@ class Folder extends Model implements HasMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user assigned to the folder.
|
||||
* Get the user assigned to the declaration.
|
||||
*
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
@@ -120,7 +125,7 @@ class Folder extends Model implements HasMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the messages for the folder.
|
||||
* Get the messages for the declaration.
|
||||
*
|
||||
* @return HasMany<Message>
|
||||
*/
|
||||
@@ -130,13 +135,29 @@ class Folder extends Model implements HasMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invitations for the folder.
|
||||
* Get the invitations for the declaration.
|
||||
*
|
||||
* @return HasMany<FolderInvitation>
|
||||
* @return HasMany<DeclarationInvitation>
|
||||
*/
|
||||
public function invitations(): HasMany
|
||||
{
|
||||
return $this->hasMany(FolderInvitation::class);
|
||||
return $this->hasMany(DeclarationInvitation::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include active (non-archived) declarations.
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->whereNull('archived_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope a query to only include archived declarations.
|
||||
*/
|
||||
public function scopeArchived(Builder $query): Builder
|
||||
{
|
||||
return $query->whereNotNull('archived_at');
|
||||
}
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
@@ -6,15 +6,17 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FolderInvitation extends Model
|
||||
class DeclarationInvitation extends Model
|
||||
{
|
||||
protected $table = 'declaration_invitations';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'folder_id',
|
||||
'declaration_id',
|
||||
'token',
|
||||
'email',
|
||||
'expires_at',
|
||||
@@ -41,7 +43,7 @@ class FolderInvitation extends Model
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function (FolderInvitation $invitation) {
|
||||
static::creating(function (DeclarationInvitation $invitation) {
|
||||
if (empty($invitation->token)) {
|
||||
$invitation->token = Str::uuid()->toString();
|
||||
}
|
||||
@@ -49,13 +51,13 @@ class FolderInvitation extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folder that owns the invitation.
|
||||
* Get the declaration that owns the invitation.
|
||||
*
|
||||
* @return BelongsTo<Folder, $this>
|
||||
* @return BelongsTo<Declaration, $this>
|
||||
*/
|
||||
public function folder(): BelongsTo
|
||||
public function declaration(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Folder::class);
|
||||
return $this->belongsTo(Declaration::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,7 +15,7 @@ class Message extends Model
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'folder_id',
|
||||
'declaration_id',
|
||||
'type',
|
||||
'body',
|
||||
'sent_by_type',
|
||||
@@ -38,13 +38,13 @@ class Message extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folder that owns the message.
|
||||
* Get the declaration that owns the message.
|
||||
*
|
||||
* @return BelongsTo<Folder, $this>
|
||||
* @return BelongsTo<Declaration, $this>
|
||||
*/
|
||||
public function folder(): BelongsTo
|
||||
public function declaration(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Folder::class);
|
||||
return $this->belongsTo(Declaration::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@ use Spatie\Activitylog\Traits\LogsActivity;
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable, SoftDeletes, TwoFactorAuthenticatable, LogsActivity;
|
||||
use HasFactory, LogsActivity, Notifiable, SoftDeletes, TwoFactorAuthenticatable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
||||
@@ -14,7 +14,7 @@ use Spatie\Activitylog\Traits\LogsActivity;
|
||||
class Workspace extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\WorkspaceFactory> */
|
||||
use HasFactory, SoftDeletes, LogsActivity;
|
||||
use HasFactory, LogsActivity, SoftDeletes;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -57,13 +57,13 @@ class Workspace extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folders for the workspace.
|
||||
* Get the declarations for the workspace.
|
||||
*
|
||||
* @return HasMany<Folder>
|
||||
* @return HasMany<Declaration>
|
||||
*/
|
||||
public function folders(): HasMany
|
||||
public function declarations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Folder::class);
|
||||
return $this->hasMany(Declaration::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,6 +21,7 @@ class WorkspaceUser extends Pivot
|
||||
*/
|
||||
protected $fillable = [
|
||||
'role',
|
||||
'permissions',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -32,6 +33,7 @@ class WorkspaceUser extends Pivot
|
||||
{
|
||||
return [
|
||||
'role' => WorkspaceUserRole::class,
|
||||
'permissions' => 'array',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user