Skip to content

Commit cf01490

Browse files
committed
Support hiding activity from admin accounts not associated with the server
1 parent 95de4c3 commit cf01490

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

app/Http/Controllers/Api/Client/Servers/ActivityLogController.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
44

5+
use Pterodactyl\Models\User;
56
use Pterodactyl\Models\Server;
67
use Pterodactyl\Models\Permission;
78
use Spatie\QueryBuilder\QueryBuilder;
89
use Spatie\QueryBuilder\AllowedFilter;
10+
use Illuminate\Database\Eloquent\Builder;
11+
use Illuminate\Database\Query\JoinClause;
912
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
1013
use Pterodactyl\Transformers\Api\Client\ActivityLogTransformer;
1114
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
@@ -26,6 +29,22 @@ public function __invoke(ClientApiRequest $request, Server $server): array
2629
AllowedFilter::exact('ip'),
2730
AllowedFilter::partial('event'),
2831
])
32+
->when(config('activity.hide_admin_activity'), function (Builder $builder) use ($server) {
33+
// We could do this with a query and a lot of joins, but that gets pretty
34+
// painful so for now we'll execute a simpler query.
35+
$subusers = $server->subusers()->pluck('user_id')->merge($server->owner_id);
36+
37+
$builder->select('activity_logs.*')
38+
->leftJoin('users', function (JoinClause $join) {
39+
$join->on('users.id', 'activity_logs.actor_id')
40+
->where('activity_logs.actor_type', (new User())->getMorphClass());
41+
})
42+
->where(function (Builder $builder) use ($subusers) {
43+
$builder->whereNull('users.id')
44+
->orWhere('users.root_admin', 0)
45+
->orWhereIn('users.id', $subusers);
46+
});
47+
})
2948
->paginate(min($request->query('per_page', 25), 100))
3049
->appends($request->query());
3150

config/activity.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<?php
22

33
return [
4-
/*
5-
* The number of days that must elapse before old activity log entries are deleted
6-
* from the database.
7-
*/
4+
// The number of days ellapsed before old activity log entries are deleted.
85
'prune_days' => env('APP_ACTIVITY_PRUNE_DAYS', 90),
6+
7+
// If set to true activity log entries generated by an admin user that is not also
8+
// a part of the server in question will be hidden from the activity logs API response.
9+
//
10+
// Activity will still be properly tracked, just not displayed.
11+
'hide_admin_activity' => env('APP_ACTIVITY_HIDE_ADMIN', false),
912
];

resources/scripts/components/elements/table/PaginationFooter.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const PaginationFooter = ({ pagination, className, onPageSelect }: Props) => {
2626
}
2727
}
2828

29+
if (pagination.total === 0) {
30+
return null;
31+
}
32+
2933
return (
3034
<div className={classNames('flex items-center justify-between my-2', className)}>
3135
<p className={'text-sm text-neutral-500'}>

resources/scripts/components/server/ServerActivityLogContainer.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ export default () => {
4848
{!data && isValidating ?
4949
<Spinner centered/>
5050
:
51-
<div className={'bg-gray-700'}>
52-
{data?.items.map((activity) => (
53-
<ActivityLogEntry key={activity.timestamp.toString() + activity.event} activity={activity}>
54-
<span/>
55-
</ActivityLogEntry>
56-
))}
57-
</div>
51+
!data?.items.length ?
52+
<p className={'text-sm text-center text-gray-400'}>No activity logs available for this server.</p>
53+
:
54+
<div className={'bg-gray-700'}>
55+
{data?.items.map((activity) => (
56+
<ActivityLogEntry key={activity.timestamp.toString() + activity.event} activity={activity}>
57+
<span/>
58+
</ActivityLogEntry>
59+
))}
60+
</div>
5861
}
5962
{data && <PaginationFooter
6063
pagination={data.pagination}

0 commit comments

Comments
 (0)