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

pulibrary / pdc_describe / 06242e19-aea0-4511-b228-adfed64ce8ef

12 Dec 2024 08:35PM UTC coverage: 95.68% (-0.4%) from 96.113%
06242e19-aea0-4511-b228-adfed64ce8ef

Pull #2000

circleci

jrgriffiniii
wip
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

3322 of 3472 relevant lines covered (95.68%)

202.28 hits per line

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

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

11
  def update_precurated_file_list(added_files, deleted_files)
1✔
12
    delete_uploads(deleted_files)
56✔
13
    add_uploads(added_files)
56✔
14
    file_list_changed = deleted_files.count > 0 || added_files.count > 0
56✔
15
    if file_list_changed
56✔
16
      s3_service.client_s3_files(reload: true)
12✔
17
      # Pick up the changes in the attachments and assings them to the current user
18
      work.reload
12✔
19
      work.reload_snapshots(user_id: current_user.id)
12✔
20
    end
21

22
    work
56✔
23
  end
24

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

34
    # assigns all backgroun changes and deletes to the current user
35
    work.reload_snapshots(user_id: current_user.id)
6✔
36
    work
6✔
37
  end
38

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

44
  private
1✔
45

46
    def delete_uploads(deleted_files)
1✔
47
      return if deleted_files.empty?
56✔
48

49
      deleted_files.each do |filename|
6✔
50
        s3_service.delete_s3_object(filename)
9✔
51
      end
52
    end
53

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

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

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

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