to_spotlight 0.2.1 → 0.2.6

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: 5944a4acea93f3863a6f28ed2c50821e13ab4253f50ee66f375ddd875b960a30
4
- data.tar.gz: 1ad10835c8271e17696a5d5ce3de25d96e7d563b731a162ffda1ccbbffc88839
3
+ metadata.gz: '0396d6c1545a7b42c6bc1598868019d0ff55e8a51c423e0657cbcfc6829902bd'
4
+ data.tar.gz: 0eee8724658d6492ef2ae51f4b5ec4462555b1bf448f2f8087e9ae35d0af5603
5
5
  SHA512:
6
- metadata.gz: 2d2ebb3fabfc29cd787e25ba28a5af7b2c249de427b60a8b8a3321a99d93250fde1b350d276112c4eb962bbb36efa3df235898f2a10a48e2d1fbff4484c9f3dd
7
- data.tar.gz: 599493c82a5051da4cb70db3ab32c66b89a541f6bdca1c17d94abeb9650754a3dfb663aaae82047a3596c2cd67e14e36d80929f51fec789a28e5d84a61db76b2
6
+ metadata.gz: b74723ef303d5eaea2c5ca9953a88a88679048d1fdea86f759768b9bcf274a1c1ae35a55ca7625549767c018ff66ba18a856441ac057d2c133f52e845e885b4d
7
+ data.tar.gz: 0c41425fae0466f948a186426f732952308396fdbe572aef830a61bbffe7025c75ad1a736e30f8f3f1cdaa8ad45cbaa3464af020271f6af80052a88f50e7caeb
@@ -1,7 +1,12 @@
1
1
  module ToSpotlight
2
- class SpotlightTransferController < ActionController::Base
2
+ class SpotlightTransferController < ApplicationController
3
3
  protect_from_forgery with: :exception
4
+ before_action :authenticate_user!, except: [:api, :receive]
4
5
  skip_before_action :verify_authenticity_token, only: :receive
6
+ helper_method :default_page_title, :admin_host?, :available_translations, :available_works
7
+ include ActionView::Helpers::UrlHelper
8
+ layout 'hyrax/dashboard' if Hyrax
9
+ before_action :authenticate, except: [:index, :api, :receive]
5
10
  require 'json'
6
11
  require 'net/http'
7
12
 
@@ -20,8 +25,8 @@ module ToSpotlight
20
25
  end
21
26
 
22
27
  def receive
23
- return unless params[:token]
24
- @transfer = ToSpotlight::SpotlightTransfer.new get_transfer_attributes
28
+ return unless params[:token] == token
29
+ @transfer = ToSpotlight::SpotlightTransfer.new get_transfer_attributes
25
30
  @transfer.mappings = params[:mappings]
26
31
  if @transfer.save
27
32
  render plain: 'Transfer Request Received'
@@ -35,9 +40,9 @@ module ToSpotlight
35
40
  end
36
41
 
37
42
  def approve
38
- now = params[:commit].downcase.include?('now')
43
+ now = params[:commit].downcase.include?('now')
39
44
  transfer = ToSpotlight::SpotlightTransfer.find params[:transfer_id]
40
- works = ::ActiveFedora::Base.where member_of_collection_ids_ssim: transfer.collection_id
45
+ works = ::ActiveFedora::Base.where member_of_collection_ids_ssim: transfer.collection_id
41
46
  mappings = mapping_invert transfer.mappings
42
47
  if now
43
48
  SpotlightTransferJob.perform_later(works.to_a, mappings, transfer)
@@ -45,14 +50,18 @@ module ToSpotlight
45
50
  SpotlightTransferJob.set(wait_until: Date.today.end_of_day)
46
51
  .perform_later(works.to_a, mappings, transfer)
47
52
  end
48
-
53
+ redirect_to spotlight_transfer_index_path
49
54
  end
50
55
 
51
56
  private
52
57
 
58
+ def token
59
+ ToSpotlight::Engine.config['hyrax_instances']
60
+ end
61
+
53
62
  def mapping_invert(hash)
54
63
  result = []
55
- test = hash.map { |h| {h['hyrax'] => h['spotlight'].values} }
64
+ test = hash.map { |h| { h['hyrax'] => h['spotlight'].values } }
56
65
  test.reduce({}, :merge).map { |k, v| v.map { |val| [val, k] } }.each { |a| a.each { |a2| result << a2 } }
57
66
  Hash[result]
58
67
  end
@@ -66,31 +75,21 @@ module ToSpotlight
66
75
  end
67
76
 
68
77
  def curated_fields
69
- {"common_fields" => (work_fields - excluded_fields - field_differences), "differences" => field_differences}
78
+ {
79
+ common_fields: (work_fields - excluded_fields - field_differences),
80
+ differences: field_differences
81
+ }
70
82
  end
71
83
 
72
84
  def work_fields
73
- curated_works.map { |work| work.constantize.new.attributes.keys }.flatten.uniq
74
- #%w[id head tail depositor title date_uploaded date_modified state
75
- # proxy_depositor on_behalf_of arkivo_checksum owner alternative_title
76
- # edition geographic_coverage coordinates chronological_coverage extent
77
- # additional_physical_characteristics has_format physical_repository
78
- # collection provenance provider sponsor genre format
79
- # archival_item_identifier fonds_title fonds_creator fonds_description
80
- # fonds_identifier is_referenced_by date_digitized transcript
81
- # technical_note year label relative_path import_url creator part_of
82
- # resource_type contributor description keyword license rights_statement
83
- # publisher date_created subject language identifier based_near
84
- # related_url bibliographic_citation source access_control_id
85
- # representative_id thumbnail_id rendering_ids admin_set_id
86
- # embargo_id lease_id]
85
+ @work_fields ||= curated_works.map { |work| work.constantize.new.attributes.keys }.flatten.uniq
87
86
  end
88
87
 
89
88
  def excluded_fields
90
89
  %w[id title head tail state proxy_depositor on_behalf_of arkivo_checksum label
91
- relative_path import_url part_of resource_type access_control_id
92
- representative_id thumbnail_id rendering_ids admin_set_id embargo_id
93
- lease_id]
90
+ relative_path import_url part_of resource_type access_control_id
91
+ representative_id thumbnail_id rendering_ids admin_set_id embargo_id
92
+ lease_id]
94
93
  end
95
94
 
96
95
  def field_differences
@@ -108,7 +107,7 @@ module ToSpotlight
108
107
  end
109
108
 
110
109
  def intersect a_of_a
111
- eval a_of_a.map{|a| a.inspect}.join(' & ')
110
+ eval a_of_a.map { |a| a.inspect }.join(' & ')
112
111
  end
113
112
 
114
113
  def get_transfer_attributes
@@ -118,5 +117,24 @@ module ToSpotlight
118
117
  :spotlight_url)
119
118
  end
120
119
 
120
+ #helpers
121
+ def available_works
122
+ @available_works ||= Hyrax::QuickClassificationQuery.new(current_user).authorized_models
123
+ end
124
+
125
+ def default_page_title
126
+ 'Spotlight Transfer'
127
+ end
128
+
129
+ def admin_host?
130
+ false unless Settings.multitenancy.enabled rescue nil
131
+ end
132
+
133
+ def available_translations
134
+ {
135
+ 'en' => 'English',
136
+ 'fr' => 'French'
137
+ }
138
+ end
121
139
  end
122
140
  end
@@ -3,9 +3,9 @@ module ToSpotlight
3
3
  queue_as :default
4
4
 
5
5
  def perform(works, mappings, transfer)
6
- base_url = ::Account.where(tenant: Apartment::Tenant.current).first.cname
6
+ base_url = ::Account.where(tenant: Apartment::Tenant.current).first.cname
7
7
  csv_headers = %w[url full_title_tesim] + mappings.keys + %w[children]
8
- csv_array = [csv_headers.join(',')]
8
+ csv_array = [csv_headers.join(',')]
9
9
  #items = []
10
10
  works.each do |wk|
11
11
  #if comp
@@ -16,7 +16,7 @@ module ToSpotlight
16
16
  # next if wk.file_set_ids.length>1
17
17
  #end
18
18
  #index += 1
19
- comp = false #wk.file_set_ids.length > 1
19
+ comp = false #wk.file_set_ids.length > 1
20
20
  children = []
21
21
  if comp
22
22
  index = wk.ordered_file_set_ids.length * -1
@@ -29,8 +29,8 @@ module ToSpotlight
29
29
 
30
30
  doc = ::SolrDocument.find wk.id
31
31
 
32
- line_hash = {}
33
- line_hash['url'] = "http://#{base_url}/concern/#{underscore_name(wk)}/#{wk.id}/manifest.json" #url
32
+ line_hash = {}
33
+ line_hash['url'] = "http://#{base_url}/concern/#{underscore_name(wk)}/#{wk.id}/manifest.json" #url
34
34
  line_hash['full_title_tesim'] = (doc.title.length > 1 ? doc.title.join('; ') : doc.title.first) #full_title_tesim
35
35
 
36
36
  mappings.each do |skey, field|
@@ -39,30 +39,30 @@ module ToSpotlight
39
39
 
40
40
  line_hash['children'] = children.join('|')
41
41
 
42
- csv_array << line_hash.values_at(*csv_headers).map { |cell| cell = '' if cell.nil?; "\"#{cell.gsub("\"","\"\"")}\"" }.join(',')
42
+ csv_array << line_hash.values_at(*csv_headers).map { |cell| cell = '' if cell.nil?; "\"#{cell.gsub("\"", "\"\"")}\"" }.join(',')
43
43
 
44
44
  end
45
45
 
46
46
  dir = Rails.root.join('public', 'uploads', 'csvs')
47
47
  Dir.mkdir(dir) unless Dir.exist?(dir)
48
- time = DateTime.now.strftime('%s')
48
+ time = DateTime.now.strftime('%s')
49
49
  filename = "spotlight_export-#{time}.csv"
50
50
  File.open(dir.join(filename), 'wb') do |file|
51
51
  file.write(csv_array.join("\n"))
52
52
  end
53
53
  res = post_response URI("#{transfer.spotlight_url}/from_hyrax/receive"),
54
- csv_url: "https://#{base_url}/uploads/csvs/#{filename}",
55
- transfer: transfer.attributes.slice(:user, :exhibit), #only allow user+exhibit
56
- token: 'secret_token'
54
+ csv_url: "https://#{base_url}/uploads/csvs/#{filename}",
55
+ transfer: transfer.attributes.slice(:user, :exhibit), #only allow user+exhibit
56
+ token: 'secret_token'
57
57
 
58
58
  end
59
59
 
60
- def post_response uri, options={}
61
- http = Net::HTTP.new(uri.host, uri.port)
62
- http.use_ssl = true
60
+ def post_response uri, options = {}
61
+ http = Net::HTTP.new(uri.host, uri.port)
62
+ http.use_ssl = true
63
63
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
64
- request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
65
- request.body = options.to_json
64
+ request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
65
+ request.body = options.to_json
66
66
  http.request(request)
67
67
  end
68
68
 
@@ -9,7 +9,7 @@
9
9
  </thead>
10
10
  <tbody>
11
11
  <% transfers.each do |transfer| %>
12
- <%= render 'list_transfers', transfer: transfer %>
12
+ <%= render 'list_transfers', transfer: transfer %>
13
13
  <% end %>
14
14
  </tbody>
15
15
  </table>
@@ -7,10 +7,10 @@
7
7
  <td><%= transfer.collection_title %></td>
8
8
 
9
9
  <td>
10
- <%= form_tag to_spotlight.approve_path, method: :post, class: "form-inline" do %>
10
+ <%= form_tag main_app.to_spotlight_approve_path, method: :post, class: "form-inline" do %>
11
11
  <%= hidden_field_tag 'transfer_id', transfer.id %>
12
12
  <%= submit_tag "Run Tonight", class: 'btn btn-primary' %>
13
- <% end %><%= form_tag to_spotlight.approve_path, method: :post, class: "form-inline" do %>
13
+ <% end %><%= form_tag main_app.to_spotlight_approve_path, method: :post, class: "form-inline" do %>
14
14
  <%= hidden_field_tag 'transfer_id', transfer.id %>
15
15
  <%= submit_tag "Run Now", class: 'btn btn-primary' %>
16
16
  <% end %>
@@ -1,4 +1,4 @@
1
- <% # container for all batches in index view -%>
1
+ <% # container for all batches in index view -%>
2
2
  <div class="table-responsive" id="transfers">
3
3
  <%= render 'default_group', transfers: @transfers %>
4
4
  </div>
@@ -1,6 +1,6 @@
1
- ToSpotlight::Engine.routes.draw do
2
- get 'api/:request_type' => 'spotlight_transfer#api'
3
- post 'receive' => 'spotlight_transfer#receive'
4
- get 'index' => 'spotlight_transfer#index'
5
- post 'approve' => 'spotlight_transfer#approve'
1
+ Rails.application.routes.draw do
2
+ get '/to_spotlight/api/:request_type' => 'to_spotlight/spotlight_transfer#api', as: 'to_spotlight_api'
3
+ post '/to_spotlight/receive' => 'to_spotlight/spotlight_transfer#receive'
4
+ get '/to_spotlight' => 'to_spotlight/spotlight_transfer#index'
5
+ post '/to_spotlight/approve' => 'to_spotlight/spotlight_transfer#approve'
6
6
  end
@@ -0,0 +1,7 @@
1
+ class CdmMigrator::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def inject_content_dm_yml
5
+ copy_file('config/to_spotlight.yml', 'config/to_spotlight.yml') unless File.file?('config/to_spotlight.yml')
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ secret_token: 'rftvgyuhwefhcgyvuryweudijxoschdufygvebhqwdijloschvugbeiofhqdijlcnhqeljcmjioeql328r9hdfec3h'
@@ -3,10 +3,26 @@ module ToSpotlight
3
3
  isolate_namespace ToSpotlight
4
4
  initializer :append_migrations do |app|
5
5
  unless app.root.to_s.match root.to_s
6
- config.paths["db/migrate"].expanded.each do |expanded_path|
7
- app.config.paths["db/migrate"] << expanded_path
6
+ config.paths['db/migrate'].expanded.each do |expanded_path|
7
+ app.config.paths['db/migrate'] << expanded_path
8
8
  end
9
9
  end
10
10
  end
11
+
12
+ class << self
13
+
14
+ def config
15
+ file = File.open(File.join(::Rails.root, '/config/from_hyrax.yml'))
16
+ @config ||= YAML.safe_load(file)
17
+ end
18
+
19
+ # loads a yml file with the configuration options
20
+ #
21
+ # @param file [String] path to the yml file
22
+ #
23
+ def load_config(file)
24
+ @config = YAML.load_file(file)
25
+ end
26
+ end
11
27
  end
12
28
  end
@@ -1,3 +1,3 @@
1
1
  module ToSpotlight
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_spotlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.6
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-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -64,14 +64,13 @@ files:
64
64
  - app/views/to_spotlight/spotlight_transfer/_default_group.html.erb
65
65
  - app/views/to_spotlight/spotlight_transfer/_list_transfers.html.erb
66
66
  - app/views/to_spotlight/spotlight_transfer/_select.html.erb
67
- - app/views/to_spotlight/spotlight_transfer/_tabs.html.erb
68
67
  - app/views/to_spotlight/spotlight_transfer/_transfers_list.html.erb
69
- - app/views/to_spotlight/spotlight_transfer/approve.html.erb
70
68
  - app/views/to_spotlight/spotlight_transfer/index.html.erb
71
69
  - app/views/to_spotlight/spotlight_transfer/receive.html.erb
72
- - config/application.rb
73
70
  - config/routes.rb
74
71
  - db/migrate/20200310153953_create_to_spotlight_spotlight_transfers.rb
72
+ - lib/generators/install/install_generator.rb
73
+ - lib/generators/install/templates/config/to_spotlight.yml
75
74
  - lib/tasks/to_spotlight_tasks.rake
76
75
  - lib/to_spotlight.rb
77
76
  - lib/to_spotlight/engine.rb
@@ -1,5 +0,0 @@
1
- <ul class="nav nav-tabs" id="my_nav" role="navigation">
2
- <li<%= ' class="active"'.html_safe %>>
3
- <%= link_to "All CSV Batches", to_spotlight.index_path %>
4
- </li>
5
- </ul>
@@ -1,7 +0,0 @@
1
- <h1>ToSpotlight#approve</h1>
2
- <p>Find me in app/views/to_spotlight/to_spotlight/approve.html.erb</p>
3
- <%= params.inspect %>
4
-
5
- <br/>
6
-
7
- <%#= @res.body %>
@@ -1,10 +0,0 @@
1
- module ToSpotlight
2
- class Application < Rails::Application
3
- config.middleware.insert_before 0, Rack::Cors do
4
- allow do
5
- origins '*'
6
- resource '/to_spotlight/api/*', headers: :any, methods: %i[get post options]
7
- end
8
- end
9
- end
10
- end