BookStack/app/Activity/Controllers/AuditLogController.php

71 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2023-05-17 12:56:55 -04:00
namespace BookStack\Activity\Controllers;
2023-05-17 12:56:55 -04:00
use BookStack\Activity\ActivityType;
use BookStack\Activity\Models\Activity;
use BookStack\Http\Controllers\Controller;
use BookStack\Util\SimpleListOptions;
use Illuminate\Http\Request;
class AuditLogController extends Controller
{
public function index(Request $request)
{
$this->checkPermission('settings-manage');
$this->checkPermission('users-manage');
$sort = $request->get('sort', 'activity_date');
$order = $request->get('order', 'desc');
$listOptions = (new SimpleListOptions('', $sort, $order))->withSortOptions([
'created_at' => trans('settings.audit_table_date'),
'type' => trans('settings.audit_table_event'),
]);
$filters = [
2021-06-26 11:23:15 -04:00
'event' => $request->get('event', ''),
'date_from' => $request->get('date_from', ''),
2021-06-26 11:23:15 -04:00
'date_to' => $request->get('date_to', ''),
'user' => $request->get('user', ''),
2021-11-26 00:08:04 -05:00
'ip' => $request->get('ip', ''),
];
$query = Activity::query()
->with([
'entity' => fn ($query) => $query->withTrashed(),
2021-06-26 11:23:15 -04:00
'user',
])
->orderBy($listOptions->getSort(), $listOptions->getOrder());
if ($filters['event']) {
$query->where('type', '=', $filters['event']);
}
if ($filters['user']) {
$query->where('user_id', '=', $filters['user']);
}
if ($filters['date_from']) {
$query->where('created_at', '>=', $filters['date_from']);
}
if ($filters['date_to']) {
$query->where('created_at', '<=', $filters['date_to']);
}
if ($filters['ip']) {
$query->where('ip', 'like', $filters['ip'] . '%');
2021-11-26 00:08:04 -05:00
}
$activities = $query->paginate(100);
$activities->appends($request->all());
$types = ActivityType::all();
$this->setPageTitle(trans('settings.audit'));
2021-06-26 11:23:15 -04:00
return view('settings.audit', [
2021-06-26 11:23:15 -04:00
'activities' => $activities,
'filters' => $filters,
'listOptions' => $listOptions,
'activityTypes' => $types,
]);
}
}