diff --git a/.rubocop_fixme.yml b/.rubocop_fixme.yml index e11a79b74b..6bca83eb0a 100644 --- a/.rubocop_fixme.yml +++ b/.rubocop_fixme.yml @@ -5,6 +5,7 @@ Security/MarshalLoad: Metrics/ClassLength: Exclude: - 'app/controllers/hyrax/dashboard/collections_controller.rb' + - 'app/controllers/hyrax/admin/admin_sets_controller.rb' - 'app/controllers/hyrax/file_sets_controller.rb' - 'app/forms/hyrax/forms/permission_template_form.rb' - 'app/presenters/hyrax/work_show_presenter.rb' diff --git a/app/controllers/hyrax/admin/admin_sets_controller.rb b/app/controllers/hyrax/admin/admin_sets_controller.rb index e83f26c111..44f502ff47 100644 --- a/app/controllers/hyrax/admin/admin_sets_controller.rb +++ b/app/controllers/hyrax/admin/admin_sets_controller.rb @@ -71,7 +71,7 @@ def create def destroy if @admin_set.destroy - redirect_to hyrax.admin_admin_sets_path, notice: t(:'hyrax.admin.admin_sets.delete.notification') + after_delete_success else redirect_to hyrax.admin_admin_set_path(@admin_set), alert: @admin_set.errors.full_messages.to_sentence end @@ -140,5 +140,15 @@ def admin_set_params def repository_class blacklight_config.repository_class end + + def after_delete_success + if request.referer.include? "my/collections" + redirect_to hyrax.my_collections_path, notice: t(:'hyrax.admin.admin_sets.delete.notification') + elsif request.referer.include? "collections" + redirect_to hyrax.dashboard_collections_path, notice: t(:'hyrax.admin.admin_sets.delete.notification') + else + redirect_to hyrax.my_collections_path, notice: t(:'hyrax.admin.admin_sets.delete.notification') + end + end end end diff --git a/app/views/hyrax/my/collections/index.html.erb b/app/views/hyrax/my/collections/index.html.erb index 22a6f3ac58..fb1d34d6b4 100644 --- a/app/views/hyrax/my/collections/index.html.erb +++ b/app/views/hyrax/my/collections/index.html.erb @@ -15,7 +15,7 @@
- + <% if can?(:create_any, Collection) && @collection_type_list_presenter.any? %> <% if @collection_type_list_presenter.many? %> diff --git a/spec/controllers/hyrax/admin/admin_sets_controller_spec.rb b/spec/controllers/hyrax/admin/admin_sets_controller_spec.rb index 10f3c35601..964c0a1a80 100644 --- a/spec/controllers/hyrax/admin/admin_sets_controller_spec.rb +++ b/spec/controllers/hyrax/admin/admin_sets_controller_spec.rb @@ -148,9 +148,35 @@ context "with empty admin set" do it "deletes the admin set" do + controller.request.set_header("HTTP_REFERER", "/admin/admin_sets") delete :destroy, params: { id: admin_set } + + expect(response).to have_http_status(:found) + expect(response).to redirect_to(my_collections_path) + expect(flash[:notice]).to eq "Administrative set successfully deleted" + expect(AdminSet.exists?(admin_set.id)).to be false + end + end + + context "with empty admin set and referrer from the my/collections dashboard" do + it "deletes the admin set" do + controller.request.set_header("HTTP_REFERER", "/my/collections") + delete :destroy, params: { id: admin_set } + + expect(response).to have_http_status(:found) + expect(response).to redirect_to(my_collections_path) + expect(flash[:notice]).to eq "Administrative set successfully deleted" + expect(AdminSet.exists?(admin_set.id)).to be false + end + end + + context "with empty admin set and referrer from the /collections dashboard" do + it "deletes the admin set" do + controller.request.set_header("HTTP_REFERER", "/collections") + delete :destroy, params: { id: admin_set } + expect(response).to have_http_status(:found) - expect(response).to redirect_to(admin_admin_sets_path) + expect(response).to redirect_to(dashboard_collections_path) expect(flash[:notice]).to eq "Administrative set successfully deleted" expect(AdminSet.exists?(admin_set.id)).to be false end