mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-12 17:44:31 +00:00
Update AdminController, move report methods to AdminReports trait
This commit is contained in:
parent
a956b50e8e
commit
dff3dad1c8
2 changed files with 186 additions and 174 deletions
|
@ -3,16 +3,200 @@
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use Cache;
|
use Cache;
|
||||||
use App\Report;
|
|
||||||
use App\User;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Illuminate\Support\Facades\Redis;
|
||||||
use App\Services\AccountService;
|
use App\Services\AccountService;
|
||||||
use App\Services\StatusService;
|
use App\Services\StatusService;
|
||||||
|
use App\{
|
||||||
|
AccountInterstitial,
|
||||||
|
Contact,
|
||||||
|
Hashtag,
|
||||||
|
Newsroom,
|
||||||
|
OauthClient,
|
||||||
|
Profile,
|
||||||
|
Report,
|
||||||
|
Status,
|
||||||
|
Story,
|
||||||
|
User
|
||||||
|
};
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use App\Services\StoryService;
|
||||||
|
|
||||||
trait AdminReportController
|
trait AdminReportController
|
||||||
{
|
{
|
||||||
|
public function reports(Request $request)
|
||||||
|
{
|
||||||
|
$filter = $request->input('filter') == 'closed' ? 'closed' : 'open';
|
||||||
|
$page = $request->input('page') ?? 1;
|
||||||
|
|
||||||
|
$ai = Cache::remember('admin-dash:reports:ai-count', 3600, function() {
|
||||||
|
return AccountInterstitial::whereNotNull('appeal_requested_at')->whereNull('appeal_handled_at')->count();
|
||||||
|
});
|
||||||
|
|
||||||
|
$spam = Cache::remember('admin-dash:reports:spam-count', 3600, function() {
|
||||||
|
return AccountInterstitial::whereType('post.autospam')->whereNull('appeal_handled_at')->count();
|
||||||
|
});
|
||||||
|
|
||||||
|
$mailVerifications = Redis::scard('email:manual');
|
||||||
|
|
||||||
|
if($filter == 'open' && $page == 1) {
|
||||||
|
$reports = Cache::remember('admin-dash:reports:list-cache', 300, function() use($page, $filter) {
|
||||||
|
return Report::whereHas('status')
|
||||||
|
->whereHas('reportedUser')
|
||||||
|
->whereHas('reporter')
|
||||||
|
->orderBy('created_at','desc')
|
||||||
|
->when($filter, function($q, $filter) {
|
||||||
|
return $filter == 'open' ?
|
||||||
|
$q->whereNull('admin_seen') :
|
||||||
|
$q->whereNotNull('admin_seen');
|
||||||
|
})
|
||||||
|
->paginate(6);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$reports = Report::whereHas('status')
|
||||||
|
->whereHas('reportedUser')
|
||||||
|
->whereHas('reporter')
|
||||||
|
->orderBy('created_at','desc')
|
||||||
|
->when($filter, function($q, $filter) {
|
||||||
|
return $filter == 'open' ?
|
||||||
|
$q->whereNull('admin_seen') :
|
||||||
|
$q->whereNotNull('admin_seen');
|
||||||
|
})
|
||||||
|
->paginate(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.reports.home', compact('reports', 'ai', 'spam', 'mailVerifications'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showReport(Request $request, $id)
|
||||||
|
{
|
||||||
|
$report = Report::findOrFail($id);
|
||||||
|
return view('admin.reports.show', compact('report'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function appeals(Request $request)
|
||||||
|
{
|
||||||
|
$appeals = AccountInterstitial::whereNotNull('appeal_requested_at')
|
||||||
|
->whereNull('appeal_handled_at')
|
||||||
|
->latest()
|
||||||
|
->paginate(6);
|
||||||
|
return view('admin.reports.appeals', compact('appeals'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showAppeal(Request $request, $id)
|
||||||
|
{
|
||||||
|
$appeal = AccountInterstitial::whereNotNull('appeal_requested_at')
|
||||||
|
->whereNull('appeal_handled_at')
|
||||||
|
->findOrFail($id);
|
||||||
|
$meta = json_decode($appeal->meta);
|
||||||
|
return view('admin.reports.show_appeal', compact('appeal', 'meta'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function spam(Request $request)
|
||||||
|
{
|
||||||
|
$appeals = AccountInterstitial::whereType('post.autospam')
|
||||||
|
->whereNull('appeal_handled_at')
|
||||||
|
->latest()
|
||||||
|
->paginate(6);
|
||||||
|
return view('admin.reports.spam', compact('appeals'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function showSpam(Request $request, $id)
|
||||||
|
{
|
||||||
|
$appeal = AccountInterstitial::whereType('post.autospam')
|
||||||
|
->whereNull('appeal_handled_at')
|
||||||
|
->findOrFail($id);
|
||||||
|
$meta = json_decode($appeal->meta);
|
||||||
|
return view('admin.reports.show_spam', compact('appeal', 'meta'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSpam(Request $request, $id)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'action' => 'required|in:dismiss,approve'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$action = $request->input('action');
|
||||||
|
$appeal = AccountInterstitial::whereType('post.autospam')
|
||||||
|
->whereNull('appeal_handled_at')
|
||||||
|
->findOrFail($id);
|
||||||
|
|
||||||
|
$meta = json_decode($appeal->meta);
|
||||||
|
|
||||||
|
if($action == 'dismiss') {
|
||||||
|
$appeal->appeal_handled_at = now();
|
||||||
|
$appeal->save();
|
||||||
|
|
||||||
|
Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $appeal->user->profile_id);
|
||||||
|
Cache::forget('pf:bouncer_v0:recent_by_pid:' . $appeal->user->profile_id);
|
||||||
|
Cache::forget('admin-dash:reports:spam-count');
|
||||||
|
return redirect('/i/admin/reports/autospam');
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = $appeal->status;
|
||||||
|
$status->is_nsfw = $meta->is_nsfw;
|
||||||
|
$status->scope = 'public';
|
||||||
|
$status->visibility = 'public';
|
||||||
|
$status->save();
|
||||||
|
|
||||||
|
$appeal->appeal_handled_at = now();
|
||||||
|
$appeal->save();
|
||||||
|
|
||||||
|
StatusService::del($status->id);
|
||||||
|
|
||||||
|
Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $appeal->user->profile_id);
|
||||||
|
Cache::forget('pf:bouncer_v0:recent_by_pid:' . $appeal->user->profile_id);
|
||||||
|
Cache::forget('admin-dash:reports:spam-count');
|
||||||
|
|
||||||
|
return redirect('/i/admin/reports/autospam');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAppeal(Request $request, $id)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'action' => 'required|in:dismiss,approve'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$action = $request->input('action');
|
||||||
|
$appeal = AccountInterstitial::whereNotNull('appeal_requested_at')
|
||||||
|
->whereNull('appeal_handled_at')
|
||||||
|
->findOrFail($id);
|
||||||
|
|
||||||
|
if($action == 'dismiss') {
|
||||||
|
$appeal->appeal_handled_at = now();
|
||||||
|
$appeal->save();
|
||||||
|
Cache::forget('admin-dash:reports:ai-count');
|
||||||
|
return redirect('/i/admin/reports/appeals');
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($appeal->type) {
|
||||||
|
case 'post.cw':
|
||||||
|
$status = $appeal->status;
|
||||||
|
$status->is_nsfw = false;
|
||||||
|
$status->save();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'post.unlist':
|
||||||
|
$status = $appeal->status;
|
||||||
|
$status->scope = 'public';
|
||||||
|
$status->visibility = 'public';
|
||||||
|
$status->save();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$appeal->appeal_handled_at = now();
|
||||||
|
$appeal->save();
|
||||||
|
StatusService::del($status->id);
|
||||||
|
Cache::forget('admin-dash:reports:ai-count');
|
||||||
|
|
||||||
|
return redirect('/i/admin/reports/appeals');
|
||||||
|
}
|
||||||
|
|
||||||
public function updateReport(Request $request, $id)
|
public function updateReport(Request $request, $id)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
|
|
|
@ -74,178 +74,6 @@ class AdminController extends Controller
|
||||||
return view('admin.statuses.show', compact('status'));
|
return view('admin.statuses.show', compact('status'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reports(Request $request)
|
|
||||||
{
|
|
||||||
$filter = $request->input('filter') == 'closed' ? 'closed' : 'open';
|
|
||||||
$page = $request->input('page') ?? 1;
|
|
||||||
|
|
||||||
$ai = Cache::remember('admin-dash:reports:ai-count', 3600, function() {
|
|
||||||
return AccountInterstitial::whereNotNull('appeal_requested_at')->whereNull('appeal_handled_at')->count();
|
|
||||||
});
|
|
||||||
|
|
||||||
$spam = Cache::remember('admin-dash:reports:spam-count', 3600, function() {
|
|
||||||
return AccountInterstitial::whereType('post.autospam')->whereNull('appeal_handled_at')->count();
|
|
||||||
});
|
|
||||||
|
|
||||||
$mailVerifications = Redis::scard('email:manual');
|
|
||||||
|
|
||||||
if($filter == 'open' && $page == 1) {
|
|
||||||
$reports = Cache::remember('admin-dash:reports:list-cache', 300, function() use($page, $filter) {
|
|
||||||
return Report::whereHas('status')
|
|
||||||
->whereHas('reportedUser')
|
|
||||||
->whereHas('reporter')
|
|
||||||
->orderBy('created_at','desc')
|
|
||||||
->when($filter, function($q, $filter) {
|
|
||||||
return $filter == 'open' ?
|
|
||||||
$q->whereNull('admin_seen') :
|
|
||||||
$q->whereNotNull('admin_seen');
|
|
||||||
})
|
|
||||||
->paginate(6);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$reports = Report::whereHas('status')
|
|
||||||
->whereHas('reportedUser')
|
|
||||||
->whereHas('reporter')
|
|
||||||
->orderBy('created_at','desc')
|
|
||||||
->when($filter, function($q, $filter) {
|
|
||||||
return $filter == 'open' ?
|
|
||||||
$q->whereNull('admin_seen') :
|
|
||||||
$q->whereNotNull('admin_seen');
|
|
||||||
})
|
|
||||||
->paginate(6);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('admin.reports.home', compact('reports', 'ai', 'spam', 'mailVerifications'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function showReport(Request $request, $id)
|
|
||||||
{
|
|
||||||
$report = Report::findOrFail($id);
|
|
||||||
return view('admin.reports.show', compact('report'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function appeals(Request $request)
|
|
||||||
{
|
|
||||||
$appeals = AccountInterstitial::whereNotNull('appeal_requested_at')
|
|
||||||
->whereNull('appeal_handled_at')
|
|
||||||
->latest()
|
|
||||||
->paginate(6);
|
|
||||||
return view('admin.reports.appeals', compact('appeals'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function showAppeal(Request $request, $id)
|
|
||||||
{
|
|
||||||
$appeal = AccountInterstitial::whereNotNull('appeal_requested_at')
|
|
||||||
->whereNull('appeal_handled_at')
|
|
||||||
->findOrFail($id);
|
|
||||||
$meta = json_decode($appeal->meta);
|
|
||||||
return view('admin.reports.show_appeal', compact('appeal', 'meta'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function spam(Request $request)
|
|
||||||
{
|
|
||||||
$appeals = AccountInterstitial::whereType('post.autospam')
|
|
||||||
->whereNull('appeal_handled_at')
|
|
||||||
->latest()
|
|
||||||
->paginate(6);
|
|
||||||
return view('admin.reports.spam', compact('appeals'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function showSpam(Request $request, $id)
|
|
||||||
{
|
|
||||||
$appeal = AccountInterstitial::whereType('post.autospam')
|
|
||||||
->whereNull('appeal_handled_at')
|
|
||||||
->findOrFail($id);
|
|
||||||
$meta = json_decode($appeal->meta);
|
|
||||||
return view('admin.reports.show_spam', compact('appeal', 'meta'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateSpam(Request $request, $id)
|
|
||||||
{
|
|
||||||
$this->validate($request, [
|
|
||||||
'action' => 'required|in:dismiss,approve'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$action = $request->input('action');
|
|
||||||
$appeal = AccountInterstitial::whereType('post.autospam')
|
|
||||||
->whereNull('appeal_handled_at')
|
|
||||||
->findOrFail($id);
|
|
||||||
|
|
||||||
$meta = json_decode($appeal->meta);
|
|
||||||
|
|
||||||
if($action == 'dismiss') {
|
|
||||||
$appeal->appeal_handled_at = now();
|
|
||||||
$appeal->save();
|
|
||||||
|
|
||||||
Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $appeal->user->profile_id);
|
|
||||||
Cache::forget('pf:bouncer_v0:recent_by_pid:' . $appeal->user->profile_id);
|
|
||||||
Cache::forget('admin-dash:reports:spam-count');
|
|
||||||
return redirect('/i/admin/reports/autospam');
|
|
||||||
}
|
|
||||||
|
|
||||||
$status = $appeal->status;
|
|
||||||
$status->is_nsfw = $meta->is_nsfw;
|
|
||||||
$status->scope = 'public';
|
|
||||||
$status->visibility = 'public';
|
|
||||||
$status->save();
|
|
||||||
|
|
||||||
$appeal->appeal_handled_at = now();
|
|
||||||
$appeal->save();
|
|
||||||
|
|
||||||
StatusService::del($status->id);
|
|
||||||
|
|
||||||
Cache::forget('pf:bouncer_v0:exemption_by_pid:' . $appeal->user->profile_id);
|
|
||||||
Cache::forget('pf:bouncer_v0:recent_by_pid:' . $appeal->user->profile_id);
|
|
||||||
Cache::forget('admin-dash:reports:spam-count');
|
|
||||||
|
|
||||||
return redirect('/i/admin/reports/autospam');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateAppeal(Request $request, $id)
|
|
||||||
{
|
|
||||||
$this->validate($request, [
|
|
||||||
'action' => 'required|in:dismiss,approve'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$action = $request->input('action');
|
|
||||||
$appeal = AccountInterstitial::whereNotNull('appeal_requested_at')
|
|
||||||
->whereNull('appeal_handled_at')
|
|
||||||
->findOrFail($id);
|
|
||||||
|
|
||||||
if($action == 'dismiss') {
|
|
||||||
$appeal->appeal_handled_at = now();
|
|
||||||
$appeal->save();
|
|
||||||
Cache::forget('admin-dash:reports:ai-count');
|
|
||||||
return redirect('/i/admin/reports/appeals');
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($appeal->type) {
|
|
||||||
case 'post.cw':
|
|
||||||
$status = $appeal->status;
|
|
||||||
$status->is_nsfw = false;
|
|
||||||
$status->save();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'post.unlist':
|
|
||||||
$status = $appeal->status;
|
|
||||||
$status->scope = 'public';
|
|
||||||
$status->visibility = 'public';
|
|
||||||
$status->save();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
# code...
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$appeal->appeal_handled_at = now();
|
|
||||||
$appeal->save();
|
|
||||||
StatusService::del($status->id);
|
|
||||||
Cache::forget('admin-dash:reports:ai-count');
|
|
||||||
|
|
||||||
return redirect('/i/admin/reports/appeals');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function profiles(Request $request)
|
public function profiles(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
|
|
Loading…
Reference in a new issue