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

pulibrary / pdc_describe / 4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

07 Apr 2025 06:36PM UTC coverage: 1.283% (-94.6%) from 95.862%
4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

Pull #1994

circleci

hectorcorrea
Switched to use the autocomplete that we aleady use for ROR. Integrated it with the existing logic for creators
Pull Request #1994: Started adding auto complete to contributors

0 of 46 new or added lines in 2 files covered. (0.0%)

4806 existing lines in 74 files now uncovered.

65 of 5065 relevant lines covered (1.28%)

0.01 hits per line

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

0.0
/app/services/work_uploads_edit_service.rb
1
# frozen_string_literal: true
UNCOV
2
class WorkUploadsEditService
×
UNCOV
3
  attr_reader :work, :s3_service, :current_user
×
4

UNCOV
5
  def initialize(work, current_user)
×
UNCOV
6
    @work = work
×
UNCOV
7
    @s3_service = work.s3_query_service
×
UNCOV
8
    @current_user = current_user
×
UNCOV
9
  end
×
10

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

UNCOV
22
    work
×
UNCOV
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
UNCOV
29
  def snapshot_uppy_and_delete_files(deleted_files)
×
UNCOV
30
    deleted_files.each do |filename|
×
UNCOV
31
      s3_service.delete_s3_object(filename)
×
UNCOV
32
    end
×
33

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

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

UNCOV
44
  private
×
45

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

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

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

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

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

UNCOV
73
    def upload_file(file)
×
UNCOV
74
      key = work.s3_query_service.upload_file(io: file.to_io, filename: file.original_filename, size: file.size)
×
UNCOV
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
×
UNCOV
79
      else
×
UNCOV
80
        true
×
UNCOV
81
      end
×
UNCOV
82
    end
×
UNCOV
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