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

View file

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

View file

@ -17,12 +17,16 @@ class CreateAuditLogsTable extends Migration
$table->id();
$table->char('uuid', 36);
$table->boolean('is_system')->default(false);
$table->bigInteger('user_id')->nullable();
$table->bigInteger('server_id')->nullable();
$table->unsignedInteger('user_id')->nullable();
$table->unsignedInteger('server_id')->nullable();
$table->string('action');
$table->string('subaction')->nullable();
$table->json('device');
$table->json('metadata');
$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');
});
}