Skip to content

Commit

Permalink
redirect to the appropriate page after deleting an admin set.
Browse files Browse the repository at this point in the history
  • Loading branch information
blancoj committed Nov 17, 2017
1 parent f1b3742 commit 9bbeb63
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .rubocop_fixme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 11 additions & 1 deletion app/controllers/hyrax/admin/admin_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/views/hyrax/my/collections/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="collections-wrapper">
<section class="tabs-row">
<!-- Page tabs -->
<nav><%= render 'tabs' if current_page?(hyrax.dashboard_collections_path(locale: nil)) || @managed_collection_count > 0 %></nav>
<nav><%= render 'tabs' if @managed_collection_count > 0 %></nav>

<% if can?(:create_any, Collection) && @collection_type_list_presenter.any? %>
<% if @collection_type_list_presenter.many? %>
Expand Down
28 changes: 27 additions & 1 deletion spec/controllers/hyrax/admin/admin_sets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9bbeb63

Please sign in to comment.