From c8ea9502751816d23d5a8971492a61b6b2fed52a Mon Sep 17 00:00:00 2001 From: moif Date: Tue, 6 Feb 2024 19:04:29 -0500 Subject: [PATCH] Bug(Visual Trait Index): Hidden Traits were still showing when they shouldn't --- app/Models/Feature/Feature.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/Models/Feature/Feature.php b/app/Models/Feature/Feature.php index 712ee96059..cdf9f9b1fb 100644 --- a/app/Models/Feature/Feature.php +++ b/app/Models/Feature/Feature.php @@ -191,8 +191,8 @@ public function scopeSortOldest($query) { * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeVisible($query, $withHidden = 0) { - if ($withHidden) { + public function scopeVisible($query, $user = null) { + if ($user && $user->hasPower('edit_data')) { return $query; } @@ -297,14 +297,15 @@ public function getAdminPowerAttribute() { **********************************************************************************************/ public static function getDropdownItems($withHidden = 0) { + $visibleOnly = 1; + if ($withHidden) { + $visibleOnly = 0; + } + if (config('lorekeeper.extensions.organised_traits_dropdown')) { - $visibleOnly = 1; - if ($withHidden) { - $visibleOnly = 0; - } $sorted_feature_categories = collect(FeatureCategory::all()->where('is_visible', '>=', $visibleOnly)->sortBy('sort')->pluck('name')->toArray()); - $grouped = self::visible($withHidden)->select('name', 'id', 'feature_category_id')->with('category')->orderBy('name')->get()->keyBy('id')->groupBy('category.name', $preserveKeys = true)->toArray(); + $grouped = self::where('is_visible', '>=', $visibleOnly)->select('name', 'id', 'feature_category_id')->with('category')->orderBy('name')->get()->keyBy('id')->groupBy('category.name', $preserveKeys = true)->toArray(); if (isset($grouped[''])) { if (!$sorted_feature_categories->contains('Miscellaneous')) { $sorted_feature_categories->push('Miscellaneous'); @@ -327,7 +328,7 @@ public static function getDropdownItems($withHidden = 0) { return $features_by_category; } else { - return self::visible($withHidden)->orderBy('name')->pluck('name', 'id')->toArray(); + return self::where('is_visible', '>=', $visibleOnly)->orderBy('name')->pluck('name', 'id')->toArray(); } } }