* @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')); } }