Club System
This commit is contained in:
@@ -4,31 +4,47 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Models\Entry;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EntryController extends Controller
|
||||
{
|
||||
|
||||
private const SECTION_TYPES = [ 'translations', 'romhacks', 'homebrew', 'utilities', 'documents', 'lua-scripts', 'tutorials' ];
|
||||
private const SECTION_TYPES = ['translations', 'romhacks', 'homebrew', 'utilities', 'documents', 'lua-scripts', 'tutorials'];
|
||||
|
||||
public function index(): View
|
||||
{
|
||||
|
||||
return view('entries.index');
|
||||
}
|
||||
|
||||
public function show(string $section, Entry $entry): View
|
||||
{
|
||||
if( ! in_array($section, self::SECTION_TYPES) )
|
||||
if (!in_array($section, self::SECTION_TYPES))
|
||||
abort(404);
|
||||
|
||||
if( $entry->type !== $section )
|
||||
if ($entry->type !== $section)
|
||||
abort(404);
|
||||
|
||||
$comments = EntryHelpers::getLatestComments( $entry );
|
||||
Gate::authorize('viewAny', $entry);
|
||||
|
||||
return view('entries.show', compact('entry', 'section', 'comments' ) );
|
||||
// Permissions.
|
||||
$entryPolicy = match ($entry->state) {
|
||||
'pending' => 'viewPending',
|
||||
'draft' => 'viewDraft',
|
||||
'rejected' => 'viewRejected',
|
||||
'hidden' => 'viewHidden',
|
||||
'locked' => 'viewLocked',
|
||||
'published' => null,
|
||||
'default' => null
|
||||
};
|
||||
|
||||
if ($entryPolicy)
|
||||
Gate::authorize($entryPolicy, $entry);
|
||||
|
||||
$comments = EntryHelpers::getLatestComments($entry);
|
||||
|
||||
return view('entries.show', compact('entry', 'section', 'comments'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,8 @@ class FileServerController extends Controller {
|
||||
'filepath' => $data['file_path'],
|
||||
'filesize' => $data['file']['size'],
|
||||
'favorite_server' => $data['favorite_server'],
|
||||
'favorite_at' => time()
|
||||
'favorite_at' => time(),
|
||||
'state' => 'public'
|
||||
], now()->addHours(2) );
|
||||
|
||||
$data['finished'] = true;
|
||||
|
||||
49
app/Http/Controllers/QueueController.php
Normal file
49
app/Http/Controllers/QueueController.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\XenForoHelpers;
|
||||
use App\Models\Entry;
|
||||
use App\Services\XenforoService;
|
||||
use Illuminate\Http\Request;
|
||||
class QueueController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$entries = Entry::inQueue()
|
||||
->with(['authors', 'game.platform'])
|
||||
->orderByRaw("CASE WHEN state = 'pending' THEN 1 ELSE 0 END")
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
|
||||
return view('queue.index', compact('entries'));
|
||||
}
|
||||
|
||||
public function updateComment(Request $request, Entry $entry)
|
||||
{
|
||||
$request->validate(['comment' => 'nullable|string|max:2000']);
|
||||
|
||||
$entry->update(['staff_comment' => $request->input('comment')]);
|
||||
|
||||
return back()->with('success', 'Comment updated');
|
||||
}
|
||||
|
||||
public function approve(Request $request, Entry $entry)
|
||||
{
|
||||
// $entry->update(['state' => 'published']);
|
||||
|
||||
XenForoHelpers::entryApproved($entry);
|
||||
|
||||
return back()->with('success', 'Entry approved');
|
||||
}
|
||||
|
||||
public function reject(Request $request, Entry $entry)
|
||||
{
|
||||
$request->validate(['reason' => 'nullable|string|max:2000']);
|
||||
|
||||
$entry->update(['state' => 'rejected', 'staff_comment' => $request->input('reason'), 'rejected_at' => now() ]);
|
||||
|
||||
return back()->with('success', 'Entry rejected');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Rules\PublicFileExists;
|
||||
use App\Rules\XfUserExists;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -49,12 +50,20 @@ class StoreEntryRequest extends FormRequest
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
$isEdit = (bool) $this->route('entry');
|
||||
|
||||
$rules = [];
|
||||
$section = $this->route('section');
|
||||
|
||||
$rules['files_uuid'] = 'array|required|min:1';
|
||||
$rules['files_uuid.*'] = 'string';
|
||||
|
||||
if( $isEdit ){
|
||||
$rules['files_state'] = 'array|required|min:1';
|
||||
$rules['files_state.*'] = 'string|in:public,private,archived';
|
||||
}
|
||||
|
||||
if( section_must_not_be( 'translations', $section ) ){
|
||||
$rules['entry_title'] = "required|string|max:255";
|
||||
} else {
|
||||
@@ -78,7 +87,6 @@ class StoreEntryRequest extends FormRequest
|
||||
$rules['new-game-genre'] = 'required_with:new-game-title|integer|nullable|exists:genres,id';
|
||||
}
|
||||
|
||||
|
||||
$rules['hashes'] = 'array|required|min:1';
|
||||
$rules['hashes.*.filename'] = 'required|string|max:512';
|
||||
$rules['hashes.*.hash_crc32'] = 'required|string|max:512';
|
||||
@@ -101,7 +109,25 @@ class StoreEntryRequest extends FormRequest
|
||||
$rules['release_site'] = 'nullable|url|max:500';
|
||||
$rules['youtube_video'] = 'nullable|url|max:500';
|
||||
|
||||
$rules['submit-state'] = 'required|string|in:draft,pending,published';
|
||||
if( $isEdit ){
|
||||
$ss = 'draft,pending,published';
|
||||
if( \Auth::user()->can('moderate', $this->route('entry')) && \Auth::user()->can('view-hidden', $this->route('entry')) )
|
||||
$ss .= ',hidden';
|
||||
if(\Auth::user()->can('moderate', $this->route('entry')) && \Auth::user()->can('view-locked', $this->route('entry')) )
|
||||
$ss .= ',locked';
|
||||
$rules['submit-state'] = 'required|in:' . $ss;
|
||||
} else {
|
||||
if( $this->user()->can('skip-queue', '\App\Models\Entry') ){
|
||||
$rules['submit-state'] = 'required|string|in:draft,pending,published';
|
||||
} else {
|
||||
$rules['submit-state'] = 'required|string|in:draft,pending';
|
||||
}
|
||||
}
|
||||
|
||||
if( $isEdit && $this->user()->can('moderate', $this->route('entry') ) ){
|
||||
$rules['staff_comment'] = 'nullable|string';
|
||||
$rules['owner_user_id'] = [ 'required', 'integer', new XfUserExists ];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user