1
0
Fork 0
pixelfed/app/Http/Controllers/Admin/AdminReportController.php

85 lines
1.8 KiB
PHP
Raw Normal View History

2018-08-19 22:35:16 +00:00
<?php
namespace App\Http\Controllers\Admin;
2018-08-28 03:07:36 +00:00
use App\Report;
2018-08-19 22:35:16 +00:00
use Carbon\Carbon;
2018-08-28 03:07:36 +00:00
use Illuminate\Http\Request;
2018-08-19 22:35:16 +00:00
trait AdminReportController
{
public function updateReport(Request $request, $id)
{
2018-08-28 03:07:36 +00:00
$this->validate($request, [
'action' => 'required|string',
]);
2018-08-19 22:35:16 +00:00
2018-08-28 03:07:36 +00:00
$action = $request->input('action');
2018-08-19 22:35:16 +00:00
2018-08-28 03:07:36 +00:00
$actions = [
'ignore',
'cw',
'unlist',
'delete',
'shadowban',
'ban',
];
2018-08-19 22:35:16 +00:00
2018-08-28 03:07:36 +00:00
if (!in_array($action, $actions)) {
return abort(403);
}
2018-08-19 22:35:16 +00:00
2018-08-28 03:07:36 +00:00
$report = Report::findOrFail($id);
2018-08-19 22:35:16 +00:00
2018-08-28 03:07:36 +00:00
$this->handleReportAction($report, $action);
2018-08-19 22:35:16 +00:00
2018-08-28 03:07:36 +00:00
return response()->json(['msg'=> 'Success']);
2018-08-19 22:35:16 +00:00
}
public function handleReportAction(Report $report, $action)
{
2018-08-28 03:07:36 +00:00
$item = $report->reported();
$report->admin_seen = Carbon::now();
switch ($action) {
case 'ignore':
$report->not_interested = true;
break;
case 'cw':
$item->is_nsfw = true;
$item->save();
$report->nsfw = true;
break;
case 'unlist':
$item->visibility = 'unlisted';
$item->save();
break;
case 'delete':
// Todo: fire delete job
$report->admin_seen = null;
break;
case 'shadowban':
// Todo: fire delete job
$report->admin_seen = null;
break;
case 'ban':
// Todo: fire delete job
$report->admin_seen = null;
break;
default:
$report->admin_seen = null;
break;
}
$report->save();
return $this;
2018-08-19 22:35:16 +00:00
}
2018-08-28 03:07:36 +00:00
}