45
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Assignment extends Model
|
||||
{
|
||||
protected $fillable = ['tenant_id', 'template_id', 'directory_group_id', 'priority'];
|
||||
|
||||
public function template(): BelongsTo { return $this->belongsTo(Template::class); }
|
||||
public function group(): BelongsTo { return $this->belongsTo(DirectoryGroup::class, 'directory_group_id'); }
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AuditLog extends Model
|
||||
{
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['changes' => 'array'];
|
||||
}
|
||||
|
||||
public static function record(string $actorType, ?string $actor, string $action, ?Model $subject = null, array $changes = [], ?int $tenantId = null): self
|
||||
{
|
||||
return static::create([
|
||||
'tenant_id' => $tenantId ?? ($subject?->tenant_id ?? null),
|
||||
'actor_type' => $actorType,
|
||||
'actor' => $actor,
|
||||
'action' => $action,
|
||||
'subject_type' => $subject ? $subject::class : null,
|
||||
'subject_id' => $subject?->getKey(),
|
||||
'changes' => $changes ?: null,
|
||||
'ip' => request()?->ip(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Campaign extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['starts_at' => 'datetime', 'ends_at' => 'datetime', 'active' => 'boolean'];
|
||||
}
|
||||
|
||||
public function groups(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(DirectoryGroup::class, 'campaign_group');
|
||||
}
|
||||
|
||||
public function scopeRunning(Builder $q): Builder
|
||||
{
|
||||
return $q->where('active', true)->where('starts_at', '<=', now())->where('ends_at', '>=', now());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class DirectoryGroup extends Model
|
||||
{
|
||||
protected $fillable = ['tenant_id', 'entra_oid', 'display_name', 'synced_at'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['synced_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); }
|
||||
|
||||
public function members(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(DirectoryUser::class, 'group_members');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/** Copie locale d'un utilisateur Entra (alimentée par la synchro Graph, jamais modifiée à la main). */
|
||||
class DirectoryUser extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['account_enabled' => 'boolean', 'synced_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); }
|
||||
|
||||
public function groups(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(DirectoryGroup::class, 'group_members');
|
||||
}
|
||||
|
||||
public function overrides(): HasMany { return $this->hasMany(UserOverride::class); }
|
||||
public function preference(): HasOne { return $this->hasOne(UserPreference::class); }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EditableField extends Model
|
||||
{
|
||||
protected $fillable = ['tenant_id', 'field', 'label', 'enabled', 'validation_rule'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['enabled' => 'boolean'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SharedMailbox extends Model
|
||||
{
|
||||
protected $fillable = ['tenant_id', 'address', 'display_name', 'template_id', 'include_sender'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['include_sender' => 'boolean'];
|
||||
}
|
||||
|
||||
public function template(): BelongsTo { return $this->belongsTo(Template::class); }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Template extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['is_default' => 'boolean', 'editor_state' => 'array', 'published_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); }
|
||||
public function versions(): HasMany { return $this->hasMany(TemplateVersion::class); }
|
||||
public function assignments(): HasMany { return $this->hasMany(Assignment::class); }
|
||||
|
||||
/** Publie le brouillon : copie vers le contenu servi + nouvelle version d'historique. */
|
||||
public function publish(?User $by = null): void
|
||||
{
|
||||
$this->html_full = $this->draft_html_full ?? $this->html_full;
|
||||
$this->html_short = $this->draft_html_short ?? $this->html_short;
|
||||
$this->published_version++;
|
||||
$this->published_at = now();
|
||||
$this->save();
|
||||
|
||||
$this->versions()->create([
|
||||
'version' => $this->published_version,
|
||||
'html_full' => $this->html_full,
|
||||
'html_short' => $this->html_short,
|
||||
'published_by' => $by?->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class TemplateVersion extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function template(): BelongsTo { return $this->belongsTo(Template::class); }
|
||||
public function publisher(): BelongsTo { return $this->belongsTo(User::class, 'published_by'); }
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Tenant extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'entra_tenant_id', 'active', 'users_delta_link', 'last_sync_at', 'last_sync_status'];
|
||||
|
||||
protected $hidden = ['users_delta_link'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['active' => 'boolean', 'last_sync_at' => 'datetime'];
|
||||
}
|
||||
|
||||
public function users(): HasMany { return $this->hasMany(DirectoryUser::class); }
|
||||
public function groups(): HasMany { return $this->hasMany(DirectoryGroup::class); }
|
||||
public function templates(): HasMany { return $this->hasMany(Template::class); }
|
||||
public function assignments(): HasMany { return $this->hasMany(Assignment::class); }
|
||||
public function campaigns(): HasMany { return $this->hasMany(Campaign::class); }
|
||||
public function sharedMailboxes(): HasMany { return $this->hasMany(SharedMailbox::class); }
|
||||
public function editableFields(): HasMany { return $this->hasMany(EditableField::class); }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
/** Compte du back-office (connexion SSO Entra uniquement). */
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
public const ROLE_RANK = ['editor' => 1, 'admin' => 2, 'superadmin' => 3];
|
||||
|
||||
protected $fillable = ['name', 'email', 'tenant_id', 'entra_oid', 'role'];
|
||||
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
|
||||
public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); }
|
||||
|
||||
public function hasRole(string $minimum): bool
|
||||
{
|
||||
return (self::ROLE_RANK[$this->role] ?? 0) >= (self::ROLE_RANK[$minimum] ?? PHP_INT_MAX);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserOverride extends Model
|
||||
{
|
||||
protected $fillable = ['directory_user_id', 'field', 'value'];
|
||||
|
||||
public function user(): BelongsTo { return $this->belongsTo(DirectoryUser::class, 'directory_user_id'); }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserPreference extends Model
|
||||
{
|
||||
protected $fillable = ['directory_user_id', 'reply_variant'];
|
||||
}
|
||||
Reference in New Issue
Block a user