Class: WorksWizardController

Inherits:
ApplicationController show all
Includes:
ERB::Util
Defined in:
app/controllers/works_wizard_controller.rb

Overview

Controller to handle wizard Mode when editing an work

The wizard flow is shown in the [mermaid diagram here](github.com/pulibrary/pdc_describe/blob/main/docs/wizard_flow.md).

Direct Known Subclasses

WorksWizardUpdateAdditionalController

Instance Method Summary collapse

Methods inherited from ApplicationController

#new_session_path

Instance Method Details

#attachment_selectObject

Prompt to select how to submit their files GET /works/1/attachment_select



36
# File 'app/controllers/works_wizard_controller.rb', line 36

def attachment_select; end

#attachment_selectedObject

User selected a specific way to submit their files POST /works/1/attachment_selected



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/works_wizard_controller.rb', line 40

def attachment_selected
  @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"

  if params[:save_only] == "true"
    render :attachment_select
  else
    redirect_to file_location_url
  end
end

#edit_wizardObject

GET /works/1/edit-wizard



19
20
21
22
23
24
25
26
27
# File 'app/controllers/works_wizard_controller.rb', line 19

def edit_wizard
  @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}")

    prepare_decorators_for_work_form(@work)
  end
end

#file_location_urlObject



165
166
167
# File 'app/controllers/works_wizard_controller.rb', line 165

def file_location_url
  WorkMetadataService.file_location_url(@work)
end

#file_otherObject

Allow user to indicate where their files are located in the WWW GET /works/1/file_other



94
# File 'app/controllers/works_wizard_controller.rb', line 94

def file_other; end

#file_uploadObject

Allow user to upload files directly GET /works/1/file_upload



56
57
58
# File 'app/controllers/works_wizard_controller.rb', line 56

def file_upload
  @work_decorator = WorkDecorator.new(@work, current_user)
end

#file_uploadedObject

POST /works/1/file_upload



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/works_wizard_controller.rb', line 68

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

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

  redirect_to work_file_upload_path(@work)
end

#files_paramObject



143
144
145
# File 'app/controllers/works_wizard_controller.rb', line 143

def files_param
  params["files"]
end

#readme_selectObject

Show the user the form to select a readme GET /works/1/readme_select



125
126
127
128
# File 'app/controllers/works_wizard_controller.rb', line 125

def readme_select
  readme = Readme.new(@work, current_user)
  @readme = readme.file_name
end

#readme_uploadedObject

Hit when the user clicks “Save” or “Next” on the README upload process. Notice that this does not really uploads the file, that happens in readme_uploaded_payload. PATCH /works/1/readme_uploaded



133
134
135
136
137
138
139
140
141
# File 'app/controllers/works_wizard_controller.rb', line 133

def readme_uploaded
  readme = Readme.new(@work, current_user)
  if params[:save_only] == "true"
    @readme = readme.file_name
    render :readme_select
  else
    redirect_to work_attachment_select_url(@work)
  end
end

#readme_uploaded_payloadObject

Uploads the README file, called by Uppy. POST /works/1/readme-uploaded-payload



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'app/controllers/works_wizard_controller.rb', line 149

def readme_uploaded_payload
  raise StandardError("Only one README file can be uploaded.") if files_param.empty?
  raise StandardError("Only one README file can be uploaded.") if files_param.length > 1

  readme_file = files_param.first
  readme = Readme.new(@work, current_user)

  readme_error = readme.attach(readme_file)
  if readme_error.nil?
    render plain: readme.file_name
  else
    # Tell Uppy there was an error uploading the README
    render plain: readme.file_name, status: :internal_server_error
  end
end

#reviewObject

GET /works/1/review POST /works/1/review



98
99
100
101
102
103
104
105
106
# File 'app/controllers/works_wizard_controller.rb', line 98

def review
  if request.method == "POST" || request.method == "PATCH"
    @work.location_notes = params["location_notes"]
    @work.save!
    if params[:save_only] == "true"
      render :file_other
    end
  end
end

#update_wizardObject

PATCH /works/1/update-wizard



30
31
32
# File 'app/controllers/works_wizard_controller.rb', line 30

def update_wizard
  edit_helper(:edit_wizard, work_update_additional_path(@work))
end

#upload_filesObject

POST /works/1/upload-files-wizard (called via Uppy)



61
62
63
64
65
# File 'app/controllers/works_wizard_controller.rb', line 61

def upload_files
  @work = Work.find(params[:id])
  upload_service = WorkUploadsEditService.new(@work, current_user)
  upload_service.update_precurated_file_list(params["files"], [])
end

#validateObject

Validates that the work is ready to be approved POST /works/1/validate-wizard PATCH /works/1/validate-wizard



111
112
113
114
115
116
117
118
119
120
121
# File 'app/controllers/works_wizard_controller.rb', line 111

def validate
  @work.submission_notes = params["submission_notes"]

  if params[:save_only] == "true"
    @work.save
    render :review
  else
    @work.complete_submission!(current_user)
    redirect_to work_complete_path(@work.id)
  end
end