Added operate? admin? policy for navbar

This commit is contained in:
2024-10-02 14:34:31 +02:00
parent b3c79e095b
commit d28f9ce305
2 changed files with 10 additions and 2 deletions

View File

@@ -12,6 +12,14 @@ class ApplicationPolicy < ActionPolicy::Base
deny! unless user.verified? deny! unless user.verified?
end end
def operate?
allow! if user.operator? || user.admin?
end
def admin?
allow! if user.admin?
end
# Configure additional authorization contexts here # Configure additional authorization contexts here
# (`user` is added by default). # (`user` is added by default).
# #

View File

@@ -13,14 +13,14 @@
<%= link_to "Profil", profile_path %> <%= link_to "Profil", profile_path %>
</button> </button>
</li> </li>
<% if current_user.admin? %> <% if allowed_to? :admin?, with: ApplicationPolicy %>
<li class="relative"> <li class="relative">
<button class="px-4 py-2 <%= current_user.admin? && 'hover:text-hsrm-red' || 'text-hsrm-gray-light' %> border-b-4 <%= admin_tab? && 'border-hsrm-red-light' || 'hover:border-hsrm-red-light hover:bg-gray-100' %>"> <button class="px-4 py-2 <%= current_user.admin? && 'hover:text-hsrm-red' || 'text-hsrm-gray-light' %> border-b-4 <%= admin_tab? && 'border-hsrm-red-light' || 'hover:border-hsrm-red-light hover:bg-gray-100' %>">
<%= link_to_if current_user.admin?, "Admin", admin_dashboard_path %> <%= link_to_if current_user.admin?, "Admin", admin_dashboard_path %>
</button> </button>
</li> </li>
<% end %> <% end %>
<% if current_user.operator? %> <% if allowed_to? :operate?, with: ApplicationPolicy %>
<li class="relative"> <li class="relative">
<button class="px-4 py-2 hover:text-hsrm-red border-b-4 <%= operator_tab? && 'border-hsrm-red-light' || 'hover:border-hsrm-red-light hover:bg-gray-100' %>"> <button class="px-4 py-2 hover:text-hsrm-red border-b-4 <%= operator_tab? && 'border-hsrm-red-light' || 'hover:border-hsrm-red-light hover:bg-gray-100' %>">
<%= link_to 'Operator', operator_jobs_path %> <%= link_to 'Operator', operator_jobs_path %>