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

pulibrary / pdc_describe / cace366a-ffad-45f1-9b60-678e607fa527

14 May 2024 02:21PM UTC coverage: 60.862% (-35.0%) from 95.908%
cace366a-ffad-45f1-9b60-678e607fa527

push

circleci

jrgriffiniii
wip

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

1194 existing lines in 57 files now uncovered.

2076 of 3411 relevant lines covered (60.86%)

22.71 hits per line

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

54.35
/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
11✔
7
    @s3_service = work.s3_query_service
11✔
8
    @current_user = current_user
11✔
9
  end
10

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

19
    work
11✔
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✔
UNCOV
27
    deleted_files.each do |filename|
×
UNCOV
28
      s3_service.delete_s3_object(filename)
×
29
    end
30

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

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

41
  private
1✔
42

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

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

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

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

62
      # ...adds the file to AWS directly and mark them as complete in the snapshot
UNCOV
63
      added_files.map do |file|
×
UNCOV
64
        if upload_file(file)
×
UNCOV
65
          snapshot.mark_complete(file.original_filename, work.s3_query_service.last_response.etag.delete('"'))
×
UNCOV
66
          snapshot.save!
×
UNCOV
67
          File.delete(file.path) # delete the local copy
×
68
        end
69
      end
70
    end
71

72
    def upload_file(file)
1✔
UNCOV
73
      key = work.s3_query_service.upload_file(io: file.to_io, filename: file.original_filename, size: file.size)
×
UNCOV
74
      if key.blank?
×
75
        Rails.logger.error("Error uploading #{file.original_filename} to work #{work.id}")
×
76
        Honeybadger.notify("Error uploading #{file.original_filename} to work #{work.id}")
×
77
        false
×
78
      else
UNCOV
79
        true
×
80
      end
81
    end
82
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