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

pulibrary / pdc_describe / 3a77b3ec-d590-434f-a051-a322a332e47d

04 Apr 2024 02:39PM UTC coverage: 95.849% (+0.007%) from 95.842%
3a77b3ec-d590-434f-a051-a322a332e47d

Pull #1739

circleci

carolyncole
Load presenters for additional metadata screen
Pull Request #1739: 1684 additional step

10 of 10 new or added lines in 1 file covered. (100.0%)

2 existing lines in 1 file now uncovered.

3233 of 3373 relevant lines covered (95.85%)

214.09 hits per line

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

98.08
/app/controllers/works_wizard_controller.rb
1
# frozen_string_literal: true
2

3
require "nokogiri"
1✔
4
require "open-uri"
1✔
5

6
# Controller to handle wizard Mode when editing an work
7
#
8
# The wizard flow is as follows:
9
# new_submission -> new_submission_save -> edit_wizard -> update_wizard -> readme_select -> readme_uploaded -> attachment_select ->
10
#     attachment_selected -> file_other ->                  review -> validate -> [ work controller ] show & file_list
11
#                         \> file_upload -> file_uploaded -^
12

13
class WorksWizardController < ApplicationController
1✔
14
  include ERB::Util
1✔
15
  around_action :rescue_aasm_error, only: [:validate, :new_submission_save]
1✔
16

17
  before_action :load_work, only: [:edit_wizard, :update_wizard, :attachment_select, :attachment_selected,
1✔
18
                                   :file_upload, :file_uploaded, :file_other, :review, :validate,
19
                                   :readme_select, :readme_uploaded, :update_additional_save, :update_additional]
20

21
  # get Renders the "step 0" information page before creating a new dataset
22
  # GET /works/new_submission
23
  def new_submission
1✔
24
    @work = WorkMetadataService.new(params:, current_user:).work_for_new_submission
26✔
25
    prepare_decorators_for_work_form(@work)
26✔
26
  end
27

28
  # Creates the new dataset or update the dataset is save only was done previously
29
  # POST /works/new_submission or POST /works/1/new_submission
30
  def new_submission_save
1✔
31
    @work = WorkMetadataService.new(params:, current_user:).new_submission
22✔
32
    @errors = @work.errors.to_a
22✔
33
    if @errors.count.positive?
22✔
34
      prepare_decorators_for_work_form(@work)
1✔
35
      render :new_submission
1✔
36
    else
37
      redirect_to edit_work_wizard_path(@work)
21✔
38
    end
39
  end
40

41
  # GET /works/1/edit-wizard
42
  def edit_wizard
1✔
43
    @wizard_mode = true
24✔
44
    if validate_modification_permissions(work: @work,
24✔
45
                                         uneditable_message: "Can not edit work: #{@work.id} is not editable by #{current_user.uid}",
46
                                         current_state_message: "Can not edit work: #{@work.id} is not editable in current state by #{current_user.uid}")
47

48
      prepare_decorators_for_work_form(@work)
24✔
49
    end
50
  end
51

52
  # PATCH /works/1/update-wizard
53
  def update_wizard
1✔
54
    edit_helper(:edit_wizard, work_update_additional_path(@work))
27✔
55
  end
56

57
  # get /works/1/update-additional
58
  def update_additional
1✔
59
    prepare_decorators_for_work_form(@work)
21✔
60
  end
61

62
  # PATCH /works/1/update-additional
63
  def update_additional_save
1✔
64
    edit_helper(:update_additional, work_readme_select_path(@work))
2✔
65
  end
66

67
  # Prompt to select how to submit their files
68
  # GET /works/1/attachment_select
69
  def attachment_select; end
1✔
70

71
  # User selected a specific way to submit their files
72
  # POST /works/1/attachment_selected
73
  def attachment_selected
1✔
74
    @work.files_location = params["attachment_type"]
7✔
75
    @work.save!
7✔
76

77
    # create a directory for the work if the curator will need to move files by hand
78
    @work.s3_query_service.create_directory if @work.files_location != "file_upload"
7✔
79

80
    if params[:save_only] == "true"
7✔
81
      render :attachment_select
3✔
82
    else
83
      redirect_to file_location_url
4✔
84
    end
85
  end
86

87
  # Allow user to upload files directly
88
  # GET /works/1/file_upload
89
  def file_upload; end
1✔
90

91
  # POST /works/1/file_upload
92
  def file_uploaded
1✔
93
    files = pre_curation_uploads_param || []
5✔
94
    if files.count > 0
5✔
95
      upload_service = WorkUploadsEditService.new(@work, current_user)
4✔
96
      @work = upload_service.update_precurated_file_list(files, [])
4✔
97
      @work.reload_snapshots
3✔
98
    end
99
    if params[:save_only] == "true"
4✔
100
      render :file_upload
1✔
101
    else
102
      redirect_to(work_review_path)
3✔
103
    end
104
  rescue StandardError => active_storage_error
105
    Rails.logger.error("Failed to attach the file uploads for the work #{@work.doi}: #{active_storage_error}")
1✔
106
    flash[:notice] = "Failed to attach the file uploads for the work #{@work.doi}: #{active_storage_error}. Please contact rdss@princeton.edu for assistance."
1✔
107

108
    redirect_to work_file_upload_path(@work)
1✔
109
  end
110

111
  # Allow user to indicate where their files are located in the WWW
112
  # GET /works/1/file_other
113
  def file_other; end
1✔
114

115
  # GET /works/1/review
116
  # POST /works/1/review
117
  def review
1✔
118
    if request.method == "POST" || request.method == "PATCH"
8✔
119
      @work.location_notes = params["location_notes"]
4✔
120
      @work.save!
4✔
121
      if params[:save_only] == "true"
4✔
122
        render :file_other
2✔
123
      end
124
    end
125
  end
126

127
  # Validates that the work is ready to be approved
128
  # GET /works/1/validate
129
  def validate
1✔
130
    @work.submission_notes = params["submission_notes"]
27✔
131
    if params[:save_only] == "true"
27✔
132
      @work.save
1✔
133
      render :review
1✔
134
    else
135
      @work.complete_submission!(current_user)
26✔
136
      redirect_to user_url(current_user)
25✔
137
    end
138
  end
139

140
  # Show the user the form to select a readme
141
  # GET /works/1/readme_select
142
  def readme_select
1✔
143
    readme = Readme.new(@work, current_user)
6✔
144
    @readme = readme.file_name
6✔
145
  end
146

147
  # Uploads the readme the user selects
148
  # GET /works/1/readme_uploaded
149
  def readme_uploaded
1✔
150
    readme = Readme.new(@work, current_user)
4✔
151
    readme_error = readme.attach(readme_file_param)
4✔
152
    if readme_error.nil?
4✔
153
      if params[:save_only] == "true"
3✔
154
        @readme = readme.file_name
1✔
155
        render :readme_select
1✔
156
      else
157
        redirect_to work_attachment_select_url(@work)
2✔
158
      end
159
    else
160
      flash[:notice] = readme_error
1✔
161
      redirect_to work_readme_select_url(@work)
1✔
162
    end
163
  end
164

165
  def file_location_url
1✔
166
    WorkMetadataService.file_location_url(@work)
9✔
167
  end
168
  helper_method :file_location_url
1✔
169

170
  private
1✔
171

172
    def edit_helper(view_name, redirect_url)
1✔
173
      if validate_modification_permissions(work: @work,
29✔
174
                                           uneditable_message: "Can not update work: #{@work.id} is not editable by #{current_user.uid}",
175
                                           current_state_message: "Can not update work: #{@work.id} is not editable in current state by #{current_user.uid}")
176
        prepare_decorators_for_work_form(@work)
29✔
177
        if WorkCompareService.update_work(work: @work, update_params:, current_user:)
29✔
178
          if params[:save_only] == "true"
28✔
179
            render view_name
5✔
180
          else
181
            redirect_to redirect_url
23✔
182
          end
183
        else
184
          render view_name, status: :unprocessable_entity
1✔
185
        end
186
      end
187
    end
188

189
    def load_work
1✔
190
      @work = Work.find(params[:id])
147✔
191
    end
192

193
    def patch_params
1✔
194
      return {} unless params.key?(:patch)
18✔
195

196
      params[:patch]
16✔
197
    end
198

199
    def pre_curation_uploads_param
1✔
200
      return if patch_params.nil?
5✔
201

202
      patch_params[:pre_curation_uploads]
5✔
203
    end
204

205
    def readme_file_param
1✔
206
      return if patch_params.nil?
4✔
207

208
      patch_params[:readme_file]
4✔
209
    end
210

211
    def rescue_aasm_error
1✔
212
      super
49✔
213
    rescue StandardError => generic_error
UNCOV
214
      redirect_to root_url, notice: "We apologize, an error was encountered: #{generic_error.message}. Please contact the PDC Describe administrators."
×
215
    end
216

217
    def redirect_aasm_error(transition_error_message)
1✔
218
      if @work.persisted?
1✔
219
        redirect_to edit_work_wizard_path(id: @work.id), notice: transition_error_message, params:
1✔
220
      else
UNCOV
221
        redirect_to work_create_new_submission_path, notice: transition_error_message, params:
×
222
      end
223
    end
224
end
225
# rubocop:enable Metrics/ClassLength
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