Skip to content

Commit

Permalink
Fix Category not respecting is_visible and is_accessible (#698)
Browse files Browse the repository at this point in the history
Co-authored-by: Amin Alaee <mohammadamin.alaee@gmail.com>
  • Loading branch information
Neverfan1 and aminalaee authored Feb 18, 2024
1 parent 4e6e102 commit f797bf1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sqladmin/_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def type_(self) -> str:
class CategoryMenu(ItemMenu):
def is_active(self, request: Request) -> bool:
return any(
c.is_active(request) and c.is_accessible(request) for c in self.children
c.is_visible(request) and c.is_accessible(request) for c in self.children
)

@property
Expand Down
6 changes: 4 additions & 2 deletions sqladmin/templates/_macros.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro menu_category(menu, request) %}
{% if menu.is_visible(request) and menu.is_accessible(request) %}
{% if menu.is_active(request) %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle {% if menu.is_active(request) %}active{% endif %}" data-bs-toggle="dropdown"
href="#">
Expand All @@ -12,13 +12,15 @@
<div class="dropdown-menu-columns">
<div class="dropdown-menu-column">
{% for sub_menu in menu.children %}
{% if sub_menu.is_visible(request) and sub_menu.is_accessible(request) %}
<a class="nav-link ps-lg-3 {% if sub_menu.is_active(request) %}active{% endif %}"
href="{{ sub_menu.url(request) }}">
<span class="nav-link-icon d-md-none d-lg-inline-block">
{% if sub_menu.icon %}<i class="{{ sub_menu.icon }}"></i>{% endif %}
</span>
<span class="nav-link-title">{{ sub_menu.display_name }}</span>
</a>
{% endif %}
{% endfor %}
</div>
</div>
Expand Down Expand Up @@ -50,4 +52,4 @@
{% endif %}
{% endfor %}
</div>
{% endmacro %}
{% endmacro %}

0 comments on commit f797bf1

Please sign in to comment.