• 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/controllers/works_wizard_controller.rb
1
# frozen_string_literal: true
2

UNCOV
3
require "nokogiri"
×
UNCOV
4
require "open-uri"
×
5

6
# Controller to handle wizard Mode when editing an work
7
#
8
# The wizard flow is shown in the [mermaid diagram here](https://github.com/pulibrary/pdc_describe/blob/main/docs/wizard_flow.md).
9

UNCOV
10
class WorksWizardController < ApplicationController
×
UNCOV
11
  include ERB::Util
×
UNCOV
12
  around_action :rescue_aasm_error, only: [:validate, :new_submission_save]
×
13

UNCOV
14
  before_action :load_work, only: [:edit_wizard, :update_wizard, :attachment_select, :attachment_selected,
×
UNCOV
15
                                   :file_upload, :file_uploaded, :file_other, :review, :validate,
×
UNCOV
16
                                   :readme_select, :readme_uploaded, :readme_uploaded_payload]
×
17

18
  # GET /works/1/edit-wizard
UNCOV
19
  def edit_wizard
×
UNCOV
20
    @wizard_mode = true
×
UNCOV
21
    if validate_modification_permissions(work: @work,
×
UNCOV
22
                                         uneditable_message: "Can not edit work: #{@work.id} is not editable by #{current_user.uid}",
×
UNCOV
23
                                         current_state_message: "Can not edit work: #{@work.id} is not editable in current state by #{current_user.uid}")
×
24

UNCOV
25
      prepare_decorators_for_work_form(@work)
×
UNCOV
26
    end
×
UNCOV
27
  end
×
28

29
  # PATCH /works/1/update-wizard
UNCOV
30
  def update_wizard
×
UNCOV
31
    edit_helper(:edit_wizard, work_update_additional_path(@work))
×
UNCOV
32
  end
×
33

34
  # Prompt to select how to submit their files
35
  # GET /works/1/attachment_select
UNCOV
36
  def attachment_select; end
×
37

38
  # User selected a specific way to submit their files
39
  # POST /works/1/attachment_selected
UNCOV
40
  def attachment_selected
×
UNCOV
41
    @work.files_location = params["attachment_type"]
×
UNCOV
42
    @work.save!
×
43

44
    # create a directory for the work if the curator will need to move files by hand
UNCOV
45
    @work.s3_query_service.create_directory if @work.files_location != "file_upload"
×
46

UNCOV
47
    if params[:save_only] == "true"
×
UNCOV
48
      render :attachment_select
×
UNCOV
49
    else
×
UNCOV
50
      redirect_to file_location_url
×
UNCOV
51
    end
×
UNCOV
52
  end
×
53

54
  # Allow user to upload files directly
55
  # GET /works/1/file_upload
UNCOV
56
  def file_upload
×
UNCOV
57
    @work_decorator = WorkDecorator.new(@work, current_user)
×
UNCOV
58
  end
×
59

60
  # POST /works/1/upload-files-wizard (called via Uppy)
UNCOV
61
  def upload_files
×
62
    @work = Work.find(params[:id])
×
63
    upload_service = WorkUploadsEditService.new(@work, current_user)
×
64
    upload_service.update_precurated_file_list(params["files"], [])
×
65
    render plain: params["files"].map(&:original_filename).join(",")
×
UNCOV
66
  end
×
67

68
  # POST /works/1/file_upload
UNCOV
69
  def file_uploaded
×
UNCOV
70
    upload_service = WorkUploadsEditService.new(@work, current_user)
×
71
    # By the time we hit this endpoint files have been uploaded by Uppy submmitting POST requests
72
    # to /works/1/upload-files-wizard therefore we only need to delete files here and update the upload snapshot.
UNCOV
73
    @work = upload_service.snapshot_uppy_and_delete_files(deleted_files_param)
×
74

UNCOV
75
    prepare_decorators_for_work_form(@work)
×
UNCOV
76
    if params[:save_only] == "true"
×
UNCOV
77
      render :file_upload
×
UNCOV
78
    else
×
UNCOV
79
      redirect_to(work_review_path)
×
UNCOV
80
    end
×
UNCOV
81
  rescue => ex
×
82
    # Notice that we log the URL (rather than @work.doi) because sometimes we are getting a nil @work.
83
    # The URL will include the ID and might help us troubleshoot the issue further if it happens again.
84
    # See https://github.com/pulibrary/pdc_describe/issues/1801
UNCOV
85
    error_message = "Failed to update work snapshot, URL: #{request.url}: #{ex}"
×
UNCOV
86
    Rails.logger.error(error_message)
×
UNCOV
87
    Honeybadger.notify(error_message)
×
UNCOV
88
    flash[:notice] = "Failed to update work snapshot, work: #{@work&.doi}: #{ex}. Please contact rdss@princeton.edu for assistance."
×
89

UNCOV
90
    redirect_to work_file_upload_path(@work)
×
UNCOV
91
  end
×
92

93
  # Allow user to indicate where their files are located in the WWW
94
  # GET /works/1/file_other
UNCOV
95
  def file_other; end
×
96

97
  # GET /works/1/review
98
  # POST /works/1/review
UNCOV
99
  def review
×
UNCOV
100
    if request.method == "POST" || request.method == "PATCH"
×
UNCOV
101
      @work.location_notes = params["location_notes"]
×
UNCOV
102
      @work.save!
×
UNCOV
103
      if params[:save_only] == "true"
×
UNCOV
104
        render :file_other
×
UNCOV
105
      end
×
UNCOV
106
    end
×
UNCOV
107
  end
×
108

109
  # Validates that the work is ready to be approved
110
  # POST /works/1/validate-wizard
111
  # PATCH /works/1/validate-wizard
UNCOV
112
  def validate
×
UNCOV
113
    @work.submission_notes = params["submission_notes"]
×
114

UNCOV
115
    if params[:save_only] == "true"
×
UNCOV
116
      @work.save
×
UNCOV
117
      render :review
×
UNCOV
118
    else
×
UNCOV
119
      @work.complete_submission!(current_user)
×
UNCOV
120
      redirect_to work_complete_path(@work.id)
×
UNCOV
121
    end
×
UNCOV
122
  end
×
123

124
  # Show the user the form to select a readme
125
  # GET /works/1/readme_select
UNCOV
126
  def readme_select
×
UNCOV
127
    readme = Readme.new(@work, current_user)
×
UNCOV
128
    @readme = readme.file_name
×
UNCOV
129
  end
×
130

131
  # Hit when the user clicks "Save" or "Next" on the README upload process.
132
  # Notice that this does not really uploads the file, that happens in readme_uploaded_payload.
133
  # PATCH /works/1/readme_uploaded
UNCOV
134
  def readme_uploaded
×
UNCOV
135
    readme = Readme.new(@work, current_user)
×
UNCOV
136
    if params[:save_only] == "true"
×
UNCOV
137
      @readme = readme.file_name
×
UNCOV
138
      render :readme_select
×
UNCOV
139
    else
×
UNCOV
140
      redirect_to work_attachment_select_url(@work)
×
UNCOV
141
    end
×
UNCOV
142
  end
×
143

UNCOV
144
  def files_param
×
UNCOV
145
    params["files"]
×
UNCOV
146
  end
×
147

148
  # Uploads the README file, called by Uppy.
149
  # POST /works/1/readme-uploaded-payload
UNCOV
150
  def readme_uploaded_payload
×
UNCOV
151
    raise StandardError("Only one README file can be uploaded.") if files_param.empty?
×
UNCOV
152
    raise StandardError("Only one README file can be uploaded.") if files_param.length > 1
×
153

UNCOV
154
    readme_file = files_param.first
×
UNCOV
155
    readme = Readme.new(@work, current_user)
×
156

UNCOV
157
    readme_error = readme.attach(readme_file)
×
UNCOV
158
    if readme_error.nil?
×
UNCOV
159
      render plain: readme.file_name
×
UNCOV
160
    else
×
161
      # Tell Uppy there was an error uploading the README
UNCOV
162
      render plain: readme.file_name, status: :internal_server_error
×
UNCOV
163
    end
×
UNCOV
164
  end
×
165

UNCOV
166
  def file_location_url
×
UNCOV
167
    WorkMetadataService.file_location_url(@work)
×
UNCOV
168
  end
×
UNCOV
169
  helper_method :file_location_url
×
170

UNCOV
171
  private
×
172

UNCOV
173
    def edit_helper(view_name, redirect_url)
×
UNCOV
174
      if validate_modification_permissions(work: @work,
×
UNCOV
175
                                           uneditable_message: "Can not update work: #{@work.id} is not editable by #{current_user.uid}",
×
UNCOV
176
                                           current_state_message: "Can not update work: #{@work.id} is not editable in current state by #{current_user.uid}")
×
UNCOV
177
        prepare_decorators_for_work_form(@work)
×
UNCOV
178
        check_for_stale_update(@work, params)
×
UNCOV
179
        if WorkCompareService.update_work(work: @work, update_params:, current_user:)
×
UNCOV
180
          if params[:save_only] == "true"
×
UNCOV
181
            render view_name
×
UNCOV
182
          else
×
UNCOV
183
            redirect_to redirect_url
×
UNCOV
184
          end
×
UNCOV
185
        else
×
186
          # return 200 so the loadbalancer doesn't capture the error
UNCOV
187
          render view_name
×
UNCOV
188
        end
×
UNCOV
189
      end
×
UNCOV
190
    end
×
191

UNCOV
192
    def load_work
×
UNCOV
193
      @work = Work.find(params[:id])
×
UNCOV
194
    end
×
195

196
    # @note No testing coverage but not a route, not called
UNCOV
197
    def patch_params
×
198
      return {} unless params.key?(:patch)
×
199

200
      params[:patch]
×
UNCOV
201
    end
×
202

203
    # @note No testing coverage but not a route, not called
UNCOV
204
    def pre_curation_uploads_param
×
205
      return if patch_params.nil?
×
206

207
      patch_params[:pre_curation_uploads]
×
UNCOV
208
    end
×
209

UNCOV
210
    def deleted_files_param
×
UNCOV
211
      deleted_count = (params.dig("work", "deleted_files_count") || "0").to_i
×
UNCOV
212
      (1..deleted_count).map { |i| params.dig("work", "deleted_file_#{i}") }.select(&:present?)
×
UNCOV
213
    end
×
214

215
    # @note No testing coverage but not a route, not called
UNCOV
216
    def readme_file_param
×
217
      return if patch_params.nil?
×
218

219
      patch_params[:readme_file]
×
UNCOV
220
    end
×
221

UNCOV
222
    def rescue_aasm_error
×
UNCOV
223
      super
×
UNCOV
224
    rescue StandardError => generic_error
×
225
      redirect_to root_url, notice: "We apologize, an error was encountered: #{generic_error.message}. Please contact the PDC Describe administrators."
×
UNCOV
226
    end
×
227

UNCOV
228
    def redirect_aasm_error(transition_error_message)
×
UNCOV
229
      if @work.persisted?
×
UNCOV
230
        redirect_to edit_work_wizard_path(id: @work.id), notice: transition_error_message, params:
×
UNCOV
231
      else
×
232
        redirect_to work_create_new_submission_path(@work), notice: transition_error_message, params:
×
UNCOV
233
      end
×
UNCOV
234
    end
×
UNCOV
235
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