2020-09-19 07:06:45 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Controllers;
|
|
|
|
|
|
|
|
use BookStack\Actions\Activity;
|
|
|
|
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');
|
|
|
|
|
|
|
|
$listDetails = [
|
2021-06-26 11:23:15 -04:00
|
|
|
'order' => $request->get('order', 'desc'),
|
|
|
|
'event' => $request->get('event', ''),
|
|
|
|
'sort' => $request->get('sort', 'created_at'),
|
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([
|
|
|
|
'entity' => function ($query) {
|
|
|
|
$query->withTrashed();
|
|
|
|
},
|
2021-06-26 11:23:15 -04:00
|
|
|
'user',
|
2020-11-06 07:54:39 -05:00
|
|
|
])
|
2020-09-19 07:06:45 -04:00
|
|
|
->orderBy($listDetails['sort'], $listDetails['order']);
|
|
|
|
|
|
|
|
if ($listDetails['event']) {
|
2020-11-07 19:03:19 -05:00
|
|
|
$query->where('type', '=', $listDetails['event']);
|
2020-09-19 07:06:45 -04:00
|
|
|
}
|
2021-03-21 11:04:32 -04:00
|
|
|
if ($listDetails['user']) {
|
|
|
|
$query->where('user_id', '=', $listDetails['user']);
|
|
|
|
}
|
2020-09-19 07:06:45 -04:00
|
|
|
|
|
|
|
if ($listDetails['date_from']) {
|
|
|
|
$query->where('created_at', '>=', $listDetails['date_from']);
|
|
|
|
}
|
|
|
|
if ($listDetails['date_to']) {
|
|
|
|
$query->where('created_at', '<=', $listDetails['date_to']);
|
|
|
|
}
|
2021-11-26 00:08:04 -05:00
|
|
|
if ($listDetails['ip']) {
|
2021-12-07 04:04:11 -05:00
|
|
|
$query->where('ip', 'like', $listDetails['ip'] . "%");
|
2021-11-26 00:08:04 -05:00
|
|
|
}
|
2020-09-19 07:06:45 -04:00
|
|
|
|
|
|
|
$activities = $query->paginate(100);
|
|
|
|
$activities->appends($listDetails);
|
|
|
|
|
2020-11-07 19:03:19 -05:00
|
|
|
$types = DB::table('activities')->select('type')->distinct()->pluck('type');
|
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,
|
|
|
|
'listDetails' => $listDetails,
|
2020-11-07 19:03:19 -05:00
|
|
|
'activityTypes' => $types,
|
2020-09-19 07:06:45 -04:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|