27
27
use App \Services \ModLogService ;
28
28
use App \Services \SnowflakeService ;
29
29
use App \Services \StatusService ;
30
+ use App \Services \PublicTimelineService ;
30
31
use App \Services \NetworkTimelineService ;
31
32
use App \Services \NotificationService ;
32
33
use App \Http \Resources \AdminInstance ;
33
34
use App \Http \Resources \AdminUser ;
35
+ use App \Jobs \DeletePipeline \DeleteAccountPipeline ;
36
+ use App \Jobs \DeletePipeline \DeleteRemoteProfilePipeline ;
37
+ use App \Jobs \DeletePipeline \DeleteRemoteStatusPipeline ;
34
38
35
39
class AdminApiController extends Controller
36
40
{
@@ -95,7 +99,7 @@ public function autospamHandle(Request $request)
95
99
abort_unless ($ request ->user ()->is_admin == 1 , 404 );
96
100
97
101
$ this ->validate ($ request , [
98
- 'action ' => 'required|in:dismiss,approve,dismiss-all,approve-all ' ,
102
+ 'action ' => 'required|in:dismiss,approve,dismiss-all,approve-all,delete-post,delete-account ' ,
99
103
'id ' => 'required '
100
104
]);
101
105
@@ -107,14 +111,53 @@ public function autospamHandle(Request $request)
107
111
$ now = now ();
108
112
$ res = ['status ' => 'success ' ];
109
113
$ meta = json_decode ($ appeal ->meta );
114
+ $ user = $ appeal ->user ;
115
+ $ profile = $ user ->profile ;
110
116
111
117
if ($ action == 'dismiss ' ) {
112
118
$ appeal ->is_spam = true ;
113
119
$ appeal ->appeal_handled_at = $ now ;
114
120
$ appeal ->save ();
115
121
116
- Cache::forget ('pf:bouncer_v0:exemption_by_pid: ' . $ appeal ->user ->profile_id );
117
- Cache::forget ('pf:bouncer_v0:recent_by_pid: ' . $ appeal ->user ->profile_id );
122
+ Cache::forget ('pf:bouncer_v0:exemption_by_pid: ' . $ profile ->id );
123
+ Cache::forget ('pf:bouncer_v0:recent_by_pid: ' . $ profile ->id );
124
+ Cache::forget ('admin-dash:reports:spam-count ' );
125
+ return $ res ;
126
+ }
127
+
128
+ if ($ action == 'delete-post ' ) {
129
+ $ appeal ->appeal_handled_at = now ();
130
+ $ appeal ->is_spam = true ;
131
+ $ appeal ->save ();
132
+ ModLogService::boot ()
133
+ ->objectUid ($ profile ->id )
134
+ ->objectId ($ appeal ->status ->id )
135
+ ->objectType ('App\Status::class ' )
136
+ ->user ($ request ->user ())
137
+ ->action ('admin.status.delete ' )
138
+ ->accessLevel ('admin ' )
139
+ ->save ();
140
+ PublicTimelineService::deleteByProfileId ($ profile ->id );
141
+ StatusDelete::dispatch ($ appeal ->status )->onQueue ('high ' );
142
+ Cache::forget ('admin-dash:reports:spam-count ' );
143
+ return $ res ;
144
+ }
145
+
146
+ if ($ action == 'delete-account ' ) {
147
+ abort_if ($ user ->is_admin , 400 , 'Cannot delete an admin account. ' );
148
+ $ appeal ->appeal_handled_at = now ();
149
+ $ appeal ->is_spam = true ;
150
+ $ appeal ->save ();
151
+ ModLogService::boot ()
152
+ ->objectUid ($ profile ->id )
153
+ ->objectId ($ profile ->id )
154
+ ->objectType ('App\User::class ' )
155
+ ->user ($ request ->user ())
156
+ ->action ('admin.user.delete ' )
157
+ ->accessLevel ('admin ' )
158
+ ->save ();
159
+ PublicTimelineService::deleteByProfileId ($ profile ->id );
160
+ DeleteAccountPipeline::dispatch ($ appeal ->user )->onQueue ('high ' );
118
161
Cache::forget ('admin-dash:reports:spam-count ' );
119
162
return $ res ;
120
163
}
@@ -459,7 +502,7 @@ public function userAdminAction(Request $request)
459
502
460
503
$ this ->validate ($ request , [
461
504
'id ' => 'required ' ,
462
- 'action ' => 'required|in:unlisted,cw,no_autolink,refresh_stats,verify_email ' ,
505
+ 'action ' => 'required|in:unlisted,cw,no_autolink,refresh_stats,verify_email,delete ' ,
463
506
'value ' => 'sometimes '
464
507
]);
465
508
@@ -470,7 +513,59 @@ public function userAdminAction(Request $request)
470
513
471
514
abort_if ($ user ->is_admin == true && $ action !== 'refresh_stats ' , 400 , 'Cannot moderate admin accounts ' );
472
515
473
- if ($ action === 'refresh_stats ' ) {
516
+ if ($ action === 'delete ' ) {
517
+ if (config ('pixelfed.account_deletion ' ) == false ) {
518
+ abort (404 );
519
+ }
520
+
521
+ abort_if ($ user ->is_admin , 400 , 'Cannot delete an admin account. ' );
522
+
523
+ $ ts = now ()->addMonth ();
524
+
525
+ $ user ->status = 'delete ' ;
526
+ $ user ->delete_after = $ ts ;
527
+ $ user ->save ();
528
+
529
+ $ profile ->status = 'delete ' ;
530
+ $ profile ->delete_after = $ ts ;
531
+ $ profile ->save ();
532
+
533
+ ModLogService::boot ()
534
+ ->objectUid ($ profile ->id )
535
+ ->objectId ($ profile ->id )
536
+ ->objectType ('App\Profile::class ' )
537
+ ->user ($ request ->user ())
538
+ ->action ('admin.user.delete ' )
539
+ ->accessLevel ('admin ' )
540
+ ->save ();
541
+
542
+ PublicTimelineService::deleteByProfileId ($ profile ->id );
543
+ NetworkTimelineService::deleteByProfileId ($ profile ->id );
544
+
545
+ if ($ profile ->user_id ) {
546
+ DB ::table ('oauth_access_tokens ' )->whereUserId ($ user ->id )->delete ();
547
+ DB ::table ('oauth_auth_codes ' )->whereUserId ($ user ->id )->delete ();
548
+ $ user ->email = $ user ->id ;
549
+ $ user ->password = '' ;
550
+ $ user ->status = 'delete ' ;
551
+ $ user ->save ();
552
+ $ profile ->status = 'delete ' ;
553
+ $ profile ->delete_after = now ()->addMonth ();
554
+ $ profile ->save ();
555
+ AccountService::del ($ profile ->id );
556
+ DeleteAccountPipeline::dispatch ($ user )->onQueue ('high ' );
557
+ } else {
558
+ $ profile ->status = 'delete ' ;
559
+ $ profile ->delete_after = now ()->addMonth ();
560
+ $ profile ->save ();
561
+ AccountService::del ($ profile ->id );
562
+ DeleteRemoteProfilePipeline::dispatch ($ profile )->onQueue ('high ' );
563
+ }
564
+ return [
565
+ 'status ' => 200 ,
566
+ 'msg ' => 'deleted ' ,
567
+ ];
568
+ } else if ($ action === 'refresh_stats ' ) {
474
569
$ profile ->following_count = DB ::table ('followers ' )->whereProfileId ($ user ->profile_id )->count ();
475
570
$ profile ->followers_count = DB ::table ('followers ' )->whereFollowingId ($ user ->profile_id )->count ();
476
571
$ statusCount = Status::whereProfileId ($ user ->profile_id )
@@ -496,6 +591,51 @@ public function userAdminAction(Request $request)
496
591
])
497
592
->accessLevel ('admin ' )
498
593
->save ();
594
+ } else if ($ action === 'unlisted ' ) {
595
+ ModLogService::boot ()
596
+ ->objectUid ($ profile ->id )
597
+ ->objectId ($ profile ->id )
598
+ ->objectType ('App\Profile::class ' )
599
+ ->user ($ request ->user ())
600
+ ->action ('admin.user.moderate ' )
601
+ ->metadata ([
602
+ 'action ' => $ action ,
603
+ 'message ' => 'Success! '
604
+ ])
605
+ ->accessLevel ('admin ' )
606
+ ->save ();
607
+ $ profile ->unlisted = !$ profile ->unlisted ;
608
+ $ profile ->save ();
609
+ } else if ($ action === 'cw ' ) {
610
+ ModLogService::boot ()
611
+ ->objectUid ($ profile ->id )
612
+ ->objectId ($ profile ->id )
613
+ ->objectType ('App\Profile::class ' )
614
+ ->user ($ request ->user ())
615
+ ->action ('admin.user.moderate ' )
616
+ ->metadata ([
617
+ 'action ' => $ action ,
618
+ 'message ' => 'Success! '
619
+ ])
620
+ ->accessLevel ('admin ' )
621
+ ->save ();
622
+ $ profile ->cw = !$ profile ->cw ;
623
+ $ profile ->save ();
624
+ } else if ($ action === 'no_autolink ' ) {
625
+ ModLogService::boot ()
626
+ ->objectUid ($ profile ->id )
627
+ ->objectId ($ profile ->id )
628
+ ->objectType ('App\Profile::class ' )
629
+ ->user ($ request ->user ())
630
+ ->action ('admin.user.moderate ' )
631
+ ->metadata ([
632
+ 'action ' => $ action ,
633
+ 'message ' => 'Success! '
634
+ ])
635
+ ->accessLevel ('admin ' )
636
+ ->save ();
637
+ $ profile ->no_autolink = !$ profile ->no_autolink ;
638
+ $ profile ->save ();
499
639
} else {
500
640
$ profile ->{$ action } = filter_var ($ request ->input ('value ' ), FILTER_VALIDATE_BOOLEAN );
501
641
$ profile ->save ();
0 commit comments