Update audit design

This commit is contained in:
Dane Everitt 2021-01-17 11:52:44 -08:00
parent ccecaa6694
commit 291c65275a
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 16 additions and 15 deletions

View file

@ -146,10 +146,8 @@ class FileController extends ClientApiController
public function write(WriteFileContentRequest $request, Server $server): JsonResponse public function write(WriteFileContentRequest $request, Server $server): JsonResponse
{ {
$server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = [ $audit->subaction = 'write_content';
'file' => $request->get('file'), $audit->metadata = ['file' => $request->get('file')];
'sub_action' => 'write_content',
];
$this->fileRepository $this->fileRepository
->setServer($server) ->setServer($server)
@ -171,10 +169,8 @@ class FileController extends ClientApiController
public function create(CreateFolderRequest $request, Server $server): JsonResponse public function create(CreateFolderRequest $request, Server $server): JsonResponse
{ {
$server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = [ $audit->subaction = 'create_folder';
'file' => $request->input('root', '/') . $request->input('name'), $audit->metadata = ['file' => $request->input('root', '/') . $request->input('name')];
'sub_action' => 'create_folder',
];
$this->fileRepository $this->fileRepository
->setServer($server) ->setServer($server)
@ -218,10 +214,9 @@ class FileController extends ClientApiController
public function copy(CopyFileRequest $request, Server $server): JsonResponse public function copy(CopyFileRequest $request, Server $server): JsonResponse
{ {
$server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) { $server->audit(AuditLog::ACTION_SERVER_FILESYSTEM_WRITE, function (AuditLog $audit, Server $server) use ($request) {
$audit->metadata = [ $audit->subaction = 'copy_file';
'file' => $request->input('location'), $audit->metadata = ['file' => $request->input('location')];
'sub_action' => 'copy_file',
];
$this->fileRepository $this->fileRepository
->setServer($server) ->setServer($server)
->copyFile($request->input('location')); ->copyFile($request->input('location'));

View file

@ -13,6 +13,7 @@ use Illuminate\Container\Container;
* @property int|null $user_id * @property int|null $user_id
* @property int|null $server_id * @property int|null $server_id
* @property string $action * @property string $action
* @property string|null $subaction
* @property array $device * @property array $device
* @property array $metadata * @property array $metadata
* @property \Carbon\CarbonImmutable $created_at * @property \Carbon\CarbonImmutable $created_at
@ -49,7 +50,8 @@ class AuditLog extends Model
*/ */
public static $validationRules = [ public static $validationRules = [
'uuid' => 'required|uuid', 'uuid' => 'required|uuid',
'action' => 'required|string', 'action' => 'required|string|max:191',
'subaction' => 'nullable|string|max:191',
'device' => 'array', 'device' => 'array',
'device.ip_address' => 'ip', 'device.ip_address' => 'ip',
'device.user_agent' => 'string', 'device.user_agent' => 'string',

View file

@ -17,12 +17,16 @@ class CreateAuditLogsTable extends Migration
$table->id(); $table->id();
$table->char('uuid', 36); $table->char('uuid', 36);
$table->boolean('is_system')->default(false); $table->boolean('is_system')->default(false);
$table->bigInteger('user_id')->nullable(); $table->unsignedInteger('user_id')->nullable();
$table->bigInteger('server_id')->nullable(); $table->unsignedInteger('server_id')->nullable();
$table->string('action'); $table->string('action');
$table->string('subaction')->nullable();
$table->json('device'); $table->json('device');
$table->json('metadata'); $table->json('metadata');
$table->timestamp('created_at', 0); $table->timestamp('created_at', 0);
$table->foreign('user_id')->references('id')->on('users')->onDelete('set null');
$table->foreign('server_id')->references('id')->on('servers')->onDelete('cascade');
}); });
} }