audit
This commit is contained in:
parent
d1f8a2ef53
commit
7f770512cd
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use App\Http\Controllers\HashidControllerBase;
|
use App\Http\Controllers\HashidControllerBase;
|
||||||
use App\Models\Study;
|
use App\Models\Study;
|
||||||
|
use App\Services\AuditTrail\Activity;
|
||||||
|
|
||||||
class StudiesController extends HashidControllerBase
|
class StudiesController extends HashidControllerBase
|
||||||
{
|
{
|
||||||
@ -20,6 +21,10 @@ public function details()
|
|||||||
{
|
{
|
||||||
$this->decodeKeys();
|
$this->decodeKeys();
|
||||||
$study = Study::with(['series', 'details'])->findOrFail($this->key);
|
$study = Study::with(['series', 'details'])->findOrFail($this->key);
|
||||||
|
audit()
|
||||||
|
->did(Activity::Study_Metadata_View)
|
||||||
|
->on($study)
|
||||||
|
->log();
|
||||||
|
|
||||||
//return view('staff.studies.details', compact('study'));
|
//return view('staff.studies.details', compact('study'));
|
||||||
return response()->json($study);
|
return response()->json($study);
|
||||||
|
@ -7,11 +7,13 @@ final class Activity
|
|||||||
// studies
|
// studies
|
||||||
public const int Study_Open = 101;
|
public const int Study_Open = 101;
|
||||||
|
|
||||||
public const int Study_Metadata_Edit = 102;
|
public const int Study_Metadata_View = 102;
|
||||||
|
|
||||||
public const int Study_History_View = 103;
|
public const int Study_Metadata_Edit = 103;
|
||||||
|
|
||||||
public const int Study_History_Update = 104;
|
public const int Study_History_View = 104;
|
||||||
|
|
||||||
|
public const int Study_History_Update = 105;
|
||||||
|
|
||||||
// report
|
// report
|
||||||
|
|
||||||
|
@ -22,6 +22,13 @@ class ActivityLogger
|
|||||||
|
|
||||||
private ?string $userAgent = null;
|
private ?string $userAgent = null;
|
||||||
|
|
||||||
|
private ?string $ipAddr = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var true
|
||||||
|
*/
|
||||||
|
private bool $anonymous = false;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->category = Category::GENERAL;
|
$this->category = Category::GENERAL;
|
||||||
@ -34,10 +41,10 @@ public function on(Study $study): static
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function by(Authenticatable|int $user): static
|
public function by(Authenticatable|int|null $user = null): static
|
||||||
{
|
{
|
||||||
if ($user == null) {
|
if ($user === null) {
|
||||||
return $this;
|
$user = auth()->user();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user instanceof Authenticatable) {
|
if ($user instanceof Authenticatable) {
|
||||||
@ -84,14 +91,38 @@ public function ua(?string $agent = null): static
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function log(): bool
|
public function ip(?string $addr = null): static
|
||||||
{
|
{
|
||||||
|
$this->ipAddr = $addr ?? request()->ip();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function anon()
|
||||||
|
{
|
||||||
|
$this->anonymous = true;
|
||||||
|
$this->userId = null;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function log(bool $initDefaults = true): bool
|
||||||
|
{
|
||||||
|
if ($initDefaults) {
|
||||||
|
$this->ip();
|
||||||
|
$this->url();
|
||||||
|
$this->ua();
|
||||||
|
if ($this->userId === null && ! $this->anonymous) {
|
||||||
|
$this->by();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return DB::table('audit_logs')->insert([
|
return DB::table('audit_logs')->insert([
|
||||||
'study_id' => $this->studyId,
|
'study_id' => $this->studyId,
|
||||||
'user_id' => $this->userId,
|
'user_id' => $this->userId,
|
||||||
'category' => $this->category,
|
'category' => $this->category,
|
||||||
'activity' => $this->activity,
|
'activity' => $this->activity,
|
||||||
'ip_addr' => request()->ip(),
|
'ip_addr' => $this->ipAddr,
|
||||||
'user_agent' => $this->userAgent,
|
'user_agent' => $this->userAgent,
|
||||||
'url' => $this->url,
|
'url' => $this->url,
|
||||||
'notes' => $this->notes,
|
'notes' => $this->notes,
|
||||||
|
Loading…
Reference in New Issue
Block a user