From a9c71b51986dc8f7842e124d0ad3ce002a456e8b Mon Sep 17 00:00:00 2001 From: James Pino Date: Thu, 16 Mar 2017 13:15:18 -0400 Subject: [PATCH 01/14] MMT-717: Updates set_provider to return user to page they were on instead of to the manage metadata page. Former-commit-id: e2bae274041b9e5c01195fcd5a71f4b67262fd7a --- app/controllers/users_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 41804a247..fcb072020 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -25,8 +25,10 @@ def set_provider set_provider_context_token + session[:return_to] = request.referer + respond_to do |format| - format.html { redirect_to manage_metadata_path } + format.html { redirect_to session[:return_to] } format.json { render json: nil, status: :ok } end end From 417b5265760ae9073fb8d14e6066ad82ec6f2a40 Mon Sep 17 00:00:00 2001 From: James Pino Date: Wed, 22 Mar 2017 23:02:10 -0400 Subject: [PATCH 02/14] MMT-717: Adding helper that encapsulates redirect map and logic when changing providers. Former-commit-id: 6dd3f3096dffb76eeded7343c656c1f46a01205d --- app/controllers/users_controller.rb | 3 +- app/helpers/set_provider_helper.rb | 81 +++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 app/helpers/set_provider_helper.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fcb072020..3e94d518e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + include SetProviderHelper skip_before_filter :is_logged_in, except: [:set_provider, :refresh_providers] skip_before_filter :setup_query @@ -25,7 +26,7 @@ def set_provider set_provider_context_token - session[:return_to] = request.referer + session[:return_to] = get_redirect_route(request.referer) respond_to do |format| format.html { redirect_to session[:return_to] } diff --git a/app/helpers/set_provider_helper.rb b/app/helpers/set_provider_helper.rb new file mode 100644 index 000000000..a3cc5ade4 --- /dev/null +++ b/app/helpers/set_provider_helper.rb @@ -0,0 +1,81 @@ +# :nodoc: +module SetProviderHelper + + routes = Rails.application.routes.url_helpers + + # This map contains routes and route patterns and how they should + # be redirected when the user switches providers. + # + # For example, on the Groups page, if the user is editing, creating, + # or viewing a group, they will be redirected to the "index" page for groups. + RedirectMap = { + # Groups + '/groups/*/edit' => routes.groups_path, + '/groups/*' => routes.groups_path, + + # Orders + '/orders/*' => routes.orders_path, + + # Provider holdings + '/provider_holdings/*' => routes.provider_holdings_path, + + # Collections + '/collections/*' => routes.manage_metadata_path, + + # Order Options + '/order_options/*' => routes.order_options_path, + '/order_options/*/edit' => routes.order_options_path, + + # Order option assignments + '/order_option_assignments/*' => routes.order_option_assignments_path, + '/order_option_assignments/*/edit' => routes.order_option_assignments_path, + + # Order Policies + '/order_policies/edit' => routes.order_policies_path, + '/order_policies/*/edit' => routes.order_policies_path, + + # Permissions + '/permissions/*/edit' => routes.permissions_path, + '/permissions/*' => routes.permissions_path, + + # DQS + '/data_quality_summaries/*/edit' => routes.data_quality_summaries_path, + '/data_quality_summaries/*' => routes.data_quality_summaries_path, + + # DQS Assignments + '/data_quality_summary_assignments/*/edit' => routes.data_quality_summary_assignments_path, + '/data_quality_summary_assignments/*' => routes.data_quality_summary_assignments_path, + + # Service entries + '/service_entries/*/edit' => routes.service_entries_path, + '/service_entries/*' => routes.service_entries_path, + + # Service options + '/service_options/*/edit' => routes.service_options_path, + '/service_options/*' => routes.service_options_path, + + # Service option assignments + '/service_option_assignments/*/edit' => routes.service_option_assignments_path, + '/service_option_assignments/*' => routes.service_option_assignments_path, + + # Drafts + '/drafts/*' => routes.manage_metadata_path + } + + def get_redirect_route(original_route) + # Parse out the path + curr_route = URI::parse(original_route).path + + # Make some regex substitutions so that we can match routes in the map. + # Examples: + # /service_entries/12ADD5EB-9213-1FD1-A03E-519C07C2A9B1 ---> service_entries/* + # /order_options/34920B0B-24B2-E534-32A4-4E6F71857937/edit ---> order_options/*/edit + + curr_route.sub!(/\/(\w+)\/.+?\/edit/, "/\\1/*/edit") + curr_route.sub!(/\/(\w+)\/.+/, "/\\1/*") + curr_route.sub!(/\/drafts\/.+/, '/drafts/*') + + SetProviderHelper::RedirectMap.fetch(curr_route, original_route) + end + +end From f934e620b4c2dd0ee847b315c07753f0259f9733 Mon Sep 17 00:00:00 2001 From: James Pino Date: Thu, 23 Mar 2017 11:37:52 -0400 Subject: [PATCH 03/14] MMT-717: Changing logic to redirect to the "index" action of the original controller instead of using a map. Former-commit-id: 7329281ac567b194ef4d36d67911bc77dbb4a14e --- app/controllers/users_controller.rb | 15 +++++- app/helpers/set_provider_helper.rb | 81 ----------------------------- 2 files changed, 14 insertions(+), 82 deletions(-) delete mode 100644 app/helpers/set_provider_helper.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3e94d518e..50450ab22 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -26,7 +26,20 @@ def set_provider set_provider_context_token - session[:return_to] = get_redirect_route(request.referer) + # Add any controller names we want to exclude here. For anything in this list, + # the user will be redirected to the Manage Metadata page + route_exceptions = %w(pages) + + # Get the controller name from the original path + controller_name = Rails.application.routes.recognize_path(request.referer)[:controller] + + # Return the user to the "index" action of the original controller they were on, + # unless it's in the exception list. + if route_exceptions.include?(controller_name) + session[:return_to] = manage_metadata_path + else + session[:return_to] = '/' + controller_name + end respond_to do |format| format.html { redirect_to session[:return_to] } diff --git a/app/helpers/set_provider_helper.rb b/app/helpers/set_provider_helper.rb deleted file mode 100644 index a3cc5ade4..000000000 --- a/app/helpers/set_provider_helper.rb +++ /dev/null @@ -1,81 +0,0 @@ -# :nodoc: -module SetProviderHelper - - routes = Rails.application.routes.url_helpers - - # This map contains routes and route patterns and how they should - # be redirected when the user switches providers. - # - # For example, on the Groups page, if the user is editing, creating, - # or viewing a group, they will be redirected to the "index" page for groups. - RedirectMap = { - # Groups - '/groups/*/edit' => routes.groups_path, - '/groups/*' => routes.groups_path, - - # Orders - '/orders/*' => routes.orders_path, - - # Provider holdings - '/provider_holdings/*' => routes.provider_holdings_path, - - # Collections - '/collections/*' => routes.manage_metadata_path, - - # Order Options - '/order_options/*' => routes.order_options_path, - '/order_options/*/edit' => routes.order_options_path, - - # Order option assignments - '/order_option_assignments/*' => routes.order_option_assignments_path, - '/order_option_assignments/*/edit' => routes.order_option_assignments_path, - - # Order Policies - '/order_policies/edit' => routes.order_policies_path, - '/order_policies/*/edit' => routes.order_policies_path, - - # Permissions - '/permissions/*/edit' => routes.permissions_path, - '/permissions/*' => routes.permissions_path, - - # DQS - '/data_quality_summaries/*/edit' => routes.data_quality_summaries_path, - '/data_quality_summaries/*' => routes.data_quality_summaries_path, - - # DQS Assignments - '/data_quality_summary_assignments/*/edit' => routes.data_quality_summary_assignments_path, - '/data_quality_summary_assignments/*' => routes.data_quality_summary_assignments_path, - - # Service entries - '/service_entries/*/edit' => routes.service_entries_path, - '/service_entries/*' => routes.service_entries_path, - - # Service options - '/service_options/*/edit' => routes.service_options_path, - '/service_options/*' => routes.service_options_path, - - # Service option assignments - '/service_option_assignments/*/edit' => routes.service_option_assignments_path, - '/service_option_assignments/*' => routes.service_option_assignments_path, - - # Drafts - '/drafts/*' => routes.manage_metadata_path - } - - def get_redirect_route(original_route) - # Parse out the path - curr_route = URI::parse(original_route).path - - # Make some regex substitutions so that we can match routes in the map. - # Examples: - # /service_entries/12ADD5EB-9213-1FD1-A03E-519C07C2A9B1 ---> service_entries/* - # /order_options/34920B0B-24B2-E534-32A4-4E6F71857937/edit ---> order_options/*/edit - - curr_route.sub!(/\/(\w+)\/.+?\/edit/, "/\\1/*/edit") - curr_route.sub!(/\/(\w+)\/.+/, "/\\1/*") - curr_route.sub!(/\/drafts\/.+/, '/drafts/*') - - SetProviderHelper::RedirectMap.fetch(curr_route, original_route) - end - -end From 3e82fdd31ecc2f0386f968bfb112865be08f22ac Mon Sep 17 00:00:00 2001 From: James Pino Date: Thu, 23 Mar 2017 11:40:54 -0400 Subject: [PATCH 04/14] MMT-717: Removes include for SetProviderHelper Former-commit-id: dd19a186448f6ed568d186012d912ad359e2b739 --- app/controllers/users_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 50450ab22..9ec0d98c3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,4 @@ class UsersController < ApplicationController - include SetProviderHelper skip_before_filter :is_logged_in, except: [:set_provider, :refresh_providers] skip_before_filter :setup_query From 89cc16f82323ab531537281c967d4bc761ad2374 Mon Sep 17 00:00:00 2001 From: James Pino Date: Thu, 23 Mar 2017 14:45:09 -0400 Subject: [PATCH 05/14] MMT-717: Placing revised redirect logic into a new concern. Former-commit-id: 848eef1448972f1af79c545863fa349f79f6fe1c --- app/concerns/redirector.rb | 22 ++++++++++++++++++++++ app/controllers/users_controller.rb | 18 ++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 app/concerns/redirector.rb diff --git a/app/concerns/redirector.rb b/app/concerns/redirector.rb new file mode 100644 index 000000000..438ae042f --- /dev/null +++ b/app/concerns/redirector.rb @@ -0,0 +1,22 @@ +module Redirector + extend ActiveSupport::Concern + + routes = Rails.application.routes.url_helpers + + # Add any controller names we want to exclude here. For anything in this map, + # the user will be redirected to the Manage Metadata page + ROUTE_EXCEPTIONS = { + 'pages' => routes.manage_metadata_path, + 'provider_orders' => routes.orders_path + } + + def get_redirect_route(original_route) + # Get the controller name from the original path + controller_name = Rails.application.routes.recognize_path(original_route)[:controller] + + # Return the user to the "index" action of the original controller they were on, + # unless it's in the exception list. + ROUTE_EXCEPTIONS.include?(controller_name) ? ROUTE_EXCEPTIONS[controller_name] : url_for(action: 'index', controller: controller_name) + end + +end \ No newline at end of file diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 9ec0d98c3..39921c0b2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + include Redirector skip_before_filter :is_logged_in, except: [:set_provider, :refresh_providers] skip_before_filter :setup_query @@ -25,23 +26,8 @@ def set_provider set_provider_context_token - # Add any controller names we want to exclude here. For anything in this list, - # the user will be redirected to the Manage Metadata page - route_exceptions = %w(pages) - - # Get the controller name from the original path - controller_name = Rails.application.routes.recognize_path(request.referer)[:controller] - - # Return the user to the "index" action of the original controller they were on, - # unless it's in the exception list. - if route_exceptions.include?(controller_name) - session[:return_to] = manage_metadata_path - else - session[:return_to] = '/' + controller_name - end - respond_to do |format| - format.html { redirect_to session[:return_to] } + format.html { redirect_to get_redirect_route(request.referer) } format.json { render json: nil, status: :ok } end end From 63b254760a6ea9d0fbaf270807cfd29152fa3e22 Mon Sep 17 00:00:00 2001 From: James Pino Date: Thu, 23 Mar 2017 15:53:56 -0400 Subject: [PATCH 06/14] MMT-717: Clarifying comment about the exception list. Former-commit-id: a472fe73770a56cb9b6a17dda5f8868a0f9ef7be --- app/concerns/redirector.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/concerns/redirector.rb b/app/concerns/redirector.rb index 438ae042f..c1c89fc1a 100644 --- a/app/concerns/redirector.rb +++ b/app/concerns/redirector.rb @@ -3,8 +3,9 @@ module Redirector routes = Rails.application.routes.url_helpers - # Add any controller names we want to exclude here. For anything in this map, - # the user will be redirected to the Manage Metadata page + # Add any redirects we want to customize here, e.g., if the "index" action + # for a given path is "/provider_orders", we will redirect to the '/orders' + # path. ROUTE_EXCEPTIONS = { 'pages' => routes.manage_metadata_path, 'provider_orders' => routes.orders_path From d1140ee39129c7e3237cbc5f153ec51913aa1bf6 Mon Sep 17 00:00:00 2001 From: James Pino Date: Fri, 24 Mar 2017 18:20:57 -0400 Subject: [PATCH 07/14] MMT-717: Clarifying comment about the exception list. Former-commit-id: 74eff0743d270e1b15f3bec35f08d31bdbcbbe7d --- .../change_current_provider.coffee | 19 +++++++++++++++++++ app/views/shared/_header.html.erb | 3 ++- spec/fixtures/providers.json | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/providers.json diff --git a/app/assets/javascripts/change_current_provider.coffee b/app/assets/javascripts/change_current_provider.coffee index dc21d5874..e0b0c6814 100644 --- a/app/assets/javascripts/change_current_provider.coffee +++ b/app/assets/javascripts/change_current_provider.coffee @@ -68,3 +68,22 @@ $(document).ready -> dataType: 'json' success: (data, status, xhr) -> $("##{actionLink}")[0].click() + + + $('#refresh_available_providers_link').on 'click', (element) -> + $.ajax( + url: '/refresh_providers' + method: 'get' + dataType: 'json' + ).done( (response) -> + $('#select_provider').empty() + $('#select_provider').append( $('