mirror of
https://github.com/BillyOutlast/UNIT3D.git
synced 2026-02-08 21:21:18 +01:00
Separate requests into cruddy routes. Use route model binding. Allow forfeit of award if request approval is revoked. Use form requests.
85 lines
2.8 KiB
PHP
85 lines
2.8 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\Http\Requests\StoreRequestFillRequest;
|
|
use App\Models\Torrent;
|
|
use App\Models\TorrentRequest;
|
|
use App\Notifications\NewRequestFill;
|
|
use App\Notifications\NewRequestFillReject;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* @see \Tests\Todo\Feature\Http\Controllers\RequestControllerTest
|
|
*/
|
|
class RequestFillController extends Controller
|
|
{
|
|
/**
|
|
* Fill A Torrent Request.
|
|
*/
|
|
public function store(StoreRequestFillRequest $request, TorrentRequest $torrentRequest): \Illuminate\Http\RedirectResponse
|
|
{
|
|
$torrent = Torrent::find(basename($request->torrent_id));
|
|
|
|
if ($torrent === null) {
|
|
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
|
|
->withErrors("Submitted torrent link not found or not yet approved.");
|
|
}
|
|
|
|
$torrentRequest->update([
|
|
'filled_by' => $request->user()->id,
|
|
'torrent_id' => $torrent->id,
|
|
'filled_when' => Carbon::now(),
|
|
'filled_anon' => $request->filled_anon,
|
|
]);
|
|
|
|
// Send Private Message
|
|
$sender = $request->boolean('filled_anon') ? 'Anonymous' : $request->user()->username;
|
|
$requester = $torrentRequest->user;
|
|
|
|
if ($requester->acceptsNotification($request->user(), $requester, 'request', 'show_request_fill')) {
|
|
$requester->notify(new NewRequestFill('torrent', $sender, $torrentRequest));
|
|
}
|
|
|
|
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
|
|
->withSuccess(trans('request.pending-approval'));
|
|
}
|
|
|
|
/**
|
|
* Reject A Torrent Request Fill.
|
|
*/
|
|
public function destroy(Request $request, TorrentRequest $torrentRequest): \Illuminate\Http\RedirectResponse
|
|
{
|
|
$user = $request->user();
|
|
|
|
abort_unless($request->user()->group->is_modo, 403);
|
|
|
|
$torrentRequest->update([
|
|
'filled_by' => null,
|
|
'filled_when' => null,
|
|
'torrent_id' => null,
|
|
]);
|
|
|
|
$filler = $torrentRequest->user;
|
|
|
|
if ($filler->acceptsNotification($request->user(), $filler, 'request', 'show_request_fill_reject')) {
|
|
$filler->notify(new NewRequestFillReject('torrent', $user->username, $torrentRequest));
|
|
}
|
|
|
|
return to_route('requests.show', ['torrentRequest' => $torrentRequest])
|
|
->withSuccess(trans('request.request-reset'));
|
|
}
|
|
}
|