diff --git a/app/controllers/publish/courses/length_controller.rb b/app/controllers/publish/courses/length_controller.rb index cd7dab0544..40de3e5658 100644 --- a/app/controllers/publish/courses/length_controller.rb +++ b/app/controllers/publish/courses/length_controller.rb @@ -3,30 +3,22 @@ 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 @@ -34,9 +26,12 @@ def update 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 @@ -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