pixelfed/app/Http/Controllers/ReportController.php

180 lines
4.7 KiB
PHP
Raw Permalink Normal View History

2018-05-20 21:48:53 +00:00
<?php
namespace App\Http\Controllers;
2018-08-28 03:07:36 +00:00
use App\Profile;
use App\Report;
use App\Status;
use App\User;
2018-08-10 03:06:42 +00:00
use Auth;
2018-05-20 21:48:53 +00:00
use Illuminate\Http\Request;
2023-03-13 11:55:56 +00:00
use App\Jobs\ReportPipeline\ReportNotifyAdminViaEmail;
2018-05-20 21:48:53 +00:00
class ReportController extends Controller
{
2018-08-10 03:06:42 +00:00
protected $profile;
public function __construct()
{
2018-08-28 03:07:36 +00:00
$this->middleware('auth');
2018-08-10 03:06:42 +00:00
}
2018-05-20 21:48:53 +00:00
public function showForm(Request $request)
{
2018-08-28 03:07:36 +00:00
$this->validate($request, [
2018-08-10 03:06:42 +00:00
'type' => 'required|alpha_dash',
2018-08-28 03:07:36 +00:00
'id' => 'required|integer|min:1',
]);
2018-08-28 03:07:36 +00:00
return view('report.form');
2018-05-20 21:48:53 +00:00
}
public function notInterestedForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.not-interested');
2018-05-20 21:48:53 +00:00
}
public function spamForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.spam');
2018-05-20 21:48:53 +00:00
}
public function spamCommentForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.spam.comment');
2018-05-20 21:48:53 +00:00
}
public function spamPostForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.spam.post');
2018-05-20 21:48:53 +00:00
}
public function spamProfileForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.spam.profile');
2018-05-20 21:48:53 +00:00
}
2018-08-10 03:06:42 +00:00
public function sensitiveCommentForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.sensitive.comment');
2018-08-10 03:06:42 +00:00
}
public function sensitivePostForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.sensitive.post');
2018-08-10 03:06:42 +00:00
}
public function sensitiveProfileForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.sensitive.profile');
2018-08-10 03:06:42 +00:00
}
public function abusiveCommentForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.abusive.comment');
2018-08-10 03:06:42 +00:00
}
public function abusivePostForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.abusive.post');
2018-08-10 03:06:42 +00:00
}
public function abusiveProfileForm(Request $request)
{
2018-08-28 03:07:36 +00:00
return view('report.abusive.profile');
2018-08-10 03:06:42 +00:00
}
2018-08-28 03:07:36 +00:00
2018-08-10 03:06:42 +00:00
public function formStore(Request $request)
{
2018-08-28 03:07:36 +00:00
$this->validate($request, [
'report' => 'required|alpha_dash',
'type' => 'required|alpha_dash',
'id' => 'required|integer|min:1',
'msg' => 'nullable|string|max:150',
]);
2018-08-10 03:06:42 +00:00
2018-08-28 03:07:36 +00:00
$profile = Auth::user()->profile;
$reportType = $request->input('report');
$object_id = $request->input('id');
$object_type = $request->input('type');
$msg = $request->input('msg');
$object = null;
$types = [
// original 3
'spam',
'sensitive',
'abusive',
// new
'underage',
'copyright',
'impersonation',
'scam',
'terrorism'
];
2018-08-10 03:06:42 +00:00
2018-08-28 03:07:36 +00:00
if (!in_array($reportType, $types)) {
if($request->wantsJson()) {
return abort(400, 'Invalid report type');
} else {
return redirect('/timeline')->with('error', 'Invalid report type');
}
2018-08-28 03:07:36 +00:00
}
2018-08-10 03:06:42 +00:00
2018-08-28 03:07:36 +00:00
switch ($object_type) {
2018-08-10 03:06:42 +00:00
case 'post':
$object = Status::findOrFail($object_id);
$object_type = 'App\Status';
$exists = Report::whereUserId(Auth::id())
->whereObjectId($object->id)
->whereObjectType('App\Status')
->count();
break;
2018-08-28 03:07:36 +00:00
2018-08-10 03:06:42 +00:00
default:
if($request->wantsJson()) {
return abort(400, 'Invalid report type');
} else {
return redirect('/timeline')->with('error', 'Invalid report type');
}
2018-08-10 03:06:42 +00:00
break;
}
2018-08-28 03:07:36 +00:00
if ($exists !== 0) {
if($request->wantsJson()) {
return response()->json(200);
} else {
return redirect('/timeline')->with('error', 'You have already reported this!');
}
2018-08-28 03:07:36 +00:00
}
if ($object->profile_id == $profile->id) {
if($request->wantsJson()) {
return response()->json(200);
} else {
return redirect('/timeline')->with('error', 'You cannot report your own content!');
}
2018-08-28 03:07:36 +00:00
}
$report = new Report();
$report->profile_id = $profile->id;
$report->user_id = Auth::id();
$report->object_id = $object->id;
$report->object_type = $object_type;
$report->reported_profile_id = $object->profile_id;
$report->type = $request->input('report');
$report->message = e($request->input('msg'));
2018-08-28 03:07:36 +00:00
$report->save();
2023-03-13 11:55:56 +00:00
if(config('instance.reports.email.enabled')) {
ReportNotifyAdminViaEmail::dispatch($report)->onQueue('default');
}
if($request->wantsJson()) {
return response()->json(200);
} else {
return redirect('/timeline')->with('status', 'Report successfully sent!');
}
2018-08-10 03:06:42 +00:00
}
2018-05-20 21:48:53 +00:00
}