zizia 5.3.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fdda0863d2774964998749599636d9f063f890c02c6458741c617669d54ee35
4
- data.tar.gz: a354eba60184b5c0c8e855eff44a8175072078373df2ddf77830fa9b200b1c60
3
+ metadata.gz: 1cab6751bf520d34f829ac16a01910b30faaf202b30b8f8d7edd0202c9b688a0
4
+ data.tar.gz: a756533e194b8fd985124e0025ba9361732f54afd1aa7386aaa70ccfe588e776
5
5
  SHA512:
6
- metadata.gz: 29b861f2b65d2c96c9479ab62476ea6c9d660f26dc8ddf37422d06fd53cf6d65ed15ea01bb52c017d4be3af8f99c8a23fc0e1d91b5d3fb1a53187280f674fb20
7
- data.tar.gz: 2e5143ea56f9a584f2a3e8ac7fc4f4ba4dd38c7514678e9a149371fb474b03e494617fa7638b95e011c4c05f94864405e623ba133d5d960da71d6686eb472702
6
+ metadata.gz: 86e73e33ab8e20c03dda68e7cc5d9a5cf537c019a5896015f9da018b2cdc973303fe36eea24b5f7c863f37530bfd1aeb420cda92c6006923d8db90e4bce08275
7
+ data.tar.gz: 8437e79567466450c2645ba85c69296f0436562b05d489c3e27c186aa0f24f9d7d98894225f830601cbee02507d20c2256662b5c369f305abb30b20ed9fd5a58
data/.rubocop.yml CHANGED
@@ -62,6 +62,7 @@ RSpec/DescribeClass:
62
62
 
63
63
  RSpec/ExampleLength:
64
64
  Exclude:
65
+ - 'spec/controllers/pre_ingest_works_controller_spec.rb'
65
66
  - 'spec/zizia/hyrax/hyrax_basic_metadata_mapper_spec.rb'
66
67
  - 'spec/integration/import_hyrax_csv.rb'
67
68
  - 'spec/integration/csv_import_detail_spec.rb'
data/CHANGELOG.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## [5.1.0](https://github.com/curationexperts/zizia/tree/5.1.0) (2019-11-11)
3
+ ## [5.1.0](https://github.com/curationexperts/zizia/tree/5.1.0) (2019-11-14)
4
4
 
5
- [Full Changelog](https://github.com/curationexperts/zizia/compare/v5.2.0...5.1.0)
5
+ [Full Changelog](https://github.com/curationexperts/zizia/compare/v5.3.0...5.1.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Basic file status [\#65](https://github.com/curationexperts/zizia/pull/65) ([little9](https://github.com/little9))
10
+
11
+ ## [v5.3.0](https://github.com/curationexperts/zizia/tree/v5.3.0) (2019-11-11)
12
+
13
+ [Full Changelog](https://github.com/curationexperts/zizia/compare/v5.2.0...v5.3.0)
6
14
 
7
15
  **Merged pull requests:**
8
16
 
@@ -1,6 +1,48 @@
1
1
  var Zizia = {
2
- displayUploadedFile: function() {
2
+ displayUploadedFile: function () {
3
3
  var DisplayUploadedFile = require('zizia/DisplayUploadedFile')
4
4
  new DisplayUploadedFile().display()
5
+ },
6
+ checkStatuses: function (options) {
7
+ var results = []
8
+ // Go through the list of thumbnails for the work based
9
+ // on the deduplicationKey
10
+ options.thumbnails.forEach(function (thumbnail) {
11
+ $.ajax({
12
+ type: 'HEAD',
13
+ url: thumbnail,
14
+ complete: function (xhr) {
15
+ // Request only the headers from the thumbnail url
16
+ // push the statuses into an array
17
+ results.push(xhr.getResponseHeader('status'))
18
+ // See how many urls are not returning 200
19
+ var missingThumbnailCount = results.filter(
20
+ function (status) {
21
+ if (status !== '200 OK') { return true }
22
+ }).length
23
+ // If there are any not returning 200, the work is still being processed
24
+ if (missingThumbnailCount > 0) {
25
+
26
+ } else {
27
+ Zizia.addSuccessClasses(options)
28
+ }
29
+ }
30
+ })
31
+ })
32
+ },
33
+ displayWorkStatus: function () {
34
+ $('[id^=work-status]').each(function () {
35
+ var deduplicationKey = $(this)[0].id.split('work-status-')[1]
36
+ $.get('/pre_ingest_works/thumbnails/' + deduplicationKey, function (data) {
37
+ data.deduplicationKey = deduplicationKey
38
+ Zizia.checkStatuses(data)
39
+ })
40
+ })
41
+ },
42
+ addSuccessClasses: function (options) {
43
+ $('#work-status-' + options.deduplicationKey + ' > span').removeClass('status-unknown')
44
+ $('#work-status-' + options.deduplicationKey + ' > span').removeClass('glyphicon-question-sign')
45
+ $('#work-status-' + options.deduplicationKey + ' > span').addClass('text-success')
46
+ $('#work-status-' + options.deduplicationKey + ' > span').addClass('glyphicon-ok-sign')
5
47
  }
6
48
  }
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Zizia
4
+ class PreIngestWorksController < ::ApplicationController
5
+ before_action :merge_abilities
6
+ load_and_authorize_resource
7
+
8
+ def thumbnails
9
+ pre_ingest_work = Zizia::PreIngestWork.where(deduplication_key: pre_ingest_works_params[:deduplication_key]).first
10
+
11
+ @thumbnails = if pre_ingest_work
12
+ pre_ingest_work.thumbnails
13
+ else
14
+ []
15
+ end
16
+
17
+ respond_to do |format|
18
+ format.json { render json: { thumbnails: @thumbnails } }
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def pre_ingest_works_params
25
+ params.permit(:deduplication_key, :format)
26
+ end
27
+
28
+ def merge_abilities
29
+ current_ability.merge(Zizia::Ability.new(current_user))
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module Zizia
3
+ class Ability
4
+ include Hydra::Ability
5
+ include Hyrax::Ability
6
+ self.ability_logic += [:everyone_can_create_curation_concerns]
7
+
8
+ # Define any customized permissions here.
9
+ def custom_permissions
10
+ can :manage, Zizia::CsvImport if current_user.admin?
11
+ can :manage, Zizia::CsvImportDetail if current_user.admin?
12
+ can :manage, Zizia::PreIngestWork if current_user.admin?
13
+ end
14
+ end
15
+ end
@@ -9,10 +9,6 @@ module Zizia
9
9
  has_many :pre_ingest_works
10
10
  has_many :pre_ingest_files, through: :pre_ingest_works
11
11
 
12
- def status
13
- 'undetermined'
14
- end
15
-
16
12
  def total_size
17
13
  return 0 if pre_ingest_files.empty?
18
14
  pre_ingest_files.map(&:size).sum
@@ -12,5 +12,20 @@ module Zizia
12
12
  return solr_title unless solr_title.nil?
13
13
  'This work\'s metadata has not been indexed yet.'
14
14
  end
15
+
16
+ # Returns thumbnail urls based on the work's deduplication_key
17
+ # @return [Array<String>] the work's thumbnail urls
18
+ def thumbnails
19
+ thumbnail_urls = []
20
+ return thumbnail_urls if deduplication_key.nil?
21
+ file_sets = ActiveFedora::SolrService.get("deduplication_key_tesim:#{deduplication_key}")
22
+ .dig('response', 'docs', 0, 'file_set_ids_ssim')
23
+ return thumbnail_urls unless file_sets
24
+ file_sets.each do |file_set_id|
25
+ thumbnail_urls.push(ActiveFedora::SolrService.get("id:#{file_set_id}")
26
+ .dig('response', 'docs', 0, 'thumbnail_path_ss'))
27
+ end
28
+ thumbnail_urls
29
+ end
15
30
  end
16
31
  end
@@ -9,7 +9,6 @@
9
9
  <th>Number of Works</th>
10
10
  <th>Number of Files</th>
11
11
  <th>Total Size</th>
12
- <th>Status</th>
13
12
  <th>Overwrite Behavior Type</th>
14
13
  </tr>
15
14
  <% @csv_import_details.each do |csv_import_detail| %>
@@ -35,9 +34,6 @@
35
34
  <td>
36
35
  <%= number_to_human_size(csv_import_detail.total_size) %>
37
36
  </td>
38
- <td>
39
- <%= csv_import_detail.status %>
40
- </td>
41
37
  <td>
42
38
  <%= human_update_actor_stack(csv_import_detail.update_actor_stack) %>
43
39
  </td>
@@ -15,6 +15,7 @@
15
15
  <th>Title</th>
16
16
  <th>Files</th>
17
17
  <th>Date</th>
18
+ <th>Status</th>
18
19
  </tr>
19
20
  <% @pre_ingest_works.each do |pre_ingest_work| %>
20
21
  <tr>
@@ -30,8 +31,16 @@
30
31
  <td>
31
32
  <%= pre_ingest_work.created_at.strftime("%B %-d, %Y %H:%M") %>
32
33
  </td>
34
+ <td id="<%= "work-status-#{pre_ingest_work.deduplication_key}" %>">
35
+ <span class="glyphicon glyphicon-question-sign status-unknown"></span>
36
+ </td>
33
37
  </tr>
34
38
  <% end %>
35
39
  </table>
36
40
  <%= paginate @pre_ingest_works %>
37
41
  </div>
42
+ <script>
43
+ $(document).on('turbolinks:load', function() {
44
+ Zizia.displayWorkStatus()
45
+ })
46
+ </script>
data/config/routes.rb CHANGED
@@ -10,4 +10,5 @@ Zizia::Engine.routes.draw do
10
10
 
11
11
  get 'csv_import_details/index'
12
12
  get 'csv_import_details/show/:id', to: 'csv_import_details#show', as: 'csv_import_detail'
13
+ get 'pre_ingest_works/thumbnails/:deduplication_key', to: 'pre_ingest_works#thumbnails'
13
14
  end
data/lib/zizia/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zizia
4
- VERSION = '5.3.0'
4
+ VERSION = '5.4.0'
5
5
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe Zizia::PreIngestWorksController, :clean, type: :controller do
6
+ routes { Zizia::Engine.routes }
7
+ let(:admin_user) { FactoryBot.create(:admin) }
8
+ let(:pre_ingest_work) { FactoryBot.create(:pre_ingest_work) }
9
+ let(:pre_ingest_file) { FactoryBot.create(:pre_ingest_file, pre_ingest_work_id: pre_ingest_work.id) }
10
+ let(:pre_ingest_file_without_file) { FactoryBot.create(:pre_ingest_file, pre_ingest_work_id: pre_ingest_work.id, filename: File.open([Zizia::Engine.root, '/', 'spec/fixtures/dog.jpg'].join)) }
11
+ let(:work) { Work.new(title: ['a title'], deduplication_key: pre_ingest_work.deduplication_key) }
12
+ let(:file_set) do
13
+ FactoryBot.create(:file_set,
14
+ title: ['zizia.png'],
15
+ content: File.open([Zizia::Engine.root, '/', 'spec/fixtures/zizia.png'].join))
16
+ end
17
+ let(:basename) { 'zizia.png' }
18
+ before do
19
+ work.ordered_members << file_set
20
+ work.save
21
+ end
22
+
23
+ describe 'GET thumbnails' do
24
+ context 'as a logged in user' do
25
+ it 'returns 200' do
26
+ allow(controller).to receive(:current_user).and_return(admin_user)
27
+ get :thumbnails, params: { deduplication_key: pre_ingest_work.deduplication_key, format: :json }
28
+ expect(response.status).to eq(200)
29
+ end
30
+
31
+ it 'returns an array of thumbail paths' do
32
+ file_set.save
33
+ allow(controller).to receive(:current_user).and_return(admin_user)
34
+ get :thumbnails, params: { deduplication_key: pre_ingest_work.deduplication_key, format: :json }
35
+ parsed_json = JSON.parse(response.body)
36
+ expect(parsed_json['thumbnails']).to be_an(Array)
37
+ expect(parsed_json['thumbnails'].empty?).to eq(false)
38
+ end
39
+
40
+ it 'returns an empty array if there aren\'t any thumbnails' do
41
+ allow(controller).to receive(:current_user).and_return(admin_user)
42
+ get :thumbnails, params: { deduplication_key: 'abc/1234', format: :json }
43
+ parsed_json = JSON.parse(response.body)
44
+ expect(parsed_json['thumbnails']).to be_an(Array)
45
+ expect(parsed_json['thumbnails'].empty?).to eq(true)
46
+ end
47
+ end
48
+
49
+ context 'as someone not logged in' do
50
+ it 'returns 401' do
51
+ get :thumbnails, params: { deduplication_key: pre_ingest_work.deduplication_key, format: :json }
52
+ expect(response.status).to eq(401)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,7 +1,7 @@
1
1
  require 'rails_helper'
2
2
  include Warden::Test::Helpers
3
3
 
4
- RSpec.describe 'viewing the csv import detail page', js: true do
4
+ RSpec.describe 'viewing the csv import detail page', :clean, js: true do
5
5
  let(:user) { FactoryBot.create(:admin, email: 'systems@curationexperts.com')}
6
6
  let(:second_user) { FactoryBot.create(:user, email: 'user@curationexperts.com') }
7
7
  let(:csv_import) { FactoryBot.create(:csv_import) }
@@ -11,6 +11,14 @@ RSpec.describe 'viewing the csv import detail page', js: true do
11
11
  let(:csv_import_detail_third) { FactoryBot.create(:csv_import_detail, created_at: Time.parse('Wed, 30 Oct 2019 14:20:02 UTC +00:00').utc, depositor_id: second_user.id, csv_import_id: 2) }
12
12
  let(:csv_pre_ingest_works) { FactoryBot.create_list(:pre_ingest_work, 12, csv_import_detail_id: 4) }
13
13
  let(:csv_pre_ingest_work_second) { FactoryBot.create(:pre_ingest_work, csv_import_detail_id: 5, created_at: Time.parse('Thur, 31 Oct 2019 14:20:02 UTC +00:00').utc) }
14
+ let(:pre_ingest_file) { FactoryBot.create(:pre_ingest_file, pre_ingest_work_id: csv_pre_ingest_work_second.id) }
15
+ let(:file_set) do
16
+ FactoryBot.create(:file_set,
17
+ title: ['zizia.png'],
18
+ content: File.open([Zizia::Engine.root, '/', 'spec/fixtures/zizia.png'].join))
19
+ end
20
+ let(:work) { Work.new(title: ['a title'], deduplication_key: csv_pre_ingest_work_second.deduplication_key) }
21
+
14
22
 
15
23
  before do
16
24
  user.save
@@ -27,14 +35,16 @@ RSpec.describe 'viewing the csv import detail page', js: true do
27
35
  csv_import_detail_third.save
28
36
  csv_pre_ingest_works.each(&:save)
29
37
  csv_pre_ingest_work_second.save
38
+ pre_ingest_file.save
39
+
40
+ work.ordered_members << file_set
41
+ work.save
30
42
  login_as user
31
43
  end
32
44
 
33
45
  it 'displays the metadata when you visit the page' do
34
46
  visit ('/csv_import_details/index')
35
47
  expect(page).to have_content('ID')
36
- expect(page).to have_content('Status')
37
- expect(page).to have_content('undetermined')
38
48
  click_on '1'
39
49
  expect(page).to have_content('Total Size')
40
50
  expect(page).to have_content('Deduplication Key')
@@ -55,12 +65,6 @@ RSpec.describe 'viewing the csv import detail page', js: true do
55
65
  expect(page).to have_link '13'
56
66
  end
57
67
 
58
- it 'has a sortable status' do
59
- pending 'status is always undetermined currently'
60
- visit('/csv_import_details/index?direction=asc&locale=en&sort=status')
61
- expect(page).to have_content 'zippy'
62
- end
63
-
64
68
  it 'has a sortable date' do
65
69
  visit('/csv_import_details/index?direction=desc&locale=en&sort=created_at')
66
70
  expect(page).to have_content 'October 31'
@@ -79,12 +83,6 @@ RSpec.describe 'viewing the csv import detail page', js: true do
79
83
  expect(page).to have_content('October 29, 2019 14:20')
80
84
  end
81
85
 
82
- it 'displays undetermined for the status' do
83
- visit ('/csv_import_details/index')
84
- expect(page).to have_content('Status')
85
- expect(page).to have_content('undetermined')
86
- end
87
-
88
86
  it 'displays the overwrite behavior type' do
89
87
  visit ('/csv_import_details/index')
90
88
  expect(page).to have_content('Overwrite Behavior Type')
@@ -100,7 +98,6 @@ RSpec.describe 'viewing the csv import detail page', js: true do
100
98
 
101
99
  visit('/csv_import_details/index')
102
100
  expect(page).to have_content('Next')
103
-
104
101
  end
105
102
 
106
103
  it 'has pagination at 10' do
@@ -134,4 +131,15 @@ RSpec.describe 'viewing the csv import detail page', js: true do
134
131
  click_on 'View Files'
135
132
  expect(page).to have_content 'Row Number'
136
133
  end
134
+
135
+ it 'can show a status for a file' do
136
+ file_set
137
+ visit('/csv_import_details/index')
138
+ click_on '5'
139
+ expect(page).to have_content 'View Files'
140
+ expect(page).to have_content 'Status'
141
+ expect(page.html).to match(/glyphicon-question-sign/)
142
+ click_on 'View Files'
143
+ expect(page).to have_content('Filename')
144
+ end
137
145
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ FactoryBot.define do
3
+ factory :file_set do
4
+ transient do
5
+ user { build(:user) }
6
+ title { nil }
7
+ content { nil }
8
+ end
9
+ after(:build) do |fs, evaluator|
10
+ fs.apply_depositor_metadata evaluator.user.user_key
11
+ fs.title = evaluator.title
12
+ end
13
+
14
+ after(:create) do |file, evaluator|
15
+ Hydra::Works::UploadFileToFileSet.call(file, evaluator.content) if evaluator.content
16
+ end
17
+
18
+ trait :public do
19
+ read_groups { ["public"] }
20
+ end
21
+
22
+ trait :registered do
23
+ read_groups { ["registered"] }
24
+ end
25
+
26
+ factory :file_with_work do
27
+ after(:build) do |file, _evaluator|
28
+ file.title = ['testfile']
29
+ end
30
+ after(:create) do |file, evaluator|
31
+ Hydra::Works::UploadFileToFileSet.call(file, evaluator.content) if evaluator.content
32
+ create(:work, user: evaluator.user).members << file
33
+ end
34
+ end
35
+ end
36
+ end
@@ -7,7 +7,7 @@ FactoryBot.define do
7
7
  updated_at { Time.current }
8
8
  row_number { 1 }
9
9
  row { 'sample,row' }
10
- filename { '/a/path/to/my.csv' }
10
+ filename { [Zizia::Engine.root, '/', 'spec/fixtures/zizia.png'].join }
11
11
  size { 100_203_424 }
12
12
  end
13
13
  end
@@ -4,9 +4,15 @@ require 'rails_helper'
4
4
  RSpec.describe Zizia::PreIngestFile do
5
5
  let(:pre_ingest_work) { FactoryBot.create(:pre_ingest_work) }
6
6
  let(:pre_ingest_file) { FactoryBot.create(:pre_ingest_file, pre_ingest_work_id: pre_ingest_work.id) }
7
- let(:basename) { 'my.csv' }
7
+ let(:pre_ingest_file_without_file) { FactoryBot.create(:pre_ingest_file, pre_ingest_work_id: pre_ingest_work.id, filename: File.open([Zizia::Engine.root, '/', 'spec/fixtures/dog.jpg'].join)) }
8
+ let(:file_set) do
9
+ FactoryBot.create(:file_set,
10
+ title: ['zizia.png'],
11
+ content: File.open([Zizia::Engine.root, '/', 'spec/fixtures/zizia.png'].join))
12
+ end
13
+ let(:basename) { 'zizia.png' }
8
14
 
9
15
  it 'can get the basename for the file' do
10
- expect(pre_ingest_file.basename).to eq(basename)
16
+ expect(pre_ingest_file.basename).to eq basename
11
17
  end
12
18
  end
data/spec/rails_helper.rb CHANGED
@@ -12,6 +12,7 @@ require 'hydra-role-management'
12
12
  require 'byebug'
13
13
  require 'rails-controller-testing'
14
14
  require 'selenium-webdriver'
15
+ require 'devise'
15
16
  # Add additional requires below this line. Rails is not loaded until this point!
16
17
 
17
18
  # Requires supporting ruby files with custom matchers and macros, etc, in
@@ -38,6 +39,8 @@ rescue ActiveRecord::PendingMigrationError => e
38
39
  exit 1
39
40
  end
40
41
  RSpec.configure do |config|
42
+ config.include Devise::Test::ControllerHelpers, type: :controller
43
+
41
44
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
42
45
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
43
46
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zizia
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Data Curation Experts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-11 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active-fedora
@@ -667,6 +667,7 @@ files:
667
667
  - app/controllers/zizia/csv_imports_controller.rb
668
668
  - app/controllers/zizia/importer_documentation_controller.rb
669
669
  - app/controllers/zizia/metadata_details_controller.rb
670
+ - app/controllers/zizia/pre_ingest_works_controller.rb
670
671
  - app/helpers/zizia/application_helper.rb
671
672
  - app/helpers/zizia/metadata_details_helper.rb
672
673
  - app/importers/modular_importer.rb
@@ -675,6 +676,7 @@ files:
675
676
  - app/lib/zizia/metadata_details.rb
676
677
  - app/lib/zizia/metadata_usage.rb
677
678
  - app/lib/zizia/work_attributes.rb
679
+ - app/models/zizia/ability.rb
678
680
  - app/models/zizia/csv_import.rb
679
681
  - app/models/zizia/csv_import_detail.rb
680
682
  - app/models/zizia/pre_ingest_file.rb
@@ -773,6 +775,7 @@ files:
773
775
  - solr/config/xslt/luke.xsl
774
776
  - spec/controllers/importer_documentation_controller_spec.rb
775
777
  - spec/controllers/metadata_details_spec.rb
778
+ - spec/controllers/pre_ingest_works_controller_spec.rb
776
779
  - spec/dummy/.fcrepo_wrapper
777
780
  - spec/dummy/.gitignore
778
781
  - spec/dummy/.rspec
@@ -1503,6 +1506,7 @@ files:
1503
1506
  - spec/factories/collection.rb
1504
1507
  - spec/factories/csv_import.rb
1505
1508
  - spec/factories/csv_import_detail.rb
1509
+ - spec/factories/file_sets.rb
1506
1510
  - spec/factories/pre_ingest_file.rb
1507
1511
  - spec/factories/pre_ingest_work.rb
1508
1512
  - spec/factories/user.rb