Skip to content

Commit

Permalink
Little refactor / clean up of controller
Browse files Browse the repository at this point in the history
  • Loading branch information
elceebee committed May 22, 2024
1 parent ade1bf3 commit 6c366ad
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions app/controllers/publish/courses/length_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,35 @@
module Publish
module Courses
class LengthController < PublishController
before_action :authorise_with_pundit
before_action :redirect_if_not_editable

def edit
authorize(provider)

@course_length_form = CourseLengthForm.new(course_enrichment)

@course_length_form.valid? if show_errors_on_publish?
end

def update
authorize(provider)

@course_length_form = CourseLengthForm.new(course_enrichment, params: length_params)

if @course_length_form.save!
course_updated_message I18n.t('publish.providers.course_length.edit.course_length')

redirect_to publish_provider_recruitment_cycle_course_path(
provider.provider_code,
recruitment_cycle.year,
course.course_code
)

redirect_to redirect_path
else
render :edit
end
end

private

def authorise_with_pundit
authorize provider
end

def length_params
params.require(:publish_course_length_form)
.permit(*CourseLengthForm::FIELDS)
params.require(:publish_course_length_form).permit(*CourseLengthForm::FIELDS)
end

def course
Expand All @@ -50,7 +45,11 @@ def course_enrichment
def redirect_if_not_editable
return unless course.cannot_change_course_length?

redirect_to publish_provider_recruitment_cycle_course_path(
redirect_to redirect_path
end

def redirect_path
publish_provider_recruitment_cycle_course_path(
provider.provider_code,
recruitment_cycle.year,
course.course_code
Expand Down

0 comments on commit 6c366ad

Please sign in to comment.