mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-08 05:43:18 +01:00
Add audit owner through parent model
Models that belong to an organization via a parent model (for example project members via their project) implement AuditableThroughParent and return the parent relation. The owner organization of their audits is taken from the loaded parent if it matches the foreign key, otherwise it is queried. The declaration is also used to backfill the owner of existing audits.
This commit is contained in:
committed by
Constantin Graf
parent
6fe721fc26
commit
34273a4863
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\AuditableThroughParent;
|
||||
use App\Models\Concerns\CustomAuditable;
|
||||
use App\Models\Concerns\HasUuids;
|
||||
use Database\Factories\ProjectMemberFactory;
|
||||
@@ -29,7 +30,7 @@ use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
|
||||
* @method static Builder<ProjectMember> whereBelongsToOrganization(Organization $organization)
|
||||
* @method static ProjectMemberFactory factory()
|
||||
*/
|
||||
class ProjectMember extends Model implements AuditableContract
|
||||
class ProjectMember extends Model implements AuditableContract, AuditableThroughParent
|
||||
{
|
||||
use CustomAuditable;
|
||||
|
||||
@@ -83,11 +84,11 @@ class ProjectMember extends Model implements AuditableContract
|
||||
});
|
||||
}
|
||||
|
||||
public function getAuditOwnerOrganizationId(): ?string
|
||||
/**
|
||||
* @return BelongsTo<Project, $this>
|
||||
*/
|
||||
public function getAuditParentRelation(): BelongsTo
|
||||
{
|
||||
/** @var string|null $organizationId */
|
||||
$organizationId = Project::query()->whereKey($this->project_id)->value('organization_id');
|
||||
|
||||
return $organizationId;
|
||||
return $this->project();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user