Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #2873 - CSRF Exception after adding to Collections/Sharing #2875

Merged
merged 3 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/hyrax.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
//= require hyrax/thumbnail_select
//= require hyrax/batch_select
//= require hyrax/tabbed_form
//= require hyrax/turbolinks_events

// this needs to be after batch_select so that the form ids get setup correctly
//= require hyrax/batch_edit
5 changes: 5 additions & 0 deletions app/assets/javascripts/hyrax/turbolinks_events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Fixes a problem with csrf tokens and turbolinks
// See https://github.com/rails/jquery-ujs/issues/456
$(document).on('turbolinks:load', function() {
$.rails.refreshCSRFTokens();
});
3 changes: 1 addition & 2 deletions app/views/hyrax/my/_collection_action_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
<li role="menuitem" tabindex="-1">
<%= link_to hyrax.edit_dashboard_collection_path(id),
class: 'itemicon itemedit',
title: t("hyrax.dashboard.my.action.edit_collection"),
data: { turbolinks: false } do %>
title: t("hyrax.dashboard.my.action.edit_collection") do %>
<%= t("hyrax.dashboard.my.action.edit_collection") %>
<% end %>
</li>
Expand Down
7 changes: 7 additions & 0 deletions spec/features/dashboard/collection_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RSpec.describe 'collection', type: :feature, clean_repo: true do
include Selectors::Dashboard

let(:user) { create(:user) }
let(:admin_user) { create(:admin) }
let(:collection_type) { create(:collection_type, creator_user: user) }
Expand Down Expand Up @@ -865,11 +867,16 @@ def get_url_fragment(type)
end

context "to true, limits available users", js: true do
let(:user2) { create(:user) }
it "to system users filted by select2" do
visit "/dashboard/collections/#{sharable_collection_id}/edit"
expect(page).to have_link('Sharing', href: '#sharing')
click_link('Sharing')
expect(page).to have_selector(".form-inline.add-users .select2-container")
select_user(user2, 'Depositor')
click_button('Save')
click_link('Sharing')
expect(page).to have_selector('td', text: user2.user_key)
end
end

Expand Down
15 changes: 15 additions & 0 deletions spec/support/selectors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ def db_item_actions_toggle(item)
find '.dropdown-toggle'
end
end

# For use with javascript user selector that allows for searching for an existing user
# and granting them permission to an object.
# @param [User] user to select
# @param [String] role granting the user permission (e.g. 'Manager' | 'Depositor' | 'Viewer')
def select_user(user, role = 'Depositor')
first('a.select2-choice').click
find('.select2-input').set(user.user_key)
sleep 1
first('div.select2-result-label').click
within('div.add-users') do
select(role)
find('input.edit-collection-add-sharing-button').click
end
end
end

module NewTransfers
Expand Down