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

pulibrary / pdc_describe / aa4d17ae-5b88-4b80-9b41-f98c7bc03ef4

pending completion
aa4d17ae-5b88-4b80-9b41-f98c7bc03ef4

Pull #1060

circleci

jrgriffiniii
wip
Pull Request #1060: [wip] Integrating Support for Upload Snapshots

152 of 152 new or added lines in 7 files covered. (100.0%)

2016 of 2058 relevant lines covered (97.96%)

171.45 hits per line

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

77.78
/app/controllers/upload_snapshots_controller.rb
1
# frozen_string_literal: true
2
class UploadSnapshotsController < ApplicationController
1✔
3
  # POST /upload-snapshots/:work_id/:uri
4
  # Here the URI specifies the specific upload for which the snapshot is being generated
5
  def create
1✔
6
    @upload = find_upload(key: key_param)
4✔
7
    @upload_snapshot = @upload.create_snapshot
3✔
8

9
    flash[:notice] = "Successfully created the snapshot for upload #{@upload_snapshot.key} attached to work #{work.id}."
×
10
    redirect_to edit_upload_snapshot_path(@work)
×
11
  rescue StandardError => error
12
    error_message = "Failed to create the upload snapshot: #{error}"
4✔
13
    Rails.logger.error(error_message)
4✔
14
    flash[:notice] = error_message
4✔
15

16
    response_location = if @work.nil?
4✔
17
                          works_path
1✔
18
                        else
19
                          edit_upload_snapshot_path(@work)
3✔
20
                        end
21

22
    redirect_to response_location
4✔
23
  end
24

25
  def edit
1✔
26
    @uploads = work.uploads
×
27

28
    render :edit
×
29
  end
30

31
  # DELETE /upload-snapshots/:id
32
  # Destroys the snapshot after resolving it from the database ID
33
  def destroy
1✔
34
    current_work = upload_snapshot.work
2✔
35
    upload_snapshot.destroy
1✔
36
    flash[:notice] = "Successfully deleted the upload snapshot #{upload_snapshot_id}."
1✔
37

38
    redirect_to edit_upload_snapshot_path(current_work)
1✔
39
  rescue StandardError => error
40
    error_message = "Failed to delete the upload snapshot: #{error}"
1✔
41
    Rails.logger.error(error_message)
1✔
42
    flash[:notice] = error_message
1✔
43

44
    redirect_to works_path
1✔
45
  end
46

47
  def download
1✔
48
    @work = upload_snapshot.work
×
49
    if current_user && @work.editable_by?(current_user)
×
50
      filename = upload_snapshot.filename
×
51
      pre_curation = !@work.approved?
×
52
      service = S3QueryService.new(@work, pre_curation)
×
53
      redirect_to service.file_url(filename)
×
54
    else
55
      Honeybadger.notify("Can not download work: #{work.id} is not editable by #{current_user}")
×
56
      redirect_to root_path, notice: I18n.t("works.download.privs")
×
57
    end
58
  end
59

60
  private
1✔
61

62
    def upload_snapshot_id
1✔
63
      @upload_snapshot_id = params[:id]
6✔
64
      raise(ArgumentError, "No ID provided for the upload snapshot.") unless @upload_snapshot_id
6✔
65

66
      @upload_snapshot_id
6✔
67
    end
68

69
    def upload_snapshot
1✔
70
      return unless upload_snapshot_id
3✔
71

72
      @upload_snapshot ||= UploadSnapshot.find(upload_snapshot_id)
3✔
73
    end
74

75
    def work_id
1✔
76
      @work_id = params[:work_id]
4✔
77
      raise(ArgumentError, "No ID provided for the work.") unless @work_id
4✔
78

79
      @work_id
4✔
80
    end
81

82
    def key_param
1✔
83
      @key_param = params[:key]
4✔
84
      raise(ArgumentError, "No URI provided for the file upload.") unless @key_param
4✔
85

86
      @key_param
4✔
87
    end
88

89
    def work
1✔
90
      @work ||= Work.find(work_id)
4✔
91
    end
92

93
    def find_upload(key:)
1✔
94
      work.uploads.find { |s3_file| key.include?(s3_file.key) }
7✔
95
    end
96
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