dev #12

Merged
RHPZAdmin merged 3 commits from dev into master 2026-06-27 17:02:40 +00:00
8 changed files with 74 additions and 3 deletions
Showing only changes of commit 76a1e62129 - Show all commits

View File

@@ -60,6 +60,7 @@ use Illuminate\Contracts\Auth\Authenticatable;
* Custom properties.
*
* @property-read int $rhpz_entry_count
* @property-read int $nsfw_content
*/
class XenForoUser extends XenForoData implements Authenticatable, Authorizable, FilamentUser, HasName {

View File

@@ -138,6 +138,7 @@ class StoreEntryRequest extends FormRequest
$ss .= ',locked';
$rules['submit-state'] = 'required|in:' . $ss;
} else {
$rules['nsfw-entry'] = 'nullable|boolean';
if( $this->user()->can('skip-queue', '\App\Models\Entry') ){
$rules['submit-state'] = 'required|string|in:draft,pending,published';
} else {
@@ -160,6 +161,7 @@ class StoreEntryRequest extends FormRequest
$rules['comments_thread_id'] = 'nullable|integer';
$rules['featured'] = 'nullable|boolean';
$rules['refresh_created_at'] = 'nullable|boolean';
$rules['nsfw-entry'] = 'nullable|boolean';
}
return $rules;

View File

@@ -3,6 +3,7 @@
namespace App\Models;
use App\Helpers\EntryHelpers;
use App\Models\Scopes\NsfwScope;
use App\Traits\HasGallery;
use App\Traits\HasXenforoUserId;
use Illuminate\Database\Eloquent\Model;
@@ -137,7 +138,8 @@ class Entry extends Model
'staff_comment',
'rejected_at',
'level_id',
'created_at'
'created_at',
'nsfw'
];
/**
@@ -151,11 +153,15 @@ class Entry extends Model
];
protected static function booted(): void {
static::addGlobalScope(new NsfwScope);
static::saving( function( $entry ) {
if( $entry->isDirty('version') ) {
$entry->created_at = now();
}
});
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Models\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
class NsfwScope implements Scope
{
private function canNsfw(): bool
{
if( \Auth::guest() )
return false;
$user = \Auth::user();
return $user->nsfw_content === 1;
}
/**
* Apply the scope to a given Eloquent query builder.
*/
public function apply(Builder $builder, Model $model): void
{
if( !$this->canNsfw() )
$builder->where('nsfw', false );
}
}

View File

@@ -174,7 +174,8 @@ class SubmissionsService {
'youtube_link' => $this->request->input('youtube_video'),
'user_id' => $user_id,
'complete_title' => $completeTitle,
'level_id' => $this->request->input('level')
'level_id' => $this->request->input('level'),
'nsfw' => $this->request->input('nsfw-entry') ?? false,
];
$entry = Entry::create( $fields );
@@ -608,6 +609,7 @@ class SubmissionsService {
$refresh_created_at = $this->request->input('refresh_created_at') ?? false;
if( $refresh_created_at )
$fields['created_at'] = now();
$fields['nsfw'] = $this->request->input('nsfw-entry') ?? false;
}
$this->entry->update( $fields );

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('entries', function (Blueprint $table) {
$table->boolean('nsfw')->default(false);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('entries', function (Blueprint $table) {
$table->dropColumn('nsfw');
});
}
};

View File

@@ -26,7 +26,7 @@
</div>
@endif
<div>
@if( section_must_be( [ 'romhacks', 'homebrew' ], $section ) && !$isEdit )
@if( section_must_be( [ 'romhacks', 'homebrew' ], $section ) && !$isEdit && $VISITOR->nsfw_content === 1 )
<label class="nsfw-label"><input id="nsfw-checkbox" type="checkbox" name="nsfw-entry" x-model="nsfw" style="transform: scale(1.5)"> NSFW</label>
@endif
</div>

View File

@@ -231,6 +231,9 @@
<div class="form-type-of-checkboxes form-group level" id="entry-metadata">
<label><input class="form-checkbox" type="checkbox" name="featured" value="1" {{ old('featured', $entry->featured ) ? 'checked' : '' }}>Featured entry</label>
<label><input class="form-checkbox" type="checkbox" name="refresh_created_at" value="1">Refresh created at</label>
@if( section_must_be(['romhacks', 'homebrew'], $section ) )
<label><input class="form-checkbox" type="checkbox" name="nsfw-entry" value="1" {{ old('nsfw-entry', $entry->nsfw ) ? 'checked' : '' }}>NSFW</label>
@endif
</div>
</div>
@endcan