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

pulibrary / pdc_describe / bc426aed-306d-47e9-94c2-7b74ea9c16e2

09 May 2024 06:01PM UTC coverage: 95.922% (+0.03%) from 95.89%
bc426aed-306d-47e9-94c2-7b74ea9c16e2

Pull #1806

circleci

hectorcorrea
Added logging
Pull Request #1806: Fixes provenance bug in the Wizard

5 of 9 new or added lines in 2 files covered. (55.56%)

9 existing lines in 1 file now uncovered.

3246 of 3384 relevant lines covered (95.92%)

221.68 hits per line

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

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

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

11
  def update_precurated_file_list(added_files, deleted_files)
1✔
12
    delete_uploads(deleted_files)
75✔
13
    add_uploads(added_files)
75✔
14
    if work.changes.count > 0
75✔
15
      s3_service.client_s3_files(reload: true)
13✔
16
      work.reload # reload the work to pick up the changes in the attachments
13✔
17
    end
18

19
    work
75✔
20
  end
21

22
  # Delete any files the user has decided not to keep and
23
  #  add all files that were uploaded in the backgroud via uppy and any files deleted to an upload snapshot
24
  #
25
  # @param [Array] deleted_files files that exist in AWS that should be removed
26
  def snapshot_uppy_and_delete_files(deleted_files)
1✔
27
    deleted_files.each do |filename|
10✔
28
      s3_service.delete_s3_object(filename)
3✔
29
    end
30

31
    # assigns all backgroun changes and deletes to the current user
32
    work.reload_snapshots(user_id: current_user.id)
9✔
33
    work
9✔
34
  end
35

36
  def find_post_curation_uploads(upload_keys: [])
1✔
37
    return [] unless work.approved? && !upload_keys.empty?
5✔
38
    work.post_curation_uploads.select { |upload| upload_keys.include?(upload.key) }
3✔
39
  end
40

41
  private
1✔
42

43
    def delete_uploads(deleted_files)
1✔
44
      return if deleted_files.empty?
75✔
45

46
      deleted_files.each do |filename|
8✔
47
        s3_service.delete_s3_object(filename)
11✔
48
        work.track_change(:removed, filename)
11✔
49
      end
50
      work.log_file_changes(@current_user.id)
8✔
51
    end
52

53
    def add_uploads(added_files)
1✔
54
      return if added_files.empty?
75✔
55

56
      # Update the upload snapshot to reflect the files the user wants to add...
57
      last_snapshot = work.upload_snapshots.first
9✔
58
      snapshot = BackgroundUploadSnapshot.new(work:)
9✔
59
      snapshot.store_files(added_files, pre_existing_files: last_snapshot&.files, current_user: @current_user)
9✔
60
      snapshot.save
9✔
61

62
      # ...adds the file to AWS directly and mark them as complete in the snapshot
63
      added_files.map do |file|
9✔
64
        key = work.s3_query_service.upload_file(io: file.to_io, filename: file.original_filename, size: file.size)
14✔
65
        if key.blank?
14✔
NEW
66
          Rails.logger.error("Error uploading #{file.original_filename} to work #{work.id}")
×
NEW
67
          Honeybadger.notify("Error uploading #{file.original_filename} to work #{work.id}")
×
68
        end
69
        snapshot.mark_complete(file.original_filename, work.s3_query_service.last_response.etag.delete('"'))
14✔
70
        snapshot.save!
14✔
71
        # delete the local file
72
        File.delete(file.path)
14✔
73
      end
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