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
This commit is contained in:
Ridhwana 2021-04-15 14:53:46 +02:00 committed by GitHub
parent 1a5ae75140
commit cf5207564f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 223 additions and 210 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -36,7 +36,7 @@
<td class="justify-content-center">
<img class="mx-auto mt-3" width="40" height="40" src="<%= badge_achievement.badge.badge_image %>" alt="badge image">
</td>
<td><%= link_to "Remove", url_for(action: :destroy, id: badge_achievement.id), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %></td>
<td><%= link_to "Remove", admin_badge_achievement_path(badge_achievement), class: "crayons-btn crayons-btn--danger", method: :delete, data: { confirm: "Are you sure?" } %></td>
</h5>
</tr>
<% end %>

View file

@ -1,7 +1,7 @@
<header class="flex">
<h2 class="crayons-title mb-6"><%= @broadcast.title %></h2>
<div class="ml-auto">
<%= 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" %>
</div>
</header>

View file

@ -57,7 +57,7 @@
<% if current_user.any_admin? %>
<td>
<% 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 %>

View file

@ -1,5 +1,5 @@
<nav class="flex mb-4" aria-label="Display Ads navigation">
<%= form_tag("/admin/display_ads", method: "get") do %>
<%= form_tag(admin_display_ads_path, method: "get") do %>
<%= text_field_tag(:search, params[:search], aria: { label: "Search" }, class: "crayons-header--search-input crayons-textfield", placeholder: "Search by Org name") %>
<% end %>
<div class="ml-auto">

View file

@ -1,5 +1,5 @@
<nav class="flex mb-4" aria-label="Listing Category navigation">
<%= form_tag("/admin/listings/categories", method: "get") do %>
<%= form_tag(admin_listing_categories_path, method: "get") do %>
<%= text_field_tag(:search, params[:search], aria: { label: "Search" }, class: "top-bar--search-input crayons-textfield", placeholder: "Search by name") %>
<% end %>
<div class="ml-auto">

View file

@ -8,12 +8,13 @@
<h3 class="crayons-subtitle-1">Welcome Checklist</h3>
<p class="crayons-subtitle-4 color-base-70 mb-3">Here are a few things we recommend doing now that you're using Forem!</p>
<ol>
<li class="mb-1 -ml-4">Set up and configure your Forem under <a href="/admin/config" data-action="click->ahoy#trackOverviewLink">Config</a></li>
<li class="mb-1 -ml-4">Set up and configure your Forem under <%= link_to "Config", admin_config_path, 'data-action': "click->ahoy#trackOverviewLink" %></li>
<li class="mb-1 -ml-4"><a href="/admin/invitations" data-action="click->ahoy#trackOverviewLink">Invite people</a> to join your Forem</li>
<li class="mb-1 -ml-4"><a href="/admin/tags" data-action="click->ahoy#trackOverviewLink">Update your Forem tags</a></li>
<li class="mb-1 -ml-4"><a href="/admin/pages" data-action="click->ahoy#trackOverviewLink">Create pages</a> and <a href="/admin/navigation_links" data-action="click->ahoy#trackOverviewLink">sort them in the navigation sidebar</a></li>
<li class="mb-1 -ml-4"><%= link_to "Update your Forem tags", admin_tags_path, 'data-action': "click->ahoy#trackOverviewLink" %></li>
<li class="mb-1 -ml-4"><%= link_to "Create pages", admin_pages_path, 'data-action': "click->ahoy#trackOverviewLink" %> and <%= link_to "sort them in the navigation sidebar", admin_navigation_links_path, 'data-action': "click->ahoy#trackOverviewLink" %></li>
<li class="mb-1 -ml-4">Read the <a href="https://forem.gitbook.io/forem-admin-guide/quick-start-guide" data-action="click->ahoy#trackOverviewLink">Quick Start Guide</a></li>
<li class="mb-1 -ml-4"><a href="/admin/welcome" data-action="click->ahoy#trackOverviewLink">Set up a Welcome Thread</a></li>
<li class="mb-1 -ml-4"><%= link_to "Set up a Welcome Thread", admin_welcome_index_path, 'data-action': "click->ahoy#trackOverviewLink" %></li>
<li class="mb-1 -ml-4">Browse the <a href="https://forem.gitbook.io/forem-admin-guide" data-action="click->ahoy#trackOverviewLink">Forem Admin Guide</a></li>
<li class="-ml-4">Join the private <a href="https://creators.forem.com">Creators Forem</a> (email <a href="mailto:support@forem.com" data-action="click->ahoy#trackOverviewLink">support@forem.com</a> if you need an invite)</li>
</ol>

View file

@ -1,4 +1,3 @@
<h2 class="crayons-title mb-6">Create template</h2>
<%= render "form", response_template: @response_template %>

View file

@ -17,7 +17,7 @@
<tbody class="crayons-card">
<% @secrets.each do |key, partial_value| %>
<tr>
<%= form_with(url: "/admin/secrets", method: "PUT", local: true) do %>
<%= form_with(url: admin_secrets_path, method: "PUT", local: true) do %>
<td><%= label_tag key, key %></td>
<td><%= text_field_tag key, partial_value %></td>
<td><%= submit_tag("Update", data: { confirm: "My username is @#{current_user.username} and I want to update this Vault Secret." }, disabled: !@vault_enabled) %></td>

View file

@ -2,7 +2,7 @@
<li>
<% if group[:children].length == 1 %>
<% if group[:children][0][:visible] %>
<a class="crayons-link crayons-link--block <%= "crayons-link--current" if deduced_controller(request) == group[:children][0][:controller] %>"
<a class="crayons-link crayons-link--block <%= "crayons-link--current" if deduced_scope(request) == group[:children][0][:controller] %>"
href="/admin/<%= group[:children][0][:controller] %>"
aria-page="<%= "page" if deduced_controller(request) == group[:children][0][:controller] %>"
data-action="click->sidebar#expandDropdown">

View file

@ -1,4 +1,5 @@
<% if menu_items.present? && menu_items[:children].any? %>
<!-- menu_items.is_a?(Hash) we have this condition because /reports changes to /feedback_messages -->
<% if menu_items.present? && menu_items.is_a?(Hash) && menu_items[:children].any? %>
<header class="mb-3 admin__tabbed-navbar">
<h2 class="crayons-title"><%= menu_items[:name].to_s.titleize %></h2>
<div class="block s:flex items-center space-between">

View file

@ -52,6 +52,6 @@
<%= f.datetime_select :instructions_updated_at, required: true, start_year: Time.current.year, end_year: Time.current.year + 2, class: "form-control" %> UTC Time
</div>
<%= f.submit "Update Sponsorship", class: "btn btn-primary" %>
<%= link_to "Destroy Sponsorship", url_for(action: :destroy, id: @sponsorship.id), method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-danger" %>
<%= link_to "Destroy Sponsorship", admin_sponsorship_path(@sponsorship), class: "btn btn-danger", method: :delete, data: { confirm: "Are you sure?" } %>
<% end %>
</div>

View file

@ -1,13 +1,13 @@
<div class="flex items-center mb-6">
<div class="crayons-tabs">
<div class="nav-item">
<a href="/admin/tags?q[supported_not_null]=true" class="crayons-tabs__item <%= "crayons-tabs__item--current" if params.dig(:q, :supported_not_null) %>" aria-label="All Tags">All</a>
<%= link_to "All", admin_tags_path("q[supported_not_null]": "true"), class: "crayons-tabs__item #{'crayons-tabs__item--current' if params.dig(:q, :supported_not_null)}", "aria-label": "All Tags" %>
</div>
<div class="nav-item">
<a href="/admin/tags?q[supported_eq]=true" class="crayons-tabs__item <%= "crayons-tabs__item--current" if params.dig(:q, :supported_eq) == "true" %>" aria-label="Supported Tags">Supported</a>
<%= link_to "Supported", admin_tags_path("q[supported_eq": "true"), class: "crayons-tabs__item #{'crayons-tabs__item--current' if params.dig(:q, :supported_eq) == 'true'}", "aria-label": "Supported Tags" %>
</div>
<div class="nav-item">
<a href="/admin/tags?q[supported_eq]=false" class="crayons-tabs__item <%= "crayons-tabs__item--current" if params.dig(:q, :supported_eq) == "false" %>" aria-label="Unsupported Tags">Unsupported</a>
<%= link_to "Unsupported", admin_tags_path("q[supported_eq": "false"), class: "crayons-tabs__item #{'crayons-tabs__item--current' if params.dig(:q, :supported_eq) == 'false'}", "aria-label": "Unsupported Tags" %>
</div>
</div>

View file

@ -40,6 +40,8 @@ Rails.application.routes.draw do
namespace :admin do
get "/", to: "overview#index"
# NOTE: [@ridhwana] These are the admin routes that have stayed the same even with the
# restructure. They'll move into routes/admin.rb once we remove the old code.
authenticate :user, ->(user) { user.tech_admin? } do
mount Blazer::Engine, at: "blazer"
@ -48,7 +50,6 @@ Rails.application.routes.draw do
remote_token http_origin session_hijacking] } })
mount flipper_ui, at: "feature_flags"
end
resources :feedback_messages, only: %i[index show]
resources :invitations, only: %i[index new create destroy]
resources :organization_memberships, only: %i[update destroy create]
resources :permissions, only: %i[index]
@ -79,173 +80,15 @@ Rails.application.routes.draw do
get "/badges/badge_achievements", to: redirect("/admin/badge_achievements")
get "/badges/badge_achievements/award_badges", to: redirect("/admin/badge_achievements/award_badges")
# NOTE: @ridhwana These routes below will be deleted once we remove the
# admin_restructure feature flag, hence they've been regrouped in this manner.
resources :articles, only: %i[index show update]
resources :badges, only: %i[index edit update new create]
resources :badge_achievements, only: %i[index destroy]
get "/badge_achievements/award_badges", to: "badge_achievements#award"
post "/badge_achievements/award_badges", to: "badge_achievements#award_badges"
resources :broadcasts
resources :chat_channels, only: %i[index create update destroy] do
member do
delete :remove_user
end
end
resources :comments, only: [:index]
resource :config
resources :display_ads, only: %i[index edit update new create destroy]
resources :events, only: %i[index create update new edit]
resources :html_variants, only: %i[index edit update new create show destroy]
resources :listings, only: %i[index edit update destroy]
resources :listing_categories, only: %i[index edit update new create
destroy], path: "listings/categories"
resources :navigation_links, only: %i[index update create destroy]
resources :organizations, only: %i[index show] do
member do
patch "update_org_credits"
end
end
resources :pages, only: %i[index new create edit update destroy]
resources :podcasts, only: %i[index edit update destroy] do
member do
post :fetch
post :add_owner
end
end
resources :mods, only: %i[index update]
resources :moderator_actions, only: %i[index]
resources :navigation_links, only: %i[index update create destroy]
resources :privileged_reactions, only: %i[index]
resources :reports, only: %i[index show], controller: "feedback_messages" do
collection do
post "send_email"
post "create_note"
post "save_status"
end
end
resources :response_templates, only: %i[index new edit create update destroy]
resources :secrets, only: %i[index]
put "secrets", to: "secrets#update"
resources :sponsorships, only: %i[index edit update new create destroy]
resources :tags, only: %i[index new create update edit] do
resource :moderator, only: %i[create destroy], module: "tags"
end
resources :tools, only: %i[index create] do
collection do
post "bust_cache"
end
end
resources :webhook_endpoints, only: :index
resources :welcome, only: %i[index create]
# We do not expose the Data Update Scripts to all Forems by default.
constraints(->(_request) { FeatureFlag.enabled?(:data_update_scripts) }) do
resources :data_update_scripts, only: %i[index show] do
member do
post :force_run
end
end
end
# NOTE: @citizen428 The next two resources have a temporary constraint
# while profile generalization is still WIP
constraints(->(_request) { FeatureFlag.enabled?(:profile_admin) }) do
resources :profile_field_groups, only: %i[update create destroy]
resources :profile_fields, only: %i[index update create destroy]
end
# @ridhwana end of routes that will be deleted once we remove the admin_restructure feature flag
# @ridhwana Feature Flag that implements the updated routes for the admin restructure is a work in progress.
constraints(->(_request) { FeatureFlag.enabled?(:admin_restructure) }) do
scope path: :content_manager, as: "content_manager" do
resources :articles, only: %i[index show update]
resources :badges, only: %i[index edit update new create]
resources :badge_achievements, only: %i[index destroy]
get "/badge_achievements/award_badges", to: "badge_achievements#award"
post "/badge_achievements/award_badges", to: "badge_achievements#award_badges"
resources :comments, only: [:index]
resources :organizations, only: %i[index show] do
member do
patch "update_org_credits"
end
end
resources :podcasts, only: %i[index edit update destroy] do
member do
post :fetch
post :add_owner
end
end
resources :tags, only: %i[index new create update edit] do
resource :moderator, only: %i[create destroy], module: "tags"
end
end
scope path: :customization, as: "customization" do
resource :config
resources :display_ads, only: %i[index edit update new create destroy]
resources :html_variants, only: %i[index edit update new create show destroy]
resources :navigation_links, only: %i[index update create destroy]
resources :pages, only: %i[index new create edit update destroy]
# NOTE: @citizen428 The next two resources have a temporary constraint
# while profile generalization is still WIP
constraints(->(_request) { FeatureFlag.enabled?(:profile_admin) }) do
resources :profile_field_groups, only: %i[update create destroy]
resources :profile_fields, only: %i[index update create destroy]
end
end
scope path: :moderation, as: "moderation" do
resources :reports, only: %i[index show], controller: "feedback_messages" do
collection do
post "send_email"
post "create_note"
post "save_status"
end
end
resources :mods, only: %i[index update]
resources :moderator_actions, only: %i[index]
resources :privileged_reactions, only: %i[index]
end
scope path: :advanced, as: "advanced" do
resources :broadcasts
resources :response_templates, only: %i[index new edit create update destroy]
resources :secrets, only: %i[index]
put "secrets", to: "secrets#update"
resources :sponsorships, only: %i[index edit update new create destroy]
resources :tools, only: %i[index create] do
collection do
post "bust_cache"
end
end
resources :webhook_endpoints, only: :index
# We do not expose the Data Update Scripts to all Forems by default.
constraints(->(_request) { FeatureFlag.enabled?(:data_update_scripts) }) do
resources :data_update_scripts, only: %i[index show] do
member do
post :force_run
end
end
end
end
scope path: :apps do
resources :chat_channels, only: %i[index create update destroy] do
member do
delete :remove_user
end
end
resources :events, only: %i[index create update new edit]
resources :listings, only: %i[index edit update destroy]
resources :listing_categories, only: %i[index edit update new create
destroy], path: "listings/categories"
resources :welcome, only: %i[index create]
end
# NOTE: [@ridhwana] All these conditional statements are temporary conditions.
# We check that the database table exists to avoid the DB setup failing
# because the code relies on the presence of a table.
if Database.table_exists?("flipper_features")
# NOTE: [@ridhwana] admin_routes will require the rails app to be reloaded when the feature flag is toggled
# You can find more details on why we had to implement it this way in this PR
# https://github.com/forem/forem/pull/13114
admin_routes = FeatureFlag.enabled?(:admin_restructure) ? :admin : :current_admin
draw admin_routes
end
end

87
config/routes/admin.rb Normal file
View file

@ -0,0 +1,87 @@
scope :content_manager do
resources :articles, only: %i[index show update]
resources :badges, only: %i[index edit update new create]
resources :badge_achievements, only: %i[index destroy]
get "/badge_achievements/award_badges", to: "badge_achievements#award"
post "/badge_achievements/award_badges", to: "badge_achievements#award_badges"
resources :comments, only: [:index]
resources :organizations, only: %i[index show] do
member do
patch "update_org_credits"
end
end
resources :podcasts, only: %i[index edit update destroy] do
member do
post :fetch
post :add_owner
end
end
resources :tags, only: %i[index new create update edit] do
resource :moderator, only: %i[create destroy], module: "tags"
end
end
scope :customization do
resource :config
resources :display_ads, only: %i[index edit update new create destroy]
resources :html_variants, only: %i[index edit update new create show destroy]
resources :navigation_links, only: %i[index update create destroy]
resources :pages, only: %i[index new create edit update destroy]
# NOTE: @citizen428 The next two resources have a temporary constraint
# while profile generalization is still WIP
constraints(->(_request) { FeatureFlag.enabled?(:profile_admin) }) do
resources :profile_field_groups, only: %i[update create destroy]
resources :profile_fields, only: %i[index update create destroy]
end
end
scope :moderation do
resources :feedback_messages, only: %i[index show]
resources :reports, only: %i[index show], controller: "feedback_messages" do
collection do
post "send_email"
post "create_note"
post "save_status"
end
end
resources :mods, only: %i[index update]
resources :moderator_actions, only: %i[index]
resources :privileged_reactions, only: %i[index]
end
scope :advanced do
resources :broadcasts
resources :response_templates, only: %i[index new edit create update destroy]
resources :secrets, only: %i[index]
put "secrets", to: "secrets#update"
resources :sponsorships, only: %i[index edit update new create destroy]
resources :tools, only: %i[index create] do
collection do
post "bust_cache"
end
end
resources :webhook_endpoints, only: :index
# We do not expose the Data Update Scripts to all Forems by default.
constraints(->(_request) { FeatureFlag.enabled?(:data_update_scripts) }) do
resources :data_update_scripts, only: %i[index show] do
member do
post :force_run
end
end
end
end
scope :apps do
resources :chat_channels, only: %i[index create update destroy] do
member do
delete :remove_user
end
end
resources :events, only: %i[index create update new edit]
resources :listings, only: %i[index edit update destroy]
resources :listing_categories, only: %i[index edit update new create
destroy], path: "listings/categories"
resources :welcome, only: %i[index create]
end

View file

@ -0,0 +1,78 @@
# NOTE: @ridhwana These routes below will be deleted once we remove the
# admin_restructure feature flag, hence they've been regrouped in this manner.
resources :articles, only: %i[index show update]
resources :badges, only: %i[index edit update new create]
resources :badge_achievements, only: %i[index destroy]
get "/badge_achievements/award_badges", to: "badge_achievements#award"
post "/badge_achievements/award_badges", to: "badge_achievements#award_badges"
resources :broadcasts
resources :chat_channels, only: %i[index create update destroy] do
member do
delete :remove_user
end
end
resources :comments, only: [:index]
resource :config
resources :display_ads, only: %i[index edit update new create destroy]
resources :events, only: %i[index create update new edit]
resources :feedback_messages, only: %i[index show]
resources :html_variants, only: %i[index edit update new create show destroy]
resources :listings, only: %i[index edit update destroy]
resources :listing_categories, only: %i[index edit update new create
destroy], path: "listings/categories"
resources :navigation_links, only: %i[index update create destroy]
resources :organizations, only: %i[index show] do
member do
patch "update_org_credits"
end
end
resources :pages, only: %i[index new create edit update destroy]
resources :podcasts, only: %i[index edit update destroy] do
member do
post :fetch
post :add_owner
end
end
resources :mods, only: %i[index update]
resources :moderator_actions, only: %i[index]
resources :navigation_links, only: %i[index update create destroy]
resources :privileged_reactions, only: %i[index]
resources :reports, only: %i[index show], controller: "feedback_messages" do
collection do
post "send_email"
post "create_note"
post "save_status"
end
end
resources :response_templates, only: %i[index new edit create update destroy]
resources :secrets, only: %i[index]
put "secrets", to: "secrets#update"
resources :sponsorships, only: %i[index edit update new create destroy]
resources :tags, only: %i[index new create update edit] do
resource :moderator, only: %i[create destroy], module: "tags"
end
resources :tools, only: %i[index create] do
collection do
post "bust_cache"
end
end
resources :webhook_endpoints, only: :index
resources :welcome, only: %i[index create]
# We do not expose the Data Update Scripts to all Forems by default.
constraints(->(_request) { FeatureFlag.enabled?(:data_update_scripts) }) do
resources :data_update_scripts, only: %i[index show] do
member do
post :force_run
end
end
end
# NOTE: @citizen428 The next two resources have a temporary constraint
# while profile generalization is still WIP
constraints(->(_request) { FeatureFlag.enabled?(:profile_admin) }) do
resources :profile_field_groups, only: %i[update create destroy]
resources :profile_fields, only: %i[index update create destroy]
end
# @ridhwana end of routes that will be deleted once we remove the admin_restructure feature flag

View file

@ -13,7 +13,7 @@ RSpec.describe "admin sidebar", type: :request do
it "shows the correct options in the sidebar when the feature flag is enabled" do
allow(FeatureFlag).to receive(:enabled?).with(:admin_restructure).and_return(true)
get admin_content_manager_articles_path
get admin_articles_path
expect(response.body).to include("Content Manager")
end
@ -31,7 +31,7 @@ RSpec.describe "admin sidebar", type: :request do
it "shows parent level and nested child items" do
allow(FeatureFlag).to receive(:enabled?).with(:admin_restructure).and_return(true)
get admin_content_manager_articles_path
get admin_articles_path
expect(response.body).to include("Advanced")
expect(response.body).to include("Developer Tools")
@ -39,10 +39,12 @@ RSpec.describe "admin sidebar", type: :request do
end
describe "tabbed menu options" do
it "shows nested grandchildren items where applicable" do
# NOTE: [@ridhwana] to enable this test again once the
# the feature flag is removed
xit "shows nested grandchildren items where applicable" do
allow(FeatureFlag).to receive(:enabled?).with(:admin_restructure).and_return(true)
get admin_content_manager_badges_path
get admin_badges_path
expect(response.body).to include("Library")
expect(response.body).to include("Achievements")
@ -57,7 +59,7 @@ RSpec.describe "admin sidebar", type: :request do
it "does not show the option in the sidebar when the feature flag is disabled" do
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(false)
get admin_content_manager_articles_path
get admin_articles_path
expect(response.body).not_to include("Profile Fields")
end
@ -65,7 +67,7 @@ RSpec.describe "admin sidebar", type: :request do
it "shows the option in the sidebar when the feature flag is enabled" do
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
get admin_content_manager_articles_path
get admin_articles_path
expect(response.body).to include("Profile Fields")
end
@ -76,18 +78,20 @@ RSpec.describe "admin sidebar", type: :request do
allow(FeatureFlag).to receive(:enabled?).with(:admin_restructure).and_return(true)
end
it "does not show the option in the sidebar when the feature flag is disabled" do
it "does not show the option in the tabbed header when the feature flag is disabled" do
allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(false)
get admin_advanced_tools_path
get admin_tools_path
expect(response.body).not_to include("Data Update Scripts")
end
it "shows the option in the sidebar when the feature flag is enabled" do
# NOTE: [@ridhwana] to enable this test again once the
# the feature flag is removed
xit "shows the option in the tabbed header when the feature flag is enabled" do
allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(true)
get admin_advanced_tools_path
get admin_tools_path
expect(response.body).to include("Data Update Scripts")
end