2020-09-19 07:06:45 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Controllers;
|
|
|
|
|
|
|
|
use BookStack\Actions\Activity;
|
2022-10-30 16:24:08 -04:00
|
|
|
use BookStack\Actions\ActivityType;
|
|
|
|
use BookStack\Util\SimpleListOptions;
|
2020-09-19 07:06:45 -04:00
|
|
|
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');
|
|
|
|
|
2022-10-30 16:24:08 -04:00
|
|
|
$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', ''),
|
2020-09-19 07:06:45 -04:00
|
|
|
'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', ''),
|
2020-09-19 07:06:45 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
$query = Activity::query()
|
2020-11-06 07:54:39 -05:00
|
|
|
->with([
|
2022-10-30 16:24:08 -04:00
|
|
|
'entity' => fn ($query) => $query->withTrashed(),
|
2021-06-26 11:23:15 -04:00
|
|
|
'user',
|
2020-11-06 07:54:39 -05:00
|
|
|
])
|
2022-10-30 16:24:08 -04:00
|
|
|
->orderBy($listOptions->getSort(), $listOptions->getOrder());
|
2020-09-19 07:06:45 -04:00
|
|
|
|
2022-10-30 16:24:08 -04:00
|
|
|
if ($filters['event']) {
|
|
|
|
$query->where('type', '=', $filters['event']);
|
2020-09-19 07:06:45 -04:00
|
|
|
}
|
2022-10-30 16:24:08 -04:00
|
|
|
if ($filters['user']) {
|
|
|
|
$query->where('user_id', '=', $filters['user']);
|
2021-03-21 11:04:32 -04:00
|
|
|
}
|
2020-09-19 07:06:45 -04:00
|
|
|
|
2022-10-30 16:24:08 -04:00
|
|
|
if ($filters['date_from']) {
|
|
|
|
$query->where('created_at', '>=', $filters['date_from']);
|
2020-09-19 07:06:45 -04:00
|
|
|
}
|
2022-10-30 16:24:08 -04:00
|
|
|
if ($filters['date_to']) {
|
|
|
|
$query->where('created_at', '<=', $filters['date_to']);
|
2020-09-19 07:06:45 -04:00
|
|
|
}
|
2022-10-30 16:24:08 -04:00
|
|
|
if ($filters['ip']) {
|
|
|
|
$query->where('ip', 'like', $filters['ip'] . '%');
|
2021-11-26 00:08:04 -05:00
|
|
|
}
|
2020-09-19 07:06:45 -04:00
|
|
|
|
|
|
|
$activities = $query->paginate(100);
|
2022-10-30 16:24:08 -04:00
|
|
|
$activities->appends($request->all());
|
2020-09-19 07:06:45 -04:00
|
|
|
|
2022-10-30 16:24:08 -04:00
|
|
|
$types = ActivityType::all();
|
2020-09-19 07:06:45 -04:00
|
|
|
$this->setPageTitle(trans('settings.audit'));
|
2021-06-26 11:23:15 -04:00
|
|
|
|
2020-09-19 07:06:45 -04:00
|
|
|
return view('settings.audit', [
|
2021-06-26 11:23:15 -04:00
|
|
|
'activities' => $activities,
|
2022-10-30 16:24:08 -04:00
|
|
|
'filters' => $filters,
|
|
|
|
'listOptions' => $listOptions,
|
2020-11-07 19:03:19 -05:00
|
|
|
'activityTypes' => $types,
|
2020-09-19 07:06:45 -04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|