Added NSFW compatibility
This commit is contained in:
@@ -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 {
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
29
app/Models/Scopes/NsfwScope.php
Normal file
29
app/Models/Scopes/NsfwScope.php
Normal 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 );
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user