Skip to content

Commit d4708e9

Browse files
committed
Always show IP address to admins
1 parent d6c3009 commit d4708e9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/Transformers/Api/Client/ActivityLogTransformer.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Str;
66
use Pterodactyl\Models\User;
77
use Pterodactyl\Models\ActivityLog;
8+
use Illuminate\Database\Eloquent\Model;
89

910
class 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

Comments
 (0)