mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update AdminReportController
This commit is contained in:
parent
03ad41e2c4
commit
06ebb514d7
1 changed files with 77 additions and 38 deletions
|
@ -3,18 +3,19 @@
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\AccountInterstitial;
|
use App\AccountInterstitial;
|
||||||
use App\Http\Resources\AdminReport;
|
|
||||||
use App\Http\Resources\AdminRemoteReport;
|
use App\Http\Resources\AdminRemoteReport;
|
||||||
|
use App\Http\Resources\AdminReport;
|
||||||
use App\Http\Resources\AdminSpamReport;
|
use App\Http\Resources\AdminSpamReport;
|
||||||
use App\Jobs\DeletePipeline\DeleteAccountPipeline;
|
use App\Jobs\DeletePipeline\DeleteAccountPipeline;
|
||||||
use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline;
|
use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline;
|
||||||
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
||||||
use App\Jobs\StatusPipeline\StatusDelete;
|
use App\Jobs\StatusPipeline\StatusDelete;
|
||||||
use App\Jobs\StoryPipeline\StoryDelete;
|
use App\Jobs\StoryPipeline\StoryDelete;
|
||||||
|
use App\Models\ModeratedProfile;
|
||||||
|
use App\Models\RemoteReport;
|
||||||
use App\Notification;
|
use App\Notification;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
use App\Report;
|
use App\Report;
|
||||||
use App\Models\RemoteReport;
|
|
||||||
use App\Services\AccountService;
|
use App\Services\AccountService;
|
||||||
use App\Services\ModLogService;
|
use App\Services\ModLogService;
|
||||||
use App\Services\NetworkTimelineService;
|
use App\Services\NetworkTimelineService;
|
||||||
|
@ -25,11 +26,11 @@ use App\Status;
|
||||||
use App\Story;
|
use App\Story;
|
||||||
use App\User;
|
use App\User;
|
||||||
use Cache;
|
use Cache;
|
||||||
use Storage;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Illuminate\Support\Facades\Redis;
|
||||||
|
use Storage;
|
||||||
|
|
||||||
trait AdminReportController
|
trait AdminReportController
|
||||||
{
|
{
|
||||||
|
@ -201,10 +202,7 @@ trait AdminReportController
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render() {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,6 +827,16 @@ trait AdminReportController
|
||||||
$profile->cw = true;
|
$profile->cw = true;
|
||||||
$profile->save();
|
$profile->save();
|
||||||
|
|
||||||
|
if ($profile->remote_url) {
|
||||||
|
ModeratedProfile::updateOrCreate([
|
||||||
|
'profile_url' => $profile->remote_url,
|
||||||
|
'profile_id' => $profile->id,
|
||||||
|
], [
|
||||||
|
'is_nsfw' => true,
|
||||||
|
'domain' => $profile->domain,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Status::whereProfileId($profile->id)->cursor() as $status) {
|
foreach (Status::whereProfileId($profile->id)->cursor() as $status) {
|
||||||
$status->is_nsfw = true;
|
$status->is_nsfw = true;
|
||||||
$status->save();
|
$status->save();
|
||||||
|
@ -879,6 +887,16 @@ trait AdminReportController
|
||||||
$profile->unlisted = true;
|
$profile->unlisted = true;
|
||||||
$profile->save();
|
$profile->save();
|
||||||
|
|
||||||
|
if ($profile->remote_url) {
|
||||||
|
ModeratedProfile::updateOrCreate([
|
||||||
|
'profile_url' => $profile->remote_url,
|
||||||
|
'profile_id' => $profile->id,
|
||||||
|
], [
|
||||||
|
'is_unlisted' => true,
|
||||||
|
'domain' => $profile->domain,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Status::whereProfileId($profile->id)->whereScope('public')->cursor() as $status) {
|
foreach (Status::whereProfileId($profile->id)->whereScope('public')->cursor() as $status) {
|
||||||
$status->scope = 'unlisted';
|
$status->scope = 'unlisted';
|
||||||
$status->visibility = 'unlisted';
|
$status->visibility = 'unlisted';
|
||||||
|
@ -929,6 +947,16 @@ trait AdminReportController
|
||||||
$profile->unlisted = true;
|
$profile->unlisted = true;
|
||||||
$profile->save();
|
$profile->save();
|
||||||
|
|
||||||
|
if ($profile->remote_url) {
|
||||||
|
ModeratedProfile::updateOrCreate([
|
||||||
|
'profile_url' => $profile->remote_url,
|
||||||
|
'profile_id' => $profile->id,
|
||||||
|
], [
|
||||||
|
'is_unlisted' => true,
|
||||||
|
'domain' => $profile->domain,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Status::whereProfileId($profile->id)->cursor() as $status) {
|
foreach (Status::whereProfileId($profile->id)->cursor() as $status) {
|
||||||
$status->scope = 'private';
|
$status->scope = 'private';
|
||||||
$status->visibility = 'private';
|
$status->visibility = 'private';
|
||||||
|
@ -982,6 +1010,16 @@ trait AdminReportController
|
||||||
|
|
||||||
$ts = now()->addMonth();
|
$ts = now()->addMonth();
|
||||||
|
|
||||||
|
if ($profile->remote_url) {
|
||||||
|
ModeratedProfile::updateOrCreate([
|
||||||
|
'profile_url' => $profile->remote_url,
|
||||||
|
'profile_id' => $profile->id,
|
||||||
|
], [
|
||||||
|
'is_banned' => true,
|
||||||
|
'domain' => $profile->domain,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($profile->user_id) {
|
if ($profile->user_id) {
|
||||||
$user = $profile->user;
|
$user = $profile->user;
|
||||||
abort_if($user->is_admin, 403, 'You cannot delete admin accounts.');
|
abort_if($user->is_admin, 403, 'You cannot delete admin accounts.');
|
||||||
|
@ -1354,7 +1392,7 @@ trait AdminReportController
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'id' => 'required|exists:remote_reports,id',
|
'id' => 'required|exists:remote_reports,id',
|
||||||
'action' => 'required|in:mark-read,cw-posts,unlist-posts,delete-posts,private-posts,mark-all-read-by-domain,mark-all-read-by-username,cw-all-posts,private-all-posts,unlist-all-posts'
|
'action' => 'required|in:mark-read,cw-posts,unlist-posts,delete-posts,private-posts,mark-all-read-by-domain,mark-all-read-by-username,cw-all-posts,private-all-posts,unlist-all-posts',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$report = RemoteReport::findOrFail($request->input('id'));
|
$report = RemoteReport::findOrFail($request->input('id'));
|
||||||
|
@ -1373,11 +1411,11 @@ trait AdminReportController
|
||||||
break;
|
break;
|
||||||
case 'cw-posts':
|
case 'cw-posts':
|
||||||
$statuses = Status::find($report->status_ids);
|
$statuses = Status::find($report->status_ids);
|
||||||
foreach($statuses as $status) {
|
foreach ($statuses as $status) {
|
||||||
if($report->account_id != $status->profile_id) {
|
if ($report->account_id != $status->profile_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!$status->is_nsfw) {
|
if (! $status->is_nsfw) {
|
||||||
$ogNonCwStatuses[] = $status->id;
|
$ogNonCwStatuses[] = $status->id;
|
||||||
}
|
}
|
||||||
$status->is_nsfw = true;
|
$status->is_nsfw = true;
|
||||||
|
@ -1388,11 +1426,11 @@ trait AdminReportController
|
||||||
$report->save();
|
$report->save();
|
||||||
break;
|
break;
|
||||||
case 'cw-all-posts':
|
case 'cw-all-posts':
|
||||||
foreach(Status::whereProfileId($report->account_id)->lazyById(50, 'id') as $status) {
|
foreach (Status::whereProfileId($report->account_id)->lazyById(50, 'id') as $status) {
|
||||||
if($status->is_nsfw || $status->reblog_of_id) {
|
if ($status->is_nsfw || $status->reblog_of_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!$status->is_nsfw) {
|
if (! $status->is_nsfw) {
|
||||||
$ogNonCwStatuses[] = $status->id;
|
$ogNonCwStatuses[] = $status->id;
|
||||||
}
|
}
|
||||||
$status->is_nsfw = true;
|
$status->is_nsfw = true;
|
||||||
|
@ -1402,11 +1440,11 @@ trait AdminReportController
|
||||||
break;
|
break;
|
||||||
case 'unlist-posts':
|
case 'unlist-posts':
|
||||||
$statuses = Status::find($report->status_ids);
|
$statuses = Status::find($report->status_ids);
|
||||||
foreach($statuses as $status) {
|
foreach ($statuses as $status) {
|
||||||
if($report->account_id != $status->profile_id) {
|
if ($report->account_id != $status->profile_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($status->scope === 'public') {
|
if ($status->scope === 'public') {
|
||||||
$ogPublicStatuses[] = $status->id;
|
$ogPublicStatuses[] = $status->id;
|
||||||
$status->scope = 'unlisted';
|
$status->scope = 'unlisted';
|
||||||
$status->visibility = 'unlisted';
|
$status->visibility = 'unlisted';
|
||||||
|
@ -1418,8 +1456,8 @@ trait AdminReportController
|
||||||
$report->save();
|
$report->save();
|
||||||
break;
|
break;
|
||||||
case 'unlist-all-posts':
|
case 'unlist-all-posts':
|
||||||
foreach(Status::whereProfileId($report->account_id)->lazyById(50, 'id') as $status) {
|
foreach (Status::whereProfileId($report->account_id)->lazyById(50, 'id') as $status) {
|
||||||
if($status->visibility !== 'public' || $status->reblog_of_id) {
|
if ($status->visibility !== 'public' || $status->reblog_of_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$ogPublicStatuses[] = $status->id;
|
$ogPublicStatuses[] = $status->id;
|
||||||
|
@ -1431,12 +1469,12 @@ trait AdminReportController
|
||||||
break;
|
break;
|
||||||
case 'private-posts':
|
case 'private-posts':
|
||||||
$statuses = Status::find($report->status_ids);
|
$statuses = Status::find($report->status_ids);
|
||||||
foreach($statuses as $status) {
|
foreach ($statuses as $status) {
|
||||||
if($report->account_id != $status->profile_id) {
|
if ($report->account_id != $status->profile_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(in_array($status->scope, ['public', 'unlisted', 'private'])) {
|
if (in_array($status->scope, ['public', 'unlisted', 'private'])) {
|
||||||
if($status->scope === 'public') {
|
if ($status->scope === 'public') {
|
||||||
$ogPublicStatuses[] = $status->id;
|
$ogPublicStatuses[] = $status->id;
|
||||||
}
|
}
|
||||||
$status->scope = 'private';
|
$status->scope = 'private';
|
||||||
|
@ -1449,13 +1487,13 @@ trait AdminReportController
|
||||||
$report->save();
|
$report->save();
|
||||||
break;
|
break;
|
||||||
case 'private-all-posts':
|
case 'private-all-posts':
|
||||||
foreach(Status::whereProfileId($report->account_id)->lazyById(50, 'id') as $status) {
|
foreach (Status::whereProfileId($report->account_id)->lazyById(50, 'id') as $status) {
|
||||||
if(!in_array($status->visibility, ['public', 'unlisted']) || $status->reblog_of_id) {
|
if (! in_array($status->visibility, ['public', 'unlisted']) || $status->reblog_of_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($status->visibility === 'public') {
|
if ($status->visibility === 'public') {
|
||||||
$ogPublicStatuses[] = $status->id;
|
$ogPublicStatuses[] = $status->id;
|
||||||
} else if($status->visibility === 'unlisted') {
|
} elseif ($status->visibility === 'unlisted') {
|
||||||
$ogUnlistedStatuses[] = $status->id;
|
$ogUnlistedStatuses[] = $status->id;
|
||||||
}
|
}
|
||||||
$status->visibility = 'private';
|
$status->visibility = 'private';
|
||||||
|
@ -1466,8 +1504,8 @@ trait AdminReportController
|
||||||
break;
|
break;
|
||||||
case 'delete-posts':
|
case 'delete-posts':
|
||||||
$statuses = Status::find($report->status_ids);
|
$statuses = Status::find($report->status_ids);
|
||||||
foreach($statuses as $status) {
|
foreach ($statuses as $status) {
|
||||||
if($report->account_id != $status->profile_id) {
|
if ($report->account_id != $status->profile_id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
StatusDelete::dispatch($status);
|
StatusDelete::dispatch($status);
|
||||||
|
@ -1484,16 +1522,16 @@ trait AdminReportController
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($ogPublicStatuses && count($ogPublicStatuses)) {
|
if ($ogPublicStatuses && count($ogPublicStatuses)) {
|
||||||
Storage::disk('local')->put('mod-log-cache/' . $report->account_id . '/' . now()->format('Y-m-d') . '-og-public-statuses.json', json_encode($ogPublicStatuses, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
|
Storage::disk('local')->put('mod-log-cache/'.$report->account_id.'/'.now()->format('Y-m-d').'-og-public-statuses.json', json_encode($ogPublicStatuses, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($ogNonCwStatuses && count($ogNonCwStatuses)) {
|
if ($ogNonCwStatuses && count($ogNonCwStatuses)) {
|
||||||
Storage::disk('local')->put('mod-log-cache/' . $report->account_id . '/' . now()->format('Y-m-d') . '-og-noncw-statuses.json', json_encode($ogNonCwStatuses, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
|
Storage::disk('local')->put('mod-log-cache/'.$report->account_id.'/'.now()->format('Y-m-d').'-og-noncw-statuses.json', json_encode($ogNonCwStatuses, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($ogUnlistedStatuses && count($ogUnlistedStatuses)) {
|
if ($ogUnlistedStatuses && count($ogUnlistedStatuses)) {
|
||||||
Storage::disk('local')->put('mod-log-cache/' . $report->account_id . '/' . now()->format('Y-m-d') . '-og-unlisted-statuses.json', json_encode($ogUnlistedStatuses, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));
|
Storage::disk('local')->put('mod-log-cache/'.$report->account_id.'/'.now()->format('Y-m-d').'-og-unlisted-statuses.json', json_encode($ogUnlistedStatuses, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||||
}
|
}
|
||||||
|
|
||||||
ModLogService::boot()
|
ModLogService::boot()
|
||||||
|
@ -1504,18 +1542,19 @@ trait AdminReportController
|
||||||
->action('admin.report.moderate')
|
->action('admin.report.moderate')
|
||||||
->metadata([
|
->metadata([
|
||||||
'action' => $request->input('action'),
|
'action' => $request->input('action'),
|
||||||
'duration_active' => now()->parse($report->created_at)->diffForHumans()
|
'duration_active' => now()->parse($report->created_at)->diffForHumans(),
|
||||||
])
|
])
|
||||||
->accessLevel('admin')
|
->accessLevel('admin')
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
if($report->status_ids) {
|
if ($report->status_ids) {
|
||||||
foreach($report->status_ids as $sid) {
|
foreach ($report->status_ids as $sid) {
|
||||||
RemoteReport::whereNull('action_taken_at')
|
RemoteReport::whereNull('action_taken_at')
|
||||||
->whereJsonContains('status_ids', [$sid])
|
->whereJsonContains('status_ids', [$sid])
|
||||||
->update(['action_taken_at' => now()]);
|
->update(['action_taken_at' => now()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [200];
|
return [200];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue