mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +02:00

* add spatie/permissions * add policies * add role resource * add root admin role handling * replace some "root_admin" with function * add model specific permissions * make permission selection nicer * fix user creation * fix tests * add back subuser checks in server policy * add custom model for role * assign new users to role if root_admin is set * add api for roles * fix phpstan * add permissions for settings page * remove "restore" and "forceDelete" permissions * add user count to list * prevent deletion if role has users * update user list * fix server policy * remove old `root_admin` column * small refactor * fix tests * forgot can checks here * forgot use * disable editing own roles & disable assigning root admin * don't allow to rename root admin role * remove php bombing exception handler * fix role assignment when creating a user * fix disableOptionWhen * fix missing `root_admin` attribute on react frontend * add permission check for bulk delete * rename viewAny to viewList * improve canAccessPanel check * fix admin not displaying for non-root admins * make sure non root admins can't edit root admins * fix import * fix settings page permission check * fix server permissions for non-subusers * fix settings page permission check v2 * small cleanup * cleanup config file * move consts from resouce into enum & model * Update database/migrations/2024_08_01_114538_remove_root_admin_column.php Co-authored-by: Lance Pioch <lancepioch@gmail.com> * fix config * fix phpstan * fix phpstan 2.0 --------- Co-authored-by: Lance Pioch <lancepioch@gmail.com>
57 lines
2.3 KiB
PHP
57 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Client\Servers;
|
|
|
|
use App\Models\User;
|
|
use App\Models\Server;
|
|
use App\Models\Permission;
|
|
use App\Models\ActivityLog;
|
|
use Spatie\QueryBuilder\QueryBuilder;
|
|
use Spatie\QueryBuilder\AllowedFilter;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Query\JoinClause;
|
|
use App\Http\Requests\Api\Client\ClientApiRequest;
|
|
use App\Transformers\Api\Client\ActivityLogTransformer;
|
|
use App\Http\Controllers\Api\Client\ClientApiController;
|
|
use App\Models\Role;
|
|
|
|
class ActivityLogController extends ClientApiController
|
|
{
|
|
/**
|
|
* Returns the activity logs for a server.
|
|
*/
|
|
public function __invoke(ClientApiRequest $request, Server $server): array
|
|
{
|
|
$this->authorize(Permission::ACTION_ACTIVITY_READ, $server);
|
|
|
|
$activity = QueryBuilder::for($server->activity())
|
|
->allowedSorts(['timestamp'])
|
|
->allowedFilters([AllowedFilter::partial('event')])
|
|
->with('actor')
|
|
->whereNotIn('activity_logs.event', ActivityLog::DISABLED_EVENTS)
|
|
->when(config('activity.hide_admin_activity'), function (Builder $builder) use ($server) {
|
|
// We could do this with a query and a lot of joins, but that gets pretty
|
|
// painful so for now we'll execute a simpler query.
|
|
$subusers = $server->subusers()->pluck('user_id')->merge([$server->owner_id]);
|
|
$rootAdmins = Role::getRootAdmin()->users()->pluck('id');
|
|
|
|
$builder->select('activity_logs.*')
|
|
->leftJoin('users', function (JoinClause $join) {
|
|
$join->on('users.id', 'activity_logs.actor_id')
|
|
->where('activity_logs.actor_type', (new User())->getMorphClass());
|
|
})
|
|
->where(function (Builder $builder) use ($subusers, $rootAdmins) {
|
|
$builder->whereNull('users.id')
|
|
->orWhereNotIn('users.id', $rootAdmins)
|
|
->orWhereIn('users.id', $subusers);
|
|
});
|
|
})
|
|
->paginate(min($request->query('per_page', '25'), 100))
|
|
->appends($request->query());
|
|
|
|
return $this->fractal->collection($activity)
|
|
->transformWith($this->getTransformer(ActivityLogTransformer::class))
|
|
->toArray();
|
|
}
|
|
}
|