Always show IP address to admins

This commit is contained in:
DaneEveritt 2022-07-10 14:56:19 -04:00
parent d6c30092ec
commit d4708e9e63
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -5,6 +5,7 @@ namespace Pterodactyl\Transformers\Api\Client;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Pterodactyl\Models\User; use Pterodactyl\Models\User;
use Pterodactyl\Models\ActivityLog; use Pterodactyl\Models\ActivityLog;
use Illuminate\Database\Eloquent\Model;
class ActivityLogTransformer extends BaseClientTransformer class ActivityLogTransformer extends BaseClientTransformer
{ {
@ -25,7 +26,7 @@ class ActivityLogTransformer extends BaseClientTransformer
'batch' => $model->batch, 'batch' => $model->batch,
'event' => $model->event, 'event' => $model->event,
'is_api' => !is_null($model->api_key_id), 'is_api' => !is_null($model->api_key_id),
'ip' => optional($model->actor)->is($this->request->user()) ? $model->ip : null, 'ip' => $this->canViewIP($model->actor) ? $model->ip : null,
'description' => $model->description, 'description' => $model->description,
'properties' => $this->properties($model), 'properties' => $this->properties($model),
'has_additional_metadata' => $this->hasAdditionalMetadata($model), 'has_additional_metadata' => $this->hasAdditionalMetadata($model),
@ -105,4 +106,13 @@ class ActivityLogTransformer extends BaseClientTransformer
return false; return false;
} }
/**
* Determines if the user can view the IP address in the output either because they are the
* actor that performed the action, or because they are an administrator on the Panel.
*/
protected function canViewIP(Model $actor = null): bool
{
return optional($actor)->is($this->request->user()) || $this->request->user()->root_admin;
}
} }