the browser-facing portion of osu!
at master 1.5 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Http\Controllers; 7 8use App\Exceptions\ValidationException; 9use App\Libraries\MorphMap; 10use App\Models\Traits\ReportableInterface; 11 12class ReportsController extends Controller 13{ 14 public function __construct() 15 { 16 parent::__construct(); 17 18 $this->middleware('auth'); 19 } 20 21 public function store() 22 { 23 $params = get_params(request()->all(), null, [ 24 'comments', 25 'reason', 26 'reportable_id:int', 27 'reportable_type', 28 ], ['null_missing' => true]); 29 30 $class = MorphMap::getClass($params['reportable_type']); 31 if ($class === null) { 32 abort(404); 33 } 34 35 $classInstance = new $class(); 36 if (!($classInstance instanceof ReportableInterface)) { 37 abort(404); 38 } 39 40 $reportable = $class::findOrFail($params['reportable_id']); 41 priv_check('UserReport', $reportable)->ensureCan(); 42 43 try { 44 $reportable->reportBy(auth()->user(), [ 45 'comments' => trim($params['comments']), 46 'reason' => $params['reason'], 47 ]); 48 } catch (ValidationException $e) { 49 return error_popup($e->getMessage()); 50 } 51 52 return response(null, 204); 53 } 54}