to_spotlight 0.2.2 → 0.2.7

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: 4deb28ad3713576341e26dda6fe4d04c035125f8d7787afab0887344175b02d4
4
- data.tar.gz: 3481e5a52599293ab4462e5ec47bb0f80f0e9ae51e0921360c58537640f76a98
3
+ metadata.gz: 070111e1947b8dfc8761c5733c4e896f196be0e2e35a2d6705a3966fc03d0ced
4
+ data.tar.gz: 259d653332a734d74c82fcf49ec532803c39c868bf0217bcaea6a429d9c519aa
5
5
  SHA512:
6
- metadata.gz: d200aad7d3b7a82795c7629655397bc6345406246e863e98d5a3c34a7b5c7aefbc7ae337a325b13690d1888f33aa9408a78a0273e1b48a7bf94939ddca319680
7
- data.tar.gz: a3f955886e4d0d015011b7af44b19c8a1507a0c38e09fe77f9841c8673d90ca8470a1188f6128c6a100c768a124b528ff47b117186535a5d048de7e2e7f2dc00
6
+ metadata.gz: e1295991e10c234798c3b25d8260af0a5f750b1929103d5a7631b6722134c4a63bbac936f491135ff31b0ef86687e360422fcfce2330b8cf702cc17f3cab9e1d
7
+ data.tar.gz: 1758daf976e1710b890caf97524744c8643c4dd6bd8e839007fc4e69a80d05c301dc5b41c5a6867a5857a9b7b7fbad655d877781ee06e2d5a10654fcba91eadf
@@ -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', as: 'to_spotlight_index'
5
+ post '/to_spotlight/approve' => 'to_spotlight/spotlight_transfer#approve'
6
6
  end
@@ -0,0 +1,21 @@
1
+ class ToSpotlight::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
+
8
+ def inject_dashboard_link
9
+ file_path = 'app/views/hyrax/dashboard/sidebar/_tasks.html.erb'
10
+ if File.file?(file_path)
11
+ insert_into_file file_path, before: /[ \t]*<% if can\? :manage, User %>/m do
12
+ " \n<% if can? :review, :submissions %>\n" \
13
+ " <%= menu.nav_link(main_app.to_spotlight_index_path) do %>\n" \
14
+ " <span class=\"fa fa-flag\" aria-hidden=\"true\"></span> <span class=\"sidebar-action-text\"><%= t('Spotlight Transfers') %></span>\n" \
15
+ " <% end %>\n\n"
16
+ end
17
+ else
18
+ copy_file 'sidebar/_tasks.html.erb', 'app/views/hyrax/dashboard/sidebar/_tasks.html.erb'
19
+ end
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ secret_token: 'rftvgyuhwefhcgyvuryweudijxoschdufygvebhqwdijloschvugbeiofhqdijlcnhqeljcmjioeql328r9hdfec3h'
@@ -0,0 +1,41 @@
1
+ <li class="h5"><%= t('hyrax.admin.sidebar.tasks') %></li>
2
+
3
+ <% if can? :review, :submissions %>
4
+ <%= menu.nav_link(hyrax.admin_workflows_path) do %>
5
+ <span class="fa fa-flag" aria-hidden="true"></span>
6
+ <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.workflow_review') %></span>
7
+ <% end %>
8
+ <% end %>
9
+
10
+ <% if can? :review, :submissions %>
11
+ <%= menu.nav_link(main_app.to_spotlight_index_path) do %>
12
+ <span class="fa fa-flag" aria-hidden="true"></span>
13
+ <span class="sidebar-action-text"><%= t('Spotlight Transfers') %></span>
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <% if can? :manage, User %>
18
+ <%= menu.nav_link(hyrax.admin_users_path) do %>
19
+ <span class="fa fa-user" aria-hidden="true"></span>
20
+ <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.users') %></span>
21
+ <% end %>
22
+ <% end %>
23
+
24
+ <% if can? :manage, Hyku::Group %>
25
+ <%= menu.nav_link(main_app.admin_groups_path) do %>
26
+ <span class="fa fa-users"></span>
27
+ <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.manage_groups') %></span>
28
+ <% end %>
29
+ <% end %>
30
+
31
+ <% if can? :read, :admin_dashboard %>
32
+ <%= menu.nav_link(hyrax.embargoes_path) do %>
33
+ <span class="fa fa-flag" aria-hidden="true"></span>
34
+ <span class="sidebar-action-text"><%= t('hyrax.embargoes.index.manage_embargoes') %></span>
35
+ <% end %>
36
+
37
+ <%= menu.nav_link(hyrax.leases_path) do %>
38
+ <span class="fa fa-flag" aria-hidden="true"></span>
39
+ <span class="sidebar-action-text"><%= t('hyrax.leases.index.manage_leases') %></span>
40
+ <% end %>
41
+ <% end %>
@@ -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.2'.freeze
2
+ VERSION = '0.2.7'.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.2
4
+ version: 0.2.7
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-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -64,14 +64,14 @@ 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
74
+ - lib/generators/install/templates/sidebar/_tasks.html.erb
75
75
  - lib/tasks/to_spotlight_tasks.rake
76
76
  - lib/to_spotlight.rb
77
77
  - 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