BookStack/app/Http/Controllers/AuditLogController.php

71 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace BookStack\Http\Controllers;
use BookStack\Actions\Activity;
use BookStack\Actions\ActivityType;
use BookStack\Util\SimpleListOptions;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
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,
]);
}
}