• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 5db21940-59bd-4742-a25d-02e5e58d6646

pending completion
5db21940-59bd-4742-a25d-02e5e58d6646

Pull #1014

circleci

Carolyn Cole
Creating a folder in Amazon so the curators do not need to do it by hand fixes #1001
Pull Request #1014: Creating a folder in Amazon so the curators do not need to do it by hand

3 of 3 new or added lines in 2 files covered. (100.0%)

1703 of 1872 relevant lines covered (90.97%)

80.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.91
/app/services/work_uploads_edit_service.rb
1
# frozen_string_literal: true
2
class WorkUploadsEditService
1✔
3
  attr_reader :work, :s3_service
1✔
4

5
  def initialize(work, current_user)
1✔
6
    @work = work
6✔
7
    @s3_service = work.s3_query_service
6✔
8
    @current_user = current_user
6✔
9
    @changes = []
6✔
10
  end
11

12
  def update_precurated_file_list(work_params)
1✔
13
    if work_params.key?(:deleted_uploads) || work_params.key?(:pre_curation_uploads) || work_params.key?(:replaced_uploads)
4✔
14
      if work_params.key?(:deleted_uploads)
×
15
        delete_pre_curation_uploads(work_params[:deleted_uploads])
×
16
      elsif work_params.key?(:pre_curation_uploads)
×
17
        update_uploads(work_params)
×
18
      elsif work_params.key?(:replaced_uploads)
×
19
        replace_uploads(work_params[:replaced_uploads])
×
20
      end
21
      work.log_file_changes(@changes, @current_user.id)
×
22
      s3_service.client_s3_files(reload: true)
×
23
      work.reload # reload the work to pick up the changes in the attachments
×
24
    else # no changes in the parameters, just return the original work
25
      work
4✔
26
    end
27
  end
28

29
  def find_post_curation_uploads(upload_keys: [])
1✔
30
    return [] unless work.approved? && !upload_keys.empty?
2✔
31
    work.post_curation_uploads.select { |upload| upload_keys.include?(upload.key) }
3✔
32
  end
33

34
  private
1✔
35

36
    def replace_uploads(replaced_uploads_params)
1✔
37
      replaced_uploads_params.keys.each do |key|
×
38
        s3_service.delete_s3_object(key)
×
39
        track_change(:deleted, key)
×
40
        new_upload = replaced_uploads_params[key]
×
41
        work.pre_curation_uploads.attach(new_upload)
×
42
        track_change(:added, new_upload.original_filename)
×
43
      end
44
    end
45

46
    def delete_pre_curation_uploads(deleted_uploads_params)
1✔
47
      deleted_uploads_params.each do |delete_s3|
×
48
        s3_service.delete_s3_object(delete_s3.first) if delete_s3.last == "1"
×
49
        track_change(:deleted, delete_s3.first)
×
50
      end
51
    end
52

53
    def update_uploads(work_params)
1✔
54
      # delete all existing uploads...
55
      work.pre_curation_uploads_fast.each do |existing_upload|
×
56
        track_change(:deleted, existing_upload.filename.to_s)
×
57
        s3_service.delete_s3_object(existing_upload.key)
×
58
      end
59

60
      # TODO: can we remove this reload now???  May be causing issues with mocking
61
      # ...reload the work to pick up the changes in the attachments
62
      work.reload
×
63

64
      # ...and then and then track the ones indicated in the parameters
65
      # todo - How do we know what has been attached in the background?
66
      Array(work_params[:pre_curation_uploads]).each do |new_upload|
×
67
        work.pre_curation_uploads.attach(new_upload)
×
68
        track_change(:added, new_upload.original_filename)
×
69
      end
70
    end
71

72
    def track_change(action, filename)
1✔
73
      @changes << { action: action, filename: filename }
×
74
    end
75
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc