mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-01-21 11:30:46 -06:00
Separate torrents into cruddy route names. Route model binding isn't possible due to the global scope on unapproved torrents. Use form requests. Simplify the controller flow where possible.
117 lines
3.4 KiB
PHP
117 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* NOTICE OF LICENSE.
|
|
*
|
|
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
|
* The details is bundled with this project in the file LICENSE.txt.
|
|
*
|
|
* @project UNIT3D Community Edition
|
|
*
|
|
* @author HDVinnie <hdinnovations@protonmail.com>
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
|
*/
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Report;
|
|
use App\Models\Torrent;
|
|
use App\Models\TorrentRequest;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* @see \Tests\Todo\Feature\Http\Controllers\ReportControllerTest
|
|
*/
|
|
class ReportController extends Controller
|
|
{
|
|
/**
|
|
* ReportController Constructor.
|
|
*/
|
|
public function __construct(private readonly Report $report)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Create A Request Report.
|
|
*/
|
|
public function request(Request $request, int $id): \Illuminate\Http\RedirectResponse
|
|
{
|
|
$torrentRequest = TorrentRequest::findOrFail($id);
|
|
$reportedBy = $request->user();
|
|
$reportedUser = $torrentRequest->user;
|
|
|
|
$request->validate([
|
|
'message' => 'required',
|
|
]);
|
|
|
|
$this->report->create([
|
|
'type' => 'Request',
|
|
'request_id' => $torrentRequest->id,
|
|
'torrent_id' => 0,
|
|
'reporter_id' => $reportedBy->id,
|
|
'reported_user' => $reportedUser->id,
|
|
'title' => $torrentRequest->name,
|
|
'message' => $request->get('message'),
|
|
'solved' => 0,
|
|
]);
|
|
|
|
return to_route('requests.show', ['id' => $id])
|
|
->withSuccess(trans('user.report-sent'));
|
|
}
|
|
|
|
/**
|
|
* Create A Torrent Report.
|
|
*/
|
|
public function torrent(Request $request, int $id): \Illuminate\Http\RedirectResponse
|
|
{
|
|
$torrent = Torrent::findOrFail($id);
|
|
$reportedBy = $request->user();
|
|
$reportedUser = $torrent->user;
|
|
|
|
$request->validate([
|
|
'message' => 'required',
|
|
]);
|
|
|
|
$this->report->create([
|
|
'type' => 'Torrent',
|
|
'torrent_id' => $torrent->id,
|
|
'request_id' => 0,
|
|
'reporter_id' => $reportedBy->id,
|
|
'reported_user' => $reportedUser->id,
|
|
'title' => $torrent->name,
|
|
'message' => $request->get('message'),
|
|
'solved' => 0,
|
|
]);
|
|
|
|
return to_route('torrents.show', ['id' => $id])
|
|
->withSuccess(trans('user.report-sent'));
|
|
}
|
|
|
|
/**
|
|
* Create A User Report.
|
|
*/
|
|
public function user(Request $request, string $username): \Illuminate\Http\RedirectResponse
|
|
{
|
|
$reportedUser = User::where('username', '=', $username)->sole();
|
|
$reportedBy = $request->user();
|
|
|
|
$request->validate([
|
|
'message' => 'required',
|
|
]);
|
|
|
|
$this->report->create([
|
|
'type' => 'User',
|
|
'torrent_id' => 0,
|
|
'request_id' => 0,
|
|
'reporter_id' => $reportedBy->id,
|
|
'reported_user' => $reportedUser->id,
|
|
'title' => $reportedUser->username,
|
|
'message' => $request->get('message'),
|
|
'solved' => 0,
|
|
]);
|
|
|
|
return to_route('users.show', ['user' => $reportedBy])
|
|
->withSuccess(trans('user.report-sent'));
|
|
}
|
|
}
|