From cf5207564f210fd8edd75814342c717affbcd541 Mon Sep 17 00:00:00 2001 From: Ridhwana Date: Thu, 15 Apr 2021 14:53:46 +0200 Subject: [PATCH] RFC#50-P5 Prepares the admin restructure to be tested (#13114) * feat: make the sidebar more dynamic * refactor: use the action in the same controller instead of the whole path * feat: remove hardcoded routes * feat: move routes into file * feat: use rails 6 draw for the admin routes * add a helper method * oops: fix super * feat: add the hacky helper methods :( ) * WIP: created different path helpers for the new routes and point the old helpers to the new ones if the FF is toggled * feat: update the module * chore: add new paths * feat: change link_to's use paths instead * feat: feedback_messages to scoped admin route * chore: update the feature flag urls helpers * feat: feedback_messages issue * chore: remove all the workarounds * chore: rubucop * fix: oops remove helper * chore: comment out the tests that touch the tabbed navbar which is affected by the rails application needing to be reloaded * feat: ensure that we chcek if the db table exists --- app/controllers/admin/badges_controller.rb | 2 +- .../admin/broadcasts_controller.rb | 2 +- .../admin/display_ads_controller.rb | 2 +- app/controllers/admin/events_controller.rb | 2 +- .../admin/html_variants_controller.rb | 2 +- .../admin/listing_categories_controller.rb | 2 +- .../admin/navigation_links_controller.rb | 6 +- .../admin/response_templates_controller.rb | 2 +- .../admin/sponsorships_controller.rb | 2 +- app/controllers/admin/tools_controller.rb | 4 +- app/helpers/admin_helper.rb | 4 +- .../admin/badge_achievements/index.html.erb | 2 +- app/views/admin/broadcasts/show.html.erb | 2 +- app/views/admin/chat_channels/index.html.erb | 2 +- app/views/admin/display_ads/index.html.erb | 2 +- .../admin/listing_categories/index.html.erb | 2 +- app/views/admin/overview/index.html.erb | 9 +- .../admin/response_templates/new.html.erb | 1 - app/views/admin/secrets/index.html.erb | 2 +- .../admin/shared/_nested_sidebar.html.erb | 2 +- .../admin/shared/_tabbed_navbar.html.erb | 3 +- app/views/admin/sponsorships/edit.html.erb | 2 +- app/views/admin/tags/index.html.erb | 6 +- config/routes.rb | 179 ++---------------- config/routes/admin.rb | 87 +++++++++ config/routes/current_admin.rb | 78 ++++++++ spec/requests/admin/nested_sidebar_spec.rb | 24 ++- 27 files changed, 223 insertions(+), 210 deletions(-) create mode 100644 config/routes/admin.rb create mode 100644 config/routes/current_admin.rb diff --git a/app/controllers/admin/badges_controller.rb b/app/controllers/admin/badges_controller.rb index a24d82565..035a0f6d3 100644 --- a/app/controllers/admin/badges_controller.rb +++ b/app/controllers/admin/badges_controller.rb @@ -22,7 +22,7 @@ module Admin redirect_to admin_badges_path else flash[:danger] = @badge.errors_as_sentence - render new_admin_badge_path + render :new end end diff --git a/app/controllers/admin/broadcasts_controller.rb b/app/controllers/admin/broadcasts_controller.rb index c30f57566..15d085b37 100644 --- a/app/controllers/admin/broadcasts_controller.rb +++ b/app/controllers/admin/broadcasts_controller.rb @@ -30,7 +30,7 @@ module Admin redirect_to admin_broadcast_path(@broadcast) else flash[:danger] = @broadcast.errors.full_messages.to_sentence - render new_admin_broadcast_path + render :new end end diff --git a/app/controllers/admin/display_ads_controller.rb b/app/controllers/admin/display_ads_controller.rb index ef72d279a..8eab6657c 100644 --- a/app/controllers/admin/display_ads_controller.rb +++ b/app/controllers/admin/display_ads_controller.rb @@ -31,7 +31,7 @@ module Admin redirect_to admin_display_ads_path else flash[:danger] = @display_ad.errors_as_sentence - render new_admin_display_ad_path + render :new end end diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 5f6602ad7..85cb1c62a 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -26,7 +26,7 @@ module Admin redirect_to admin_events_path else flash[:danger] = @event.errors.full_messages - render new_admin_event_path + render :new end end diff --git a/app/controllers/admin/html_variants_controller.rb b/app/controllers/admin/html_variants_controller.rb index 25a041cc2..d0a21da00 100644 --- a/app/controllers/admin/html_variants_controller.rb +++ b/app/controllers/admin/html_variants_controller.rb @@ -43,7 +43,7 @@ module Admin redirect_to admin_html_variants_path(state: "mine") else flash[:danger] = @html_variant.errors_as_sentence - render new_admin_html_variant_path + render :new end end diff --git a/app/controllers/admin/listing_categories_controller.rb b/app/controllers/admin/listing_categories_controller.rb index 33040a5f0..2bf562bad 100644 --- a/app/controllers/admin/listing_categories_controller.rb +++ b/app/controllers/admin/listing_categories_controller.rb @@ -28,7 +28,7 @@ module Admin redirect_to admin_listing_categories_path else flash[:danger] = @listing_category.errors_as_sentence - render new_admin_listing_category_path + render :new end end diff --git a/app/controllers/admin/navigation_links_controller.rb b/app/controllers/admin/navigation_links_controller.rb index 26dee4fe7..941b6a665 100644 --- a/app/controllers/admin/navigation_links_controller.rb +++ b/app/controllers/admin/navigation_links_controller.rb @@ -17,7 +17,7 @@ module Admin else flash[:error] = "Error: #{navigation_link.errors_as_sentence}" end - redirect_to admin_navigation_links_url + redirect_to admin_navigation_links_path end def update @@ -27,7 +27,7 @@ module Admin else flash[:error] = "Error: #{navigation_link.errors_as_sentence}" end - redirect_to admin_navigation_links_url + redirect_to admin_navigation_links_path end def destroy @@ -37,7 +37,7 @@ module Admin else flash[:error] = "Error: #{navigation_link.errors_as_sentence}" end - redirect_to admin_navigation_links_url + redirect_to admin_navigation_links_path end private diff --git a/app/controllers/admin/response_templates_controller.rb b/app/controllers/admin/response_templates_controller.rb index b466a0b8c..83b97d113 100644 --- a/app/controllers/admin/response_templates_controller.rb +++ b/app/controllers/admin/response_templates_controller.rb @@ -26,7 +26,7 @@ module Admin else flash[:danger] = @response_template.errors_as_sentence @response_templates = ResponseTemplate.page(params[:page]).per(50) - render new_admin_response_template_path + render :new end end diff --git a/app/controllers/admin/sponsorships_controller.rb b/app/controllers/admin/sponsorships_controller.rb index c0b9d8a7a..4c4038497 100644 --- a/app/controllers/admin/sponsorships_controller.rb +++ b/app/controllers/admin/sponsorships_controller.rb @@ -28,7 +28,7 @@ module Admin redirect_to admin_sponsorships_path else flash[:danger] = @sponsorship.errors_as_sentence - render new_admin_sponsorship_path + render :new end end diff --git a/app/controllers/admin/tools_controller.rb b/app/controllers/admin/tools_controller.rb index 8dff8898f..b87f78ba2 100644 --- a/app/controllers/admin/tools_controller.rb +++ b/app/controllers/admin/tools_controller.rb @@ -15,10 +15,10 @@ module Admin handle_article_cache "Article ##{params[:bust_article]} was successfully busted" end - redirect_to "/admin/tools" + redirect_to admin_tools_path rescue StandardError => e flash[:danger] = e.message - redirect_to "/admin/tools" + redirect_to admin_tools_path end private diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index e59136763..70a5abd96 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -50,11 +50,11 @@ module AdminHelper # @ridhwana end delete def deduced_controller(request) - request.path.split("/").last + request.path.split("/").fourth end def deduced_scope(request) - request.path.split("/").second_to_last + request.path.split("/").third end def display_name(group_name) diff --git a/app/views/admin/badge_achievements/index.html.erb b/app/views/admin/badge_achievements/index.html.erb index 88c7a5654..3c097d5ab 100644 --- a/app/views/admin/badge_achievements/index.html.erb +++ b/app/views/admin/badge_achievements/index.html.erb @@ -36,7 +36,7 @@ badge image - <%= link_to "Remove", url_for(action: :destroy, id: badge_achievement.id), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> + <%= link_to "Remove", admin_badge_achievement_path(badge_achievement), class: "crayons-btn crayons-btn--danger", method: :delete, data: { confirm: "Are you sure?" } %> <% end %> diff --git a/app/views/admin/broadcasts/show.html.erb b/app/views/admin/broadcasts/show.html.erb index 248ac9f86..c74cb214f 100644 --- a/app/views/admin/broadcasts/show.html.erb +++ b/app/views/admin/broadcasts/show.html.erb @@ -1,7 +1,7 @@

<%= @broadcast.title %>

- <%= link_to "Destroy", url_for(action: :destroy, id: @broadcast.id), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %> + <%= link_to "Destroy", admin_broadcast_path(@broadcast), class: "btn btn-danger", method: :delete, data: { confirm: "Are you sure?" } %> <%= link_to "Edit", edit_admin_broadcast_path, class: "btn btn-primary" %>
diff --git a/app/views/admin/chat_channels/index.html.erb b/app/views/admin/chat_channels/index.html.erb index 32221eb7b..610fa7511 100644 --- a/app/views/admin/chat_channels/index.html.erb +++ b/app/views/admin/chat_channels/index.html.erb @@ -57,7 +57,7 @@ <% if current_user.any_admin? %> <% if channel.users.count.zero? %> - <%= button_to "Delete Channel", { action: "destroy", id: channel.id }, method: :delete, data: { confirm: "Are you sure?" }, class: "crayons-btn crayons-btn--danger" %> + <%= link_to "Delete Channel", admin_chat_channel_path(channel), class: "crayons-btn crayons-btn--danger", method: :delete, data: { confirm: "Are you sure?" } %> <% else %> Cannot delete a channel with users <% end %> diff --git a/app/views/admin/display_ads/index.html.erb b/app/views/admin/display_ads/index.html.erb index e922ee4ab..409f8d90a 100644 --- a/app/views/admin/display_ads/index.html.erb +++ b/app/views/admin/display_ads/index.html.erb @@ -1,5 +1,5 @@