-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added save_only parameter processing to Wizard Controller update meth…
…ods (#1721) * Added save_only parameter processing to update_wizard save_only returns the user to the edit screen after saving instead of redirecting to the next step * adding a save check for new submissions that keeps the user on the current page * Updating test to pass valid paramaters * Adding save only to readme_uploaded * Updating to allow for save_only in review and file location select * Letting rubocop fix some of the violations * Allow file uploaded to stay on page on save * added save only to validate This completes the work, except for the fact that rubocop is not happy with the class now * Moving decorator creation to application controller so wizard and work form can share * Moving update process into compare service fixes a rubocop violation * fixing rubocop issue for file upload in the works wizard controller * fixing rubocop errors * Fixing code to make tests pass * add test for the WorkCompareServie * Updatign for rubocop --------- Co-authored-by: HyppoliteJ <[email protected]>
- Loading branch information
1 parent
08381e8
commit 5ba0354
Showing
6 changed files
with
279 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,12 @@ class WorksWizardController < ApplicationController | |
:readme_select, :readme_uploaded] | ||
|
||
# get Renders the "step 0" information page before creating a new dataset | ||
# GET /works/1/new_submission | ||
# GET /works/new_submission | ||
def new_submission | ||
group = Group.find_by(code: params[:group_code]) || current_user.default_group | ||
group_id = group.id | ||
@work = Work.new(created_by_user_id: current_user.id, group_id:) | ||
@work_decorator = WorkDecorator.new(@work, current_user) | ||
@form_resource_decorator = FormResourceDecorator.new(@work, current_user) | ||
prepare_decorators_for_work_form(@work) | ||
end | ||
|
||
# Creates the new dataset | ||
|
@@ -36,18 +35,22 @@ def new_submission_save | |
@work = Work.new(created_by_user_id: current_user.id, group_id:) | ||
@work.resource = FormToResourceService.convert(params, @work) | ||
@work.draft!(current_user) | ||
redirect_to edit_work_wizard_path(@work) | ||
if params[:save_only] == "true" | ||
prepare_decorators_for_work_form(@work) | ||
render :new_submission | ||
else | ||
redirect_to edit_work_wizard_path(@work) | ||
end | ||
end | ||
|
||
# GET /works/1/edit_wizard | ||
# GET /works/1/edit-wizard | ||
def edit_wizard | ||
@work_decorator = WorkDecorator.new(@work, current_user) | ||
@wizard_mode = true | ||
if validate_modification_permissions(work: @work, | ||
uneditable_message: "Can not edit work: #{@work.id} is not editable by #{current_user.uid}", | ||
current_state_message: "Can not edit work: #{@work.id} is not editable in current state by #{current_user.uid}") | ||
|
||
@form_resource_decorator = FormResourceDecorator.new(@work, current_user) | ||
prepare_decorators_for_work_form(@work) | ||
end | ||
end | ||
|
||
|
@@ -56,44 +59,39 @@ def update_wizard | |
if validate_modification_permissions(work: @work, | ||
uneditable_message: "Can not update work: #{@work.id} is not editable by #{current_user.uid}", | ||
current_state_message: "Can not update work: #{@work.id} is not editable in current state by #{current_user.uid}") | ||
work_before = @work.dup | ||
if @work.update(update_params) | ||
work_compare = WorkCompareService.new(work_before, @work) | ||
@work.log_changes(work_compare, current_user.id) | ||
|
||
redirect_to work_readme_select_url(@work) | ||
prepare_decorators_for_work_form(@work) | ||
if WorkCompareService.update_work(work: @work, update_params:, current_user:) | ||
if params[:save_only] == "true" | ||
render :edit_wizard | ||
else | ||
redirect_to work_readme_select_url(@work) | ||
end | ||
else | ||
# This is needed for rendering HTML views with validation errors | ||
@form_resource_decorator = FormResourceDecorator.new(@work, current_user) | ||
|
||
render :edit_wizard, status: :unprocessable_entity | ||
end | ||
end | ||
end | ||
|
||
# Prompt to select how to submit their files | ||
# GET /works/1/attachment_select | ||
def attachment_select | ||
@wizard_mode = true | ||
end | ||
def attachment_select; end | ||
|
||
# User selected a specific way to submit their files | ||
# POST /works/1/attachment_selected | ||
def attachment_selected | ||
@wizard_mode = true | ||
@work.files_location = params["attachment_type"] | ||
@work.save! | ||
|
||
# create a directory for the work if the curator will need to move files by hand | ||
@work.s3_query_service.create_directory if @work.files_location != "file_upload" | ||
|
||
next_url = case @work.files_location | ||
when "file_upload" | ||
work_file_upload_url(@work) | ||
else | ||
work_file_other_url(@work) | ||
end | ||
redirect_to next_url | ||
if params[:save_only] == "true" | ||
render :attachment_select | ||
elsif @work.files_location == "file_upload" | ||
redirect_to work_file_upload_url(@work) | ||
else | ||
redirect_to work_file_other_url(@work) | ||
end | ||
end | ||
|
||
# Allow user to upload files directly | ||
|
@@ -106,10 +104,13 @@ def file_uploaded | |
if files.count > 0 | ||
upload_service = WorkUploadsEditService.new(@work, current_user) | ||
@work = upload_service.update_precurated_file_list(files, []) | ||
@work.save! | ||
@work.reload_snapshots | ||
end | ||
redirect_to(work_review_path) | ||
if params[:save_only] == "true" | ||
render :file_upload | ||
else | ||
redirect_to(work_review_path) | ||
end | ||
rescue StandardError => active_storage_error | ||
Rails.logger.error("Failed to attach the file uploads for the work #{@work.doi}: #{active_storage_error}") | ||
flash[:notice] = "Failed to attach the file uploads for the work #{@work.doi}: #{active_storage_error}. Please contact [email protected] for assistance." | ||
|
@@ -127,6 +128,9 @@ def review | |
if request.method == "POST" | ||
@work.location_notes = params["location_notes"] | ||
@work.save! | ||
if params[:save_only] == "true" | ||
render :file_other | ||
end | ||
end | ||
end | ||
|
||
|
@@ -135,25 +139,32 @@ def review | |
def validate | ||
@work.submission_notes = params["submission_notes"] | ||
@work.complete_submission!(current_user) | ||
redirect_to user_url(current_user) | ||
if params[:save_only] == "true" | ||
render :review | ||
else | ||
redirect_to user_url(current_user) | ||
end | ||
end | ||
|
||
# Show the user the form to select a readme | ||
# GET /works/1/readme_select | ||
def readme_select | ||
readme = Readme.new(@work, current_user) | ||
@readme = readme.file_name | ||
@wizard = true | ||
end | ||
|
||
# Uploads the readme the user selects | ||
# GET /works/1/readme_uploaded | ||
def readme_uploaded | ||
@wizard = true | ||
readme = Readme.new(@work, current_user) | ||
readme_error = readme.attach(readme_file_param) | ||
if readme_error.nil? | ||
redirect_to work_attachment_select_url(@work) | ||
if params[:save_only] == "true" | ||
@readme = readme.file_name | ||
render :readme_select | ||
else | ||
redirect_to work_attachment_select_url(@work) | ||
end | ||
else | ||
flash[:notice] = readme_error | ||
redirect_to work_readme_select_url(@work) | ||
|
@@ -192,11 +203,11 @@ def rescue_aasm_error | |
Honeybadger.notify("Invalid #{@work.current_transition}: #{error.message} errors: #{message}") | ||
transition_error_message = "We apologize, the following errors were encountered: #{message}. Please contact the PDC Describe administrators for any assistance." | ||
@errors = [transition_error_message] | ||
prepare_decorators_for_work_form(@work) | ||
|
||
if @work.persisted? | ||
redirect_to edit_work_wizard_path(id: @work.id), notice: transition_error_message, params: | ||
else | ||
@form_resource_decorator = FormResourceDecorator.new(@work, current_user) | ||
redirect_to work_create_new_submission_path, notice: transition_error_message, params: | ||
end | ||
rescue StandardError => generic_error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.