Add base logic for audit logging

This commit is contained in:
Dane Everitt 2021-01-17 10:49:36 -08:00
parent 9684456480
commit b15679d3bb
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 177 additions and 0 deletions

View file

@ -50,6 +50,7 @@ use Znck\Eloquent\Traits\BelongsToThrough;
* @property \Pterodactyl\Models\ServerTransfer $transfer
* @property \Pterodactyl\Models\Backup[]|\Illuminate\Database\Eloquent\Collection $backups
* @property \Pterodactyl\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts
* @property \Pterodactyl\Models\AuditLog[] $audits
*/
class Server extends Model
{
@ -326,4 +327,29 @@ class Server extends Model
{
return $this->hasManyThrough(Mount::class, MountServer::class, 'server_id', 'id', 'id', 'mount_id');
}
/**
* Saves an audit entry to the database for the server.
*
* @param string $action
* @param array $metadata
* @return \Pterodactyl\Models\AuditLog
*/
public function audit(string $action, array $metadata): AuditLog
{
$model = AuditLog::factory($action, $metadata)->fill([
'server_id' => $this->id,
]);
$model->save();
return $model;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function audits()
{
return $this->hasMany(AuditLog::class);
}
}