Skip to content

Commit

Permalink
Merge pull request corowne#822 from SpeedyD/fix/hidden-traits-unrelea…
Browse files Browse the repository at this point in the history
…sed-items

Fix/hidden traits and unreleased items visible for staff
  • Loading branch information
itinerare authored Feb 6, 2024
2 parents 4293207 + addfac2 commit 5d7ce3d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
19 changes: 14 additions & 5 deletions app/Http/Controllers/WorldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function getFeatureCategories(Request $request) {
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getFeatures(Request $request) {
$query = Feature::visible()->with('category')->with('rarity')->with('species');
$query = Feature::visible(Auth::check() ? Auth::user() : null)->with('category')->with('rarity')->with('species');
$data = $request->only(['rarity_id', 'feature_category_id', 'species_id', 'subtype_id', 'name', 'sort']);
if (isset($data['rarity_id']) && $data['rarity_id'] != 'none') {
$query->where('rarity_id', $data['rarity_id']);
Expand Down Expand Up @@ -240,7 +240,7 @@ public function getSpeciesFeatures($id) {

$features = count($categories) ?
$species->features()
->visible()
->visible(Auth::check() ? Auth::user() : null)
->orderByRaw('FIELD(feature_category_id,'.implode(',', $categories->pluck('id')->toArray()).')')
->orderByRaw('FIELD(rarity_id,'.implode(',', $rarities->pluck('id')->toArray()).')')
->orderBy('has_image', 'DESC')
Expand All @@ -255,7 +255,7 @@ public function getSpeciesFeatures($id) {
})
->groupBy(['feature_category_id', 'id']) :
$species->features()
->visible()
->visible(Auth::check() ? Auth::user() : null)
->orderByRaw('FIELD(rarity_id,'.implode(',', $rarities->pluck('id')->toArray()).')')
->orderBy('has_image', 'DESC')
->orderBy('name')
Expand Down Expand Up @@ -306,7 +306,11 @@ public function getSpeciesFeatureDetail($speciesId, $id) {
* @return \Illuminate\Contracts\Support\Renderable
*/
public function getItems(Request $request) {
$query = Item::with('category')->released();
$query = Item::with('category');

if (!Auth::check() || !Auth::user()->isStaff) {
$query->released();
}

$categoryVisibleCheck = ItemCategory::visible(Auth::check() ? Auth::user() : null)->pluck('id', 'name')->toArray();
// query where category is visible, or, no category and released
Expand Down Expand Up @@ -367,7 +371,12 @@ public function getItems(Request $request) {
*/
public function getItem($id) {
$categories = ItemCategory::orderBy('sort', 'DESC')->get();
$item = Item::where('id', $id)->released()->first();

if (!Auth::check() || !Auth::user()->isStaff) {
$item = Item::where('id', $id)->released()->first();
} else {
$item = Item::where('id', $id)->first();
}
if (!$item) {
abort(404);
}
Expand Down
3 changes: 3 additions & 0 deletions resources/views/world/_feature_entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<div class="{{ $feature->has_image ? 'col-md-9' : 'col-12' }}">
<x-admin-edit title="Trait" :object="$feature" />
<h3>
@if (!$feature->is_visible)
<i class="fas fa-eye-slash mr-1"></i>
@endif
{!! $feature->displayName !!}
<a href="{{ $feature->searchUrl }}" class="world-entry-search text-muted">
<i class="fas fa-search"></i>
Expand Down
3 changes: 3 additions & 0 deletions resources/views/world/_item_entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<div class="{{ $imageUrl ? 'col-md-9' : 'col-12' }}">
<x-admin-edit title="Item" :object="$item" />
<h3>
@if (!$item->is_released)
<i class="fas fa-eye-slash mr-1"></i>
@endif
{!! $name !!}
@if (isset($idUrl) && $idUrl)
<a href="{{ $idUrl }}" class="world-entry-search text-muted">
Expand Down
7 changes: 6 additions & 1 deletion resources/views/world/item_page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
<div class="col-md-3 world-entry-image"><a href="{{ $imageUrl }}" data-lightbox="entry" data-title="{{ $name }}"><img src="{{ $imageUrl }}" class="world-entry-image" alt="{{ $name }}" /></a></div>
@endif
<div class="{{ $imageUrl ? 'col-md-9' : 'col-12' }}">
<h1>{!! $name !!}</h1>
<h1>
@if (!$item->is_released)
<i class="fas fa-eye-slash mr-1"></i>
@endif
{!! $name !!}
</h1>
<div class="row">
@if (isset($item->category) && $item->category)
<div class="col-md">
Expand Down
3 changes: 3 additions & 0 deletions resources/views/world/species_features.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
</a>
@endif
<p>
@if (!$feature->first()->is_visible)
<i class="fas fa-eye-slash mr-1"></i>
@endif
{!! $feature->first()->displayName !!}
@if ($feature->first()->subtype)
<br />({!! $feature->first()->subtype->displayName !!} Subtype)
Expand Down

0 comments on commit 5d7ce3d

Please sign in to comment.