from_hyrax 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c736fd68cb6c5cef649ccb26e41b19fb14587745f94b5ed2454296910dddcf5f
4
- data.tar.gz: ba1bb7bc6b22fcc69d7faa71e6c7164ab2994fec1c35f4cccffa754995982f4b
3
+ metadata.gz: d58d64b8fd9446a26bfcbd58655dd7ad39b03a853707b13b09fd30d2a594f40b
4
+ data.tar.gz: 3d69d08df378a7036390d75101e426db526a74a0a4c7e7760d6dbf9c43b93a75
5
5
  SHA512:
6
- metadata.gz: 836454272b9ca901b90b1b6b67b698552c75e2e2c06ec6b3e71fb4b9b18e36bf8137228671aa5744ed83760333a9a99bfe03cd7fc04982e11468472dc196f237
7
- data.tar.gz: cd6a1ac826bf00f94f92cd70328ef80ff9ad1e8478c38506eeb7d815ddb32cfb69f91c77cffaad016caaf567a2c06f16b3c32bd86e824e1a4931979c28af71b3
6
+ metadata.gz: 520a52ddb299bb2b2307afdae1b7136d0fabdfaaa586885f7136100dbbc68655440d58782201c037de654394e898686bc798110622419fd3a0462ebe87d7b921
7
+ data.tar.gz: 4848021ff6d5e005077f38f283195714d570d1772e169c5fbd9eccff3a30aa8fe8915eeabe1ce7c1a545207edcf3b4af57ab6822ece55d0029425181cb343ddf
@@ -1,7 +1,9 @@
1
1
  class FromHyraxController < ActionController::Base
2
2
  layout 'from_hyrax/application'
3
+ before_action :authenticate_user!
3
4
  protect_from_forgery with: :exception
4
5
  skip_before_action :verify_authenticity_token, only: :receive
6
+ load_and_authorize_resource :current_exhibit, class: Spotlight::Exhibit
5
7
  require 'net/http'
6
8
 
7
9
  def hyrax_api
@@ -23,20 +25,15 @@ class FromHyraxController < ActionController::Base
23
25
  end
24
26
 
25
27
  def create
28
+ return unless instances.include? params[:repo]
26
29
  # go to: to_spotlight/receive
27
- # use Spotlight::Engine.config.upload_fields to get spotlight fields list
28
- # map {|f| [f.label, f.field_name]}
29
30
  @mappings = params[:transfer][:mappings].permit!.to_h.map { |_, v| v unless v['spotlight']['0'].empty? }.compact #use hash.values
30
- #@res = Net::HTTP.post URI("http://#{params[:repo]}/to_spotlight/receive"),
31
- # { transfer: params[:transfer],
32
- # mappings: @mappings,
33
- # token: 'secret_token' }.to_json,
34
- # 'Content-Type' => 'application/json'
35
- post_options = { transfer: params[:transfer], mappings: @mappings, token: 'secret_token' }
31
+ post_options = { transfer: params[:transfer], mappings: @mappings, token: token }
36
32
  @res = post_response URI("#{params[:repo]}/to_spotlight/receive"), post_options
37
33
  end
38
34
 
39
35
  def receive
36
+ return unless params[:token] == token
40
37
  FromHyrax::RunImportJob.perform_later(params[:csv_url], csv_params)
41
38
  end
42
39
 
@@ -72,6 +69,8 @@ class FromHyraxController < ActionController::Base
72
69
  end
73
70
 
74
71
  def spotlight_fields
72
+ # use Spotlight::Engine.config.upload_fields to get spotlight fields list
73
+ # map {|f| [f.label, f.field_name]}
75
74
  [
76
75
  { label: 'Description', field_name: 'spotlight_upload_dc_description_tesim' },
77
76
  { label: 'Abstract', field_name: 'spotlight_upload_dc_Subject_tesim' },
@@ -3,21 +3,19 @@ module FromHyrax
3
3
  queue_as :default
4
4
 
5
5
  def perform(csv_url, csv_params)
6
- csv = CSV.parse(csv_io_param(csv_url), headers: true, return_headers: false).map(&:to_hash)
7
- exhibit = ::Exhibit.find(csv_params[:exhibit_id])
8
- user = ::User.find(csv_params[:user])
6
+ Rails.logger.warn "Import Job #{csv_url}, params: #{csv_params.inspect}"
7
+ csv = CSV.parse(get_response(URI(csv_url)).body, headers: true, return_headers: false).map(&:to_hash)
8
+ exhibit = ::Spotlight::Exhibit.find(csv_params[:exhibit_id])
9
+ user = ::User.find(csv_params[:user])
9
10
  Spotlight::AddUploadsFromCSV.perform_later(csv, exhibit, user)
10
11
  end
11
12
 
12
- def csv_io_param url
13
- file_or_io = url
14
- io = if file_or_io.respond_to?(:to_io)
15
- file_or_io.to_io
16
- else
17
- file_or_io
18
- end
19
-
20
- io.set_encoding('utf-8')
13
+ def get_response uri
14
+ http = Net::HTTP.new(uri.host, uri.port)
15
+ http.use_ssl = true
16
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
17
+ request = Net::HTTP::Get.new(uri.request_uri)
18
+ http.request(request)
21
19
  end
22
20
  end
23
- end
21
+ end
@@ -1,9 +1,8 @@
1
- <h1>FromHyrax::FromHyrax#index</h1>
2
- <p>Find me in app/views/from_hyrax/from_hyrax/index.html.erb</p>
3
-
4
-
5
- <%= form_tag from_hyrax.new_path do %>
6
- <%= select_tag "repo", options_for_select(@instances), {include_blank: true, onchange: 'get_next(this)'} %>
7
- <div id="collections_div"></div>
8
- <%= submit_tag 'start mapping'%>
9
- <% end %>
1
+ <%= render 'spotlight/shared/exhibit_sidebar' %>
2
+ <div id="content" class="col-md-9">
3
+ <%= form_tag from_hyrax.new_path do %>
4
+ <%= select_tag "repo", options_for_select(@instances), {include_blank: true, onchange: 'get_next(this)'} %>
5
+ <div id="collections_div"></div>
6
+ <%= submit_tag 'start mapping' %>
7
+ <% end %>
8
+ </div>
@@ -1,34 +1,32 @@
1
- <h1>FromHyrax::FromHyrax#new</h1>
2
- <p>Find me in app/views/from_hyrax/from_hyrax/new.html.erb</p>
3
-
1
+ <%= render 'spotlight/shared/exhibit_sidebar' %>
4
2
  <style type="text/css" media="screen">
5
3
 
6
- table{
7
- border-collapse:collapse;
8
- border:1px solid black;
4
+ table {
5
+ border-collapse: collapse;
6
+ border: 1px solid black;
9
7
  }
10
8
 
11
- table td{
12
- border:1px solid black;
9
+ table td {
10
+ border: 1px solid black;
13
11
  }
14
12
  </style>
13
+ <div id="content" class="col-md-9">
14
+ <h1><%= "Map from #{params[:repo]}" %></h1>
15
15
 
16
- <h1><%= "Map from #{params[:repo]}" %></h1>
17
-
18
- <%= params.inspect %>
19
-
20
- <%= form_tag from_hyrax.create_path do %>
16
+ <%= params.inspect %>
21
17
 
22
- <%#= select_tag "admin_set", options_for_select(@admin_sets), include_blank: true %>
18
+ <%= form_tag from_hyrax.create_path do %>
23
19
 
24
- <table>
25
- <%= render 'rows' %>
20
+ <%#= select_tag "admin_set", options_for_select(@admin_sets), include_blank: true %>
26
21
  <%= hidden_field_tag "repo", params[:repo] %>
27
- <%= hidden_field_tag "transfer[user]", "current_user" %>
28
- <%= hidden_field_tag "transfer[exhibit_id]", "17" %>
22
+ <%= hidden_field_tag "transfer[user]", current_user %>
23
+ <%= hidden_field_tag "transfer[exhibit_id]", @current_exhibit.id %>
29
24
  <%= hidden_field_tag "transfer[collection_id]", params[:collection] %>
30
25
  <%= hidden_field_tag "transfer[spotlight_url]", request.base_url %>
31
- </table>
32
- <%= submit_tag 'request import'%>
33
- <% end %>
34
26
 
27
+ <table>
28
+ <%= render 'rows' %>
29
+ </table>
30
+ <%= submit_tag 'request import' %>
31
+ <% end %>
32
+ </div>
@@ -1,3 +1,3 @@
1
1
  module FromHyrax
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.2.4'.freeze
3
3
  end
@@ -2,6 +2,6 @@ class CdmMigrator::InstallGenerator < Rails::Generators::Base
2
2
  source_root File.expand_path('../templates', __FILE__)
3
3
 
4
4
  def inject_content_dm_yml
5
- copy_file("config/from_hyrax.yml", "config/from_hyrax.yml") unless File.file?("config/from_hyrax.yml")
5
+ copy_file('config/from_hyrax.yml', 'config/from_hyrax.yml') unless File.file?('config/from_hyrax.yml')
6
6
  end
7
7
  end
@@ -1,2 +1,3 @@
1
1
  hyrax_instances:
2
2
  - 'https://hyrax.institution.com'
3
+ secret_token: 'rftvgyuhwefhcgyvuryweudijxoschdufygvebhqwdijloschvugbeiofhqdijlcnhqeljcmjioeql328r9hdfec3h'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: from_hyrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sephirothkod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-04 00:00:00.000000000 Z
11
+ date: 2020-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails