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

pulibrary / pdc_describe / b1776731-62d7-41a7-882d-6a5b4760db75

14 May 2024 12:28PM UTC coverage: 79.223% (-16.7%) from 95.9%
b1776731-62d7-41a7-882d-6a5b4760db75

push

circleci

carolyncole
Adding a submission completion page

fixes #1791

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

567 existing lines in 42 files now uncovered.

2692 of 3398 relevant lines covered (79.22%)

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

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

19
    work
35✔
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|
1✔
UNCOV
28
      s3_service.delete_s3_object(filename)
×
29
    end
30

31
    # assigns all backgroun changes and deletes to the current user
32
    work.reload_snapshots(user_id: current_user.id)
1✔
33
    work
1✔
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?
35✔
45

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

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

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

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

72
    def upload_file(file)
1✔
73
      key = work.s3_query_service.upload_file(io: file.to_io, filename: file.original_filename, size: file.size)
9✔
74
      if key.blank?
9✔
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
79
        true
9✔
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