Skip to content

Commit

Permalink
Panel cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljames-dj committed Jun 26, 2024
1 parent 43e6c34 commit 47faad5
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 106 deletions.
14 changes: 1 addition & 13 deletions app/controllers/panel_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@ class PanelController < ApplicationController
include DocumentsHelper

before_action :authenticate_user!
before_action -> { redirect_to_root_unless_user(:can_access_panel?) }
before_action -> { redirect_to_root_unless_user(:can_access_panel?, params[:action].to_sym) }, except: [:pending_claims_for_subordinate_delegates]
before_action -> { redirect_to_root_unless_user(:can_access_senior_delegate_panel?) }, only: [:pending_claims_for_subordinate_delegates]
before_action -> { redirect_to_root_unless_user(:can_access_staff_panel?) }, only: [:staff]
before_action -> { redirect_to_root_unless_user(:can_access_delegate_panel?) }, only: [:delegate]
before_action -> { redirect_to_root_unless_user(:can_access_board_panel?) }, only: [:board]
before_action -> { redirect_to_root_unless_user(:can_access_senior_delegate_panel?) }, only: [:senior_delegate]
before_action -> { redirect_to_root_unless_user(:can_access_leader_panel?) }, only: [:leader]
before_action -> { redirect_to_root_unless_user(:can_access_wfc_panel?) }, only: [:wfc]
before_action -> { redirect_to_root_unless_user(:can_access_wrt_panel?) }, only: [:wrt]
before_action -> { redirect_to_root_unless_user(:can_access_wst_panel?) }, only: [:wst]
before_action -> { redirect_to_root_unless_user(:can_access_wdc_panel?) }, only: [:wdc]
before_action -> { redirect_to_root_unless_user(:can_access_wec_panel?) }, only: [:wec]
before_action -> { redirect_to_root_unless_user(:can_access_weat_panel?) }, only: [:weat]
before_action -> { redirect_to_root_unless_user(:can_access_admin_panel?) }, only: [:admin]

def pending_claims_for_subordinate_delegates
# Show pending claims for a given user, or the current user, if they can see them
Expand Down
68 changes: 68 additions & 0 deletions app/helpers/panel_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# frozen_string_literal: true

module PanelHelper
def panel_list
[
{
id: :admin,
name: 'New Admin panel',
url: Rails.application.routes.url_helpers.panel_admin_path,
},
{
id: :staff,
name: 'Staff panel',
url: Rails.application.routes.url_helpers.panel_staff_path,
},
{
id: :delegate,
name: 'Delegate panel',
url: Rails.application.routes.url_helpers.panel_delegate_path,
},
{
id: :wfc,
name: 'WFC panel',
url: Rails.application.routes.url_helpers.panel_wfc_path,
},
{
id: :wrt,
name: 'WRT panel',
url: Rails.application.routes.url_helpers.panel_wrt_path,
},
{
id: :wst,
name: 'WST panel',
url: Rails.application.routes.url_helpers.panel_wst_path,
},
{
id: :board,
name: 'Board panel',
url: Rails.application.routes.url_helpers.panel_board_path,
},
{
id: :leader,
name: 'Leader panel',
url: Rails.application.routes.url_helpers.panel_leader_path,
},
{
id: :senior_delegate,
name: 'Senior Delegate panel',
url: Rails.application.routes.url_helpers.panel_senior_delegate_path,
},
{
id: :wdc,
name: 'WDC panel',
url: Rails.application.routes.url_helpers.panel_wdc_path,
},
{
id: :wec,
name: 'WEC panel',
url: Rails.application.routes.url_helpers.panel_wec_path,
},
{
id: :weat,
name: 'WEAT panel',
url: Rails.application.routes.url_helpers.panel_weat_path,
},
]
end
end
89 changes: 32 additions & 57 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class User < ApplicationRecord
include MicroserviceRegistrationHolder
include PanelHelper

has_many :competition_delegates, foreign_key: "delegate_id"
# This gives all the competitions where the user is marked as a Delegate,
Expand Down Expand Up @@ -1308,69 +1309,43 @@ def regional_delegates
delegate_roles.map { |role| role.group.lead_user }
end

def can_access_wfc_panel?
can_admin_finances?
end

def can_access_wrt_panel?
can_admin_results?
end

def can_access_wst_panel?
software_team?
end

def can_access_board_panel?
admin? || board_member?
end

def can_access_leader_panel?
admin? || active_roles.any? { |role| role.is_lead? && (role.group.teams_committees? || role.group.councils?) }
end

def can_access_senior_delegate_panel?
admin? || board_member? || senior_delegate?
end

def can_access_delegate_panel?
admin? || any_kind_of_delegate?
end

def can_access_staff_panel?
admin? || staff?
end

def can_access_wdc_panel?
admin? || wdc_team?
end

def can_access_wec_panel?
admin? || ethics_committee?
end

def can_access_weat_panel?
admin? || weat_team?
end

def can_access_admin_panel?
admin? || results_team?
def can_access_panel?(panel_id)
case panel_id
when :admin
admin? || results_team?
when :staff
staff?
when :delegate
any_kind_of_delegate?
when :wfc
can_admin_finances?
when :wrt
can_admin_results?
when :wst
software_team?
when :board
board_member?
when :leader
active_roles.any? { |role| role.is_lead? && (role.group.teams_committees? || role.group.councils?) }
when :senior_delegate
senior_delegate?
when :wdc
wdc_team?
when :wec
ethics_committee?
when :weat
weat_team?
else
false
end
end

def can_access_panel?
(
can_access_wfc_panel? ||
can_access_wrt_panel? ||
can_access_wst_panel? ||
can_access_board_panel? ||
can_access_leader_panel? ||
can_access_senior_delegate_panel? ||
can_access_delegate_panel? ||
can_access_staff_panel? ||
can_access_wdc_panel? ||
can_access_wec_panel? ||
can_access_weat_panel? ||
can_access_admin_panel?
)
def can_access_at_least_one_panel?
panel_list.any? { |panel| can_access_panel?(panel[:id]) }
end

def subordinate_delegates
Expand Down
41 changes: 5 additions & 36 deletions app/views/layouts/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -217,46 +217,15 @@
<li><%= link_to t('.my_results'), person_path(current_user.wca_id) %></li>
<% end %>
<% if current_user.can_access_panel? %>
<% if current_user.can_access_at_least_one_panel? %>
<li class="divider"></li>
<li role="presentation" class="dropdown-header">
<%= t '.panel' %>
</li>
<% if current_user.can_access_staff_panel? %>
<li><%= link_to "Staff panel", panel_staff_path %></li>
<% end %>
<% if current_user.can_access_delegate_panel? %>
<li><%= link_to "Delegate panel", panel_delegate_path %></li>
<% end %>
<% if current_user.can_access_wfc_panel? %>
<li><%= link_to "WFC panel", panel_wfc_path %></li>
<% end %>
<% if current_user.can_access_wrt_panel? %>
<li><%= link_to "WRT panel", panel_wrt_path %></li>
<% end %>
<% if current_user.can_access_wst_panel? %>
<li><%= link_to "WST panel", panel_wst_path %></li>
<% end %>
<% if current_user.can_access_board_panel? %>
<li><%= link_to "Board panel", panel_board_path %></li>
<% end %>
<% if current_user.can_access_leader_panel? %>
<li><%= link_to "Leader panel", panel_leader_path %></li>
<% end %>
<% if current_user.can_access_senior_delegate_panel? %>
<li><%= link_to "Senior Delegate panel", panel_senior_delegate_path %></li>
<% end %>
<% if current_user.can_access_wdc_panel? %>
<li><%= link_to "WDC panel", panel_wdc_path %></li>
<% end %>
<% if current_user.can_access_wec_panel? %>
<li><%= link_to "WEC panel", panel_wec_path %></li>
<% end %>
<% if current_user.can_access_weat_panel? %>
<li><%= link_to "WEAT panel", panel_weat_path %></li>
<% end %>
<% if current_user.can_access_admin_panel? %>
<li><%= link_to "New Admin panel", panel_admin_path %></li>
<% panel_list.each do |panel| %>
<% if current_user.can_access_panel?(panel[:id]) %>
<li><%= link_to panel[:name], panel[:url] %></li>
<% end %>
<% end %>
<% end %>
<% if current_user.can_view_poll? %>
Expand Down

0 comments on commit 47faad5

Please sign in to comment.