Bläddra i källkod

Update AdminController, add appeals support

Daniel Supernault 4 år sedan
förälder
incheckning
c95085ca31
1 ändrade filer med 62 tillägg och 0 borttagningar
  1. 62 0
      app/Http/Controllers/AdminController.php

+ 62 - 0
app/Http/Controllers/AdminController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers;
 
 use App\{
+	AccountInterstitial,
 	Contact,
 	Hashtag,
 	Newsroom,
@@ -85,6 +86,67 @@ class AdminController extends Controller
 		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 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();
+
+			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();
+
+		return redirect('/i/admin/reports/appeals');
+	}
+
 	public function profiles(Request $request)
 	{
 		$this->validate($request, [