55use Illuminate \Support \Str ;
66use Pterodactyl \Models \User ;
77use Pterodactyl \Models \ActivityLog ;
8+ use Illuminate \Database \Eloquent \Model ;
89
910class ActivityLogTransformer extends BaseClientTransformer
1011{
@@ -25,7 +26,7 @@ public function transform(ActivityLog $model): array
2526 'batch ' => $ model ->batch ,
2627 'event ' => $ model ->event ,
2728 'is_api ' => !is_null ($ model ->api_key_id ),
28- 'ip ' => optional ( $ model -> actor )-> is ( $ this -> request -> user () ) ? $ model ->ip : null ,
29+ 'ip ' => $ this -> canViewIP ( $ model -> actor ) ? $ model ->ip : null ,
2930 'description ' => $ model ->description ,
3031 'properties ' => $ this ->properties ($ model ),
3132 'has_additional_metadata ' => $ this ->hasAdditionalMetadata ($ model ),
@@ -105,4 +106,13 @@ protected function hasAdditionalMetadata(ActivityLog $model): bool
105106
106107 return false ;
107108 }
109+
110+ /**
111+ * Determines if the user can view the IP address in the output either because they are the
112+ * actor that performed the action, or because they are an administrator on the Panel.
113+ */
114+ protected function canViewIP (Model $ actor = null ): bool
115+ {
116+ return optional ($ actor )->is ($ this ->request ->user ()) || $ this ->request ->user ()->root_admin ;
117+ }
108118}
0 commit comments