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

pulibrary / pdc_describe / 7031ff5b-e2d7-4285-af8b-e7b55adfc48a

pending completion
7031ff5b-e2d7-4285-af8b-e7b55adfc48a

Pull #899

circleci

mccalluc
Finish removal of explicit if-then in js
Pull Request #899: Move messages up to sidebar on the right which can be toggled

1623 of 1788 relevant lines covered (90.77%)

105.5 hits per line

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

95.83
/app/services/work_uploads_edit_service.rb
1
# frozen_string_literal: true
2
class WorkUploadsEditService
1✔
3
  attr_reader :work
1✔
4

5
  def initialize(work, current_user)
1✔
6
    @work = work
19✔
7
    @current_user = current_user
19✔
8
    @changes = []
19✔
9
  end
10

11
  def update_precurated_file_list(work_params)
1✔
12
    if work_params.key?(:deleted_uploads) || work_params.key?(:pre_curation_uploads) || work_params.key?(:replaced_uploads)
19✔
13
      if work_params.key?(:deleted_uploads)
6✔
14
        delete_pre_curation_uploads(work_params[:deleted_uploads])
2✔
15
      elsif work_params.key?(:pre_curation_uploads)
4✔
16
        update_uploads(work_params)
2✔
17
      elsif work_params.key?(:replaced_uploads)
2✔
18
        replace_uploads(work_params[:replaced_uploads])
2✔
19
      end
20
      work.log_file_changes(@changes, @current_user.id)
6✔
21
      work.reload # reload the work to pick up the changes in the attachments
6✔
22
    else # no changes in the parameters, just return the original work
23
      work
13✔
24
    end
25
  end
26

27
  def find_post_curation_uploads(upload_keys: [])
1✔
28
    return [] unless work.approved? && !upload_keys.empty?
×
29
    work.post_curation_uploads.select { |upload| upload_keys.include?(upload.key) }
×
30
  end
31

32
  private
1✔
33

34
    def replace_uploads(replaced_uploads_params)
1✔
35
      new_uploads = []
2✔
36
      work.pre_curation_uploads.each_with_index do |existing|
2✔
37
        key = existing.key
5✔
38
        next unless replaced_uploads_params.key?(key)
5✔
39
        new_uploads << replaced_uploads_params[key]
2✔
40
        track_change(:deleted, existing.filename.to_s)
2✔
41
        existing.purge
2✔
42
      end
43
      work.reload
2✔
44
      new_uploads.each do |new_upload|
2✔
45
        track_change(:added, new_upload.original_filename)
2✔
46
        work.pre_curation_uploads.attach(new_upload)
2✔
47
      end
48
    end
49

50
    def delete_pre_curation_uploads(deleted_uploads_params)
1✔
51
      work.pre_curation_uploads.each do |existing|
2✔
52
        if deleted_uploads_params.key?(existing.key) && deleted_uploads_params[existing.key] == "1"
4✔
53
          track_change(:deleted, existing.filename.to_s)
2✔
54
          existing.purge
2✔
55
        end
56
      end
57
    end
58

59
    def update_uploads(work_params)
1✔
60
      # delete all existing uploads...
61
      work.pre_curation_uploads.each do |existing_upload|
2✔
62
        track_change(:deleted, existing_upload.filename.to_s)
2✔
63
        existing_upload.purge
2✔
64
      end
65

66
      # ...reload the work to pick up the changes in the attachments
67
      work.reload
2✔
68

69
      # ...and then and then add the ones indicated in the parameters
70
      Array(work_params[:pre_curation_uploads]).each do |new_upload|
2✔
71
        track_change(:added, new_upload.original_filename)
4✔
72
        work.pre_curation_uploads.attach(new_upload)
4✔
73
      end
74
    end
75

76
    def track_change(action, filename)
1✔
77
      @changes << { action: action, filename: filename }
12✔
78
    end
79
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