From 52ae67bc2ca1cf599d70a47ca0374d0271841479 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Wed, 1 May 2024 20:14:02 +0530 Subject: [PATCH] Remove /teams page (#9331) --- app/controllers/teams_controller.rb | 5 ---- app/models/user.rb | 7 +---- app/views/admin/_nav.html.erb | 1 - app/views/teams/edit.html.erb | 3 -- app/views/teams/index.html.erb | 36 ----------------------- app/webpacker/lib/requests/routes.js.erb | 2 -- config/routes.rb | 2 +- spec/controllers/teams_controller_spec.rb | 29 ------------------ spec/views/teams/index.html.erb_spec.rb | 26 ---------------- 9 files changed, 2 insertions(+), 109 deletions(-) delete mode 100644 app/views/teams/index.html.erb delete mode 100644 spec/views/teams/index.html.erb_spec.rb diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index d9b016c21f..7b422b4add 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -2,13 +2,8 @@ class TeamsController < ApplicationController before_action :authenticate_user! - before_action -> { redirect_to_root_unless_user(:can_manage_teams?) }, except: [:edit, :update] before_action -> { redirect_to_root_unless_user(:can_edit_team?, team_from_params) }, only: [:edit, :update] - def index - @teams = Team.unscoped.all - end - def edit @team = team_from_params end diff --git a/app/models/user.rb b/app/models/user.rb index d0f5d4183f..f2d2d30b88 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -673,14 +673,9 @@ def can_admin_finances? admin? || financial_committee? end - # Returns true if the user can perform every action for teams. - def can_manage_teams? - admin? || board_member? || results_team? - end - # Returns true if the user can edit the given team. def can_edit_team?(team) - can_manage_teams? || + can_edit_any_groups? || team_leader?(team) || # The leader of the WDC can edit the banned competitors list (team == Team.banned && team_leader?(Team.wdc)) diff --git a/app/views/admin/_nav.html.erb b/app/views/admin/_nav.html.erb index d0a5b23a3b..2b89deba26 100644 --- a/app/views/admin/_nav.html.erb +++ b/app/views/admin/_nav.html.erb @@ -6,7 +6,6 @@ <% [ { text: "List competitions", path: competitions_view, fa_icon: "list" }, { text: "Delegates", path: delegates_path(anchor: "all"), fa_icon: "sitemap" }, - { text: "Edit teams", path: teams_path, fa_icon: "users" }, { text: "Posting Dashboard", path: panel_wrt_path(anchor: PanelController.panel_list['wrt']['postingDashboard']), fa_icon: "user lock" }, { text: "Run validators", path: admin_check_results_path, fa_icon: "check double" }, { text: "Create newcomers", path: admin_finish_unfinished_persons_path, fa_icon: "user plus" }, diff --git a/app/views/teams/edit.html.erb b/app/views/teams/edit.html.erb index d2017daee1..a6c668d760 100644 --- a/app/views/teams/edit.html.erb +++ b/app/views/teams/edit.html.erb @@ -61,9 +61,6 @@
- <%= link_to teams_path, class: "btn btn-default teams-home" do %> - <%= ui_icon("undo") %> Back to Teams - <% end %> <%= f.button :submit, class: "btn btn-primary" %>
<% end %> diff --git a/app/views/teams/index.html.erb b/app/views/teams/index.html.erb deleted file mode 100644 index 4a5977c0fd..0000000000 --- a/app/views/teams/index.html.erb +++ /dev/null @@ -1,36 +0,0 @@ -<% provide(:title, 'Teams') %> - -
-

<%= yield(:title) %>

- - <% if @teams.empty? %> - <%= alert :warning, "There are currently no teams." %> - <% else %> -
- - - - - - - - - <% @teams.each do |team| %> - - - - - - - - <% end %> -
IDNameMembersLeader(s)
<%= team.friendly_id %><%= team.name %><%= users_to_sentence team.current_members.includes(:user).map(&:user) %> - <%= users_to_sentence team.current_members.where(team_leader: true).map(&:user) %> - - <%= link_to edit_team_path(team), class: "btn btn-success" do %> - <%= ui_icon("edit") %> Manage - <% end %> -
-
- <% end %> -
diff --git a/app/webpacker/lib/requests/routes.js.erb b/app/webpacker/lib/requests/routes.js.erb index 34c8ebb783..f59ea772e7 100644 --- a/app/webpacker/lib/requests/routes.js.erb +++ b/app/webpacker/lib/requests/routes.js.erb @@ -147,8 +147,6 @@ export const subordinateDelegateClaimsUrl = `<%= CGI.unescape(Rails.application. export const subordinateUpcomingCompetitionsUrl = `<%= CGI.unescape(Rails.application.routes.url_helpers.competitions_for_senior_path) %>`; export const wfcCompetitionsExportUrl = `<%= CGI.unescape(Rails.application.routes.url_helpers.wfc_competitions_export_path) %>`; -export const teamUrl = (id) => `<%= CGI.unescape(Rails.application.routes.url_helpers.team_path("${id}"))%>`; - export const wfcXeroUsersUrl = `<%= CGI.unescape(Rails.application.routes.url_helpers.api_v0_wfc_xero_users_path) %>`; export const wfcDuesRedirectsUrl = `<%= CGI.unescape(Rails.application.routes.url_helpers.api_v0_wfc_dues_redirects_path) %>`; diff --git a/config/routes.rb b/config/routes.rb index e3dbc8e4e7..10f6b3da3b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -181,7 +181,7 @@ get 'polls/:id/vote' => 'votes#vote', as: 'polls_vote' get 'polls/:id/results' => 'polls#results', as: 'polls_results' - resources :teams, only: [:index, :update, :edit] + resources :teams, only: [:update, :edit] resources :votes, only: [:create, :update] diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb index fe393921ae..a53ff3e777 100644 --- a/spec/controllers/teams_controller_spec.rb +++ b/spec/controllers/teams_controller_spec.rb @@ -5,35 +5,6 @@ RSpec.describe TeamsController do let(:team) { FactoryBot.create :team } - describe "GET #index" do - context "when not signed in" do - sign_out - - it 'redirects to the sign in page' do - get :index - expect(response).to redirect_to new_user_session_path - end - end - - context "when signed in as admin" do - sign_in { FactoryBot.create :admin } - - it 'shows the teams index page' do - get :index - expect(response).to render_template :index - end - end - - context 'when signed in as a regular user' do - sign_in { FactoryBot.create :user } - - it 'does not allow access' do - get :index - expect(response).to redirect_to root_url - end - end - end - describe 'GET #edit' do context 'when signed in as a team leader without rights to manage all teams' do let(:team_where_is_leader) { Team.wrc } diff --git a/spec/views/teams/index.html.erb_spec.rb b/spec/views/teams/index.html.erb_spec.rb deleted file mode 100644 index 995ff1a0a6..0000000000 --- a/spec/views/teams/index.html.erb_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe "teams/index.html.erb" do - describe "when signed in as an admin" do - let!(:user) { FactoryBot.create :admin } - let!(:teams) { Team.unscoped.all } - - before do - allow(view).to receive(:current_user) { user } - assign(:teams, teams) - render - end - - it "lists teams" do - teams.each do |team| - expect(rendered).to match team.name - end - end - - it "shows members of a team" do - expect(rendered).to match user.name - end - end -end