Skip to content

Commit

Permalink
Update AdminReportController, add account delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Apr 18, 2022
1 parent 4671836 commit 563817a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
39 changes: 38 additions & 1 deletion app/Http/Controllers/Admin/AdminReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
};
use Illuminate\Validation\Rule;
use App\Services\StoryService;
use App\Services\ModLogService;
use App\Jobs\DeletePipeline\DeleteAccountPipeline;

trait AdminReportController
{
Expand Down Expand Up @@ -243,7 +245,7 @@ public function fixUncategorizedSpam(Request $request)
public function updateSpam(Request $request, $id)
{
$this->validate($request, [
'action' => 'required|in:dismiss,approve,dismiss-all,approve-all'
'action' => 'required|in:dismiss,approve,dismiss-all,approve-all,delete-account'
]);

$action = $request->input('action');
Expand All @@ -257,6 +259,41 @@ public function updateSpam(Request $request, $id)
Cache::forget('admin-dash:reports:spam-count:total');
Cache::forget('admin-dash:reports:spam-count:30d');

if($action == 'delete-account') {
if(config('pixelfed.account_deletion') == false) {
abort(404);
}

$user = User::findOrFail($appeal->user_id);
$profile = $user->profile;

if($user->is_admin == true) {
$mid = $request->user()->id;
abort_if($user->id < $mid, 403);
}

$ts = now()->addMonth();
$user->status = 'delete';
$profile->status = 'delete';
$user->delete_after = $ts;
$profile->delete_after = $ts;
$user->save();
$profile->save();

ModLogService::boot()
->objectUid($user->id)
->objectId($user->id)
->objectType('App\User::class')
->user($request->user())
->action('admin.user.delete')
->accessLevel('admin')
->save();

Cache::forget('profiles:private');
DeleteAccountPipeline::dispatch($user)->onQueue('high');
return;
}

if($action == 'dismiss') {
$appeal->is_spam = true;
$appeal->appeal_handled_at = $now;
Expand Down
9 changes: 8 additions & 1 deletion resources/views/admin/reports/show_spam.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
<button type="button" class="btn btn-light border btn-block font-weight-bold mb-3 action-btn" data-action="approve">Mark as not spam</button>
<hr>
<button type="button" class="btn btn-default border btn-block font-weight-bold mb-3 action-btn" data-action="dismiss-all">Mark all as read</button>
<button type="button" class="btn btn-light border btn-block font-weight-bold mb-3 action-btn mb-5" data-action="approve-all">Mark all as not spam</button>
<button type="button" class="btn btn-light border btn-block font-weight-bold mb-3 action-btn" data-action="approve-all">Mark all as not spam</button>
<button type="button" class="btn btn-danger border btn-block font-weight-bold mb-3 action-btn mb-5" data-action="delete-account">Delete Account</button>
@endif
<div class="card shadow-none border">
<div class="card-header text-center font-weight-bold bg-light">
Expand Down Expand Up @@ -105,6 +106,12 @@
return;
}
break;
case 'delete-account':
if(!window.confirm('Are you sure you want to delete this account?')) {
return;
}
break;
}
axios.post(window.location.href, {
Expand Down

0 comments on commit 563817a

Please sign in to comment.