Feature: Creating Privacy Basics
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Privacy\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Lunar\Models\Customer;
|
||||
use Modules\Core\Privacy\ErasureRequestStatus;
|
||||
|
||||
/**
|
||||
* A pending, cancelled, or completed right-of-erasure request — the grace-period
|
||||
* record between "subject/staff asked for this" and "providers actually erased
|
||||
* their data" (see Modules\Core\Privacy\PrivacyService, which creates/processes
|
||||
* these).
|
||||
*
|
||||
* `subject` is polymorphic — either a Lunar Customer (business account) or a User
|
||||
* (individual), never both. See docs/privacy.md "User-scope vs Customer-scope" for
|
||||
* why these are two genuinely different operations with different blast radii,
|
||||
* not one "erase this customer and cascade to their users" flow.
|
||||
*
|
||||
* `requestedBy` is separately polymorphic (the subject themselves, self-service,
|
||||
* or Staff acting on their behalf), stored as plain type+id columns rather than
|
||||
* morphs() since it's always exactly one of those two concrete actor types.
|
||||
*/
|
||||
class DataErasureRequest extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'status' => ErasureRequestStatus::class,
|
||||
'scheduled_for' => 'datetime',
|
||||
'cancelled_at' => 'datetime',
|
||||
'completed_at' => 'datetime',
|
||||
'report' => 'array',
|
||||
];
|
||||
|
||||
public function subject(): MorphTo
|
||||
{
|
||||
return $this->morphTo(__FUNCTION__, 'subject_type', 'subject_id');
|
||||
}
|
||||
|
||||
public function requestedBy(): MorphTo
|
||||
{
|
||||
return $this->morphTo(__FUNCTION__, 'requested_by_type', 'requested_by_id');
|
||||
}
|
||||
|
||||
public function isForCustomer(): bool
|
||||
{
|
||||
return $this->subject_type === (new Customer)->getMorphClass();
|
||||
}
|
||||
|
||||
public function isPending(): bool
|
||||
{
|
||||
return $this->status === ErasureRequestStatus::Pending;
|
||||
}
|
||||
|
||||
public function isDue(): bool
|
||||
{
|
||||
return $this->isPending() && $this->scheduled_for->isPast();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\Privacy\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Lunar\Models\Customer;
|
||||
use Modules\Core\Privacy\ExportRequestStatus;
|
||||
|
||||
/**
|
||||
* A right-of-access export request. Created synchronously (fast — one insert), then
|
||||
* ExportDataSubjectJob (queued) does the actual work of gathering every registered
|
||||
* provider's data and, via Modules\Core\Privacy\Listeners\WriteExportToCsvListener,
|
||||
* writing it to a file. file_path is null until that completes.
|
||||
*
|
||||
* `subject` is polymorphic — either a Lunar Customer (business account) or a User
|
||||
* (individual), never both. See docs/privacy.md "User-scope vs Customer-scope".
|
||||
*/
|
||||
class DataExportRequest extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'status' => ExportRequestStatus::class,
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function subject(): MorphTo
|
||||
{
|
||||
return $this->morphTo(__FUNCTION__, 'subject_type', 'subject_id');
|
||||
}
|
||||
|
||||
public function isForCustomer(): bool
|
||||
{
|
||||
return $this->subject_type === (new Customer)->getMorphClass();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user