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

pulibrary / pdc_describe / 9091a1ae-29be-458c-984a-339d213919c4

12 Dec 2024 07:41PM UTC coverage: 26.434% (-69.7%) from 96.113%
9091a1ae-29be-458c-984a-339d213919c4

Pull #2000

circleci

jrgriffiniii
Removing integration with ActiveStorage
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

945 of 3575 relevant lines covered (26.43%)

0.35 hits per line

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

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

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

22
    work
×
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|
×
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)
×
36
    work
×
37
  end
38

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

44
  private
1✔
45

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

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

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

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

63
      # ...adds the file to AWS directly and mark them as complete in the snapshot
64
      added_files.map do |file|
×
65
        if upload_file(file)
×
66
          snapshot.mark_complete(file.original_filename, work.s3_query_service.last_response.etag.delete('"'))
×
67
          snapshot.save!
×
68
          File.delete(file.path) # delete the local copy
×
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)
×
75
      if key.blank?
×
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
×
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