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

pulibrary / pdc_describe / 4250c284-5797-493e-ae72-0031c71662ee

09 Apr 2024 03:40PM UTC coverage: 95.838% (-0.02%) from 95.857%
4250c284-5797-493e-ae72-0031c71662ee

push

circleci

jrgriffiniii
Adding a new policy page to the front of the wizard
fixes #1688

12 of 14 new or added lines in 3 files covered. (85.71%)

1 existing line in 1 file now uncovered.

3247 of 3388 relevant lines covered (95.84%)

210.09 hits per line

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

98.0
/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 -> update_additional -> update_additional_save ->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]
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
14✔
25
    prepare_decorators_for_work_form(@work)
14✔
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
10✔
32
    @errors = @work.errors.to_a
10✔
33
    if @errors.count.positive?
10✔
34
      prepare_decorators_for_work_form(@work)
1✔
35
      render :new_submission
1✔
36
    else
37
      redirect_to edit_work_wizard_path(@work)
9✔
38
    end
39
  end
40

41
  # GET /works/1/edit-wizard
42
  def edit_wizard
1✔
43
    @wizard_mode = true
11✔
44
    if validate_modification_permissions(work: @work,
11✔
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)
11✔
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))
12✔
55
  end
56

57
  # Prompt to select how to submit their files
58
  # GET /works/1/attachment_select
59
  def attachment_select; end
1✔
60

61
  # User selected a specific way to submit their files
62
  # POST /works/1/attachment_selected
63
  def attachment_selected
1✔
64
    @work.files_location = params["attachment_type"]
15✔
65
    @work.save!
15✔
66

67
    # create a directory for the work if the curator will need to move files by hand
68
    @work.s3_query_service.create_directory if @work.files_location != "file_upload"
15✔
69

70
    if params[:save_only] == "true"
15✔
71
      render :attachment_select
4✔
72
    else
73
      redirect_to file_location_url
11✔
74
    end
75
  end
76

77
  # Allow user to upload files directly
78
  # GET /works/1/file_upload
79
  def file_upload; end
1✔
80

81
  # POST /works/1/file_upload
82
  def file_uploaded
1✔
83
    files = pre_curation_uploads_param || []
10✔
84
    if files.count > 0
10✔
85
      upload_service = WorkUploadsEditService.new(@work, current_user)
4✔
86
      @work = upload_service.update_precurated_file_list(files, [])
4✔
87
      @work.reload_snapshots
3✔
88
    end
89
    if params[:save_only] == "true"
9✔
90
      render :file_upload
2✔
91
    else
92
      redirect_to(work_review_path)
7✔
93
    end
94
  rescue StandardError => active_storage_error
95
    Rails.logger.error("Failed to attach the file uploads for the work #{@work.doi}: #{active_storage_error}")
1✔
96
    flash[:notice] = "Failed to attach the file uploads for the work #{@work.doi}: #{active_storage_error}. Please contact rdss@princeton.edu for assistance."
1✔
97

98
    redirect_to work_file_upload_path(@work)
1✔
99
  end
100

101
  # Allow user to indicate where their files are located in the WWW
102
  # GET /works/1/file_other
103
  def file_other; end
1✔
104

105
  # GET /works/1/review
106
  # POST /works/1/review
107
  def review
1✔
108
    if request.method == "POST" || request.method == "PATCH"
13✔
109
      @work.location_notes = params["location_notes"]
7✔
110
      @work.save!
7✔
111
      if params[:save_only] == "true"
7✔
112
        render :file_other
2✔
113
      end
114
    end
115
  end
116

117
  # Validates that the work is ready to be approved
118
  # GET /works/1/validate
119
  def validate
1✔
120
    @work.submission_notes = params["submission_notes"]
33✔
121
    if params[:save_only] == "true"
33✔
122
      @work.save
2✔
123
      render :review
2✔
124
    else
125
      @work.complete_submission!(current_user)
31✔
126
      redirect_to user_url(current_user)
30✔
127
    end
128
  end
129

130
  # Show the user the form to select a readme
131
  # GET /works/1/readme_select
132
  def readme_select
1✔
133
    readme = Readme.new(@work, current_user)
14✔
134
    @readme = readme.file_name
14✔
135
  end
136

137
  # Uploads the readme the user selects
138
  # GET /works/1/readme_uploaded
139
  def readme_uploaded
1✔
140
    readme = Readme.new(@work, current_user)
13✔
141
    readme_error = readme.attach(readme_file_param)
13✔
142
    if readme_error.nil?
13✔
143
      if params[:save_only] == "true"
12✔
144
        @readme = readme.file_name
2✔
145
        render :readme_select
2✔
146
      else
147
        redirect_to work_attachment_select_url(@work)
10✔
148
      end
149
    else
150
      flash[:notice] = readme_error
1✔
151
      redirect_to work_readme_select_url(@work)
1✔
152
    end
153
  end
154

155
  def file_location_url
1✔
156
    WorkMetadataService.file_location_url(@work)
22✔
157
  end
158
  helper_method :file_location_url
1✔
159

160
  private
1✔
161

162
    def edit_helper(view_name, redirect_url)
1✔
163
      if validate_modification_permissions(work: @work,
22✔
164
                                           uneditable_message: "Can not update work: #{@work.id} is not editable by #{current_user.uid}",
165
                                           current_state_message: "Can not update work: #{@work.id} is not editable in current state by #{current_user.uid}")
166
        prepare_decorators_for_work_form(@work)
22✔
167
        if WorkCompareService.update_work(work: @work, update_params:, current_user:)
22✔
168
          if params[:save_only] == "true"
21✔
169
            render view_name
3✔
170
          else
171
            redirect_to redirect_url
18✔
172
          end
173
        else
174
          render view_name, status: :unprocessable_entity
1✔
175
        end
176
      end
177
    end
178

179
    def load_work
1✔
180
      @work = Work.find(params[:id])
170✔
181
    end
182

183
    def patch_params
1✔
184
      return {} unless params.key?(:patch)
46✔
185

186
      params[:patch]
24✔
187
    end
188

189
    def pre_curation_uploads_param
1✔
190
      return if patch_params.nil?
10✔
191

192
      patch_params[:pre_curation_uploads]
10✔
193
    end
194

195
    def readme_file_param
1✔
196
      return if patch_params.nil?
13✔
197

198
      patch_params[:readme_file]
13✔
199
    end
200

201
    def rescue_aasm_error
1✔
202
      super
43✔
203
    rescue StandardError => generic_error
204
      redirect_to root_url, notice: "We apologize, an error was encountered: #{generic_error.message}. Please contact the PDC Describe administrators."
×
205
    end
206

207
    def redirect_aasm_error(transition_error_message)
1✔
208
      if @work.persisted?
1✔
209
        redirect_to edit_work_wizard_path(id: @work.id), notice: transition_error_message, params:
1✔
210
      else
NEW
211
        redirect_to work_create_new_submission_path(@work), notice: transition_error_message, params:
×
212
      end
213
    end
214
end
215
# 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