From 039ad4abf04586011de484ce2942429d0ecbad75 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Mon, 21 Nov 2022 13:41:26 -0700 Subject: [PATCH] api(server): log activity when server description is changed --- .../Api/Client/Servers/SettingsController.php | 16 ++++++++++++---- app/Services/Activity/ActivityLogService.php | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Api/Client/Servers/SettingsController.php b/app/Http/Controllers/Api/Client/Servers/SettingsController.php index d1377d67a..6e6451836 100644 --- a/app/Http/Controllers/Api/Client/Servers/SettingsController.php +++ b/app/Http/Controllers/Api/Client/Servers/SettingsController.php @@ -34,14 +34,22 @@ class SettingsController extends ClientApiController */ public function rename(RenameServerRequest $request, Server $server): JsonResponse { + $name = $request->input('name'); + $description = $request->input('description') ?? ''; $this->repository->update($server->id, [ - 'name' => $request->input('name'), - 'description' => $request->input('description') ?? '', + 'name' => $name, + 'description' => $description, ]); - if ($server->name !== $request->input('name')) { + if ($server->name !== $name) { Activity::event('server:settings.rename') - ->property(['old' => $server->name, 'new' => $request->input('name')]) + ->property(['old' => $server->name, 'new' => $name]) + ->log(); + } + + if ($server->description !== $description) { + Activity::event('server:settings.description') + ->property(['old' => $server->description, 'new' => $description]) ->log(); } diff --git a/app/Services/Activity/ActivityLogService.php b/app/Services/Activity/ActivityLogService.php index fa4f46936..f86385214 100644 --- a/app/Services/Activity/ActivityLogService.php +++ b/app/Services/Activity/ActivityLogService.php @@ -99,7 +99,7 @@ class ActivityLogService } /** - * Sets a custom property on the activty log instance. + * Sets a custom property on the activity log instance. * * @param string|array $key * @param mixed $value @@ -115,7 +115,7 @@ class ActivityLogService } /** - * Attachs the instance request metadata to the activity log event. + * Attaches the instance request metadata to the activity log event. */ public function withRequestMetadata(): self {