Skip to content

Commit

Permalink
[1697] Working WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
avinhurry committed May 23, 2024
1 parent 1ed395d commit e7c93f9
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 18 deletions.
13 changes: 11 additions & 2 deletions app/controllers/publish/courses/funding_type_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ def update
@course_funding_form = CourseFundingForm.new(@course, params: funding_type_params)

if @course_funding_form.valid?
redirect_to(next_path)
if params[:publish_course_funding_form][:previous_tda_course] == 'true'

@course_funding_form.save! if @course_funding_form.funding_type_updated?

redirect_to full_part_time_publish_provider_recruitment_cycle_course_path(provider_code: course.provider_code,
recruitment_cycle_year: course.recruitment_cycle_year,
course_code: course.course_code, previous_tda_course: true)
else
redirect_to(next_path)
end
else
@errors = @course_funding_form.errors.messages
render :edit
Expand All @@ -45,7 +54,7 @@ def update
def funding_type_params
return {} if params[:publish_course_funding_form].blank?

params.require(:publish_course_funding_form).permit(:funding_type)
params.require(:publish_course_funding_form).permit(:funding_type, :previous_tda_course)
end

def next_path
Expand Down
50 changes: 42 additions & 8 deletions app/controllers/publish/courses/outcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,52 @@ def update
@errors = errors
return render :edit if @errors.present?

@current_qualification = @course.qualification
@updated_qualification = params[:course][:qualification]

if @course.update(course_params)
@course.update_default_attributes_for_undergraduate_degree_with_qts
if @updated_qualification == 'undergraduate_degree_with_qts'
@course.update(
study_mode: 'full_time',
funding_type: 'apprenticeship',
can_sponsor_skilled_worker_visa: false,
can_sponsor_student_visa: false
)

course_updated_message('Qualification')

redirect_to(
details_publish_provider_recruitment_cycle_course_path(
@course.provider_code,
@course.recruitment_cycle_year,
@course.course_code
)
)
elsif @current_qualification == 'undergraduate_degree_with_qts' && @updated_qualification != 'undergraduate_degree_with_qts'

course_updated_message('Qualification')
redirect_to(
funding_type_publish_provider_recruitment_cycle_course_path(
@course.provider_code,
@course.recruitment_cycle_year,
@course.course_code,
previous_tda_course: true
)
)

else

redirect_to(
details_publish_provider_recruitment_cycle_course_path(
@course.provider_code,
@course.recruitment_cycle_year,
@course.course_code
redirect_to(
funding_type_publish_provider_recruitment_cycle_course_path(
@course.provider_code,
@course.recruitment_cycle_year,
@course.course_code
)
)
)

course_updated_message('Qualification')

end

else
@errors = @course.errors.messages
render :edit
Expand Down
28 changes: 21 additions & 7 deletions app/controllers/publish/courses/study_mode_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,27 @@ def update

@course_study_mode_form = CourseStudyModeForm.new(@course, params: study_mode_params)
if @course_study_mode_form.save!
course_updated_message I18n.t('publish.providers.study_mode.form.study_pattern')

redirect_to details_publish_provider_recruitment_cycle_course_path(
provider.provider_code,
recruitment_cycle.year,
course.course_code
)
if params[:publish_course_study_mode_form][:previous_tda_course] == 'true'
if @course.student_visa?
redirect_to student_visa_sponsorship_publish_provider_recruitment_cycle_course_path(provider_code: course.provider_code,
recruitment_cycle_year: course.recruitment_cycle_year,
course_code: course.course_code)
else
redirect_to skilled_worker_visa_sponsorship_publish_provider_recruitment_cycle_course_path(provider_code: course.provider_code,
recruitment_cycle_year: course.recruitment_cycle_year,
course_code: course.course_code)
end

else
course_updated_message I18n.t('publish.providers.study_mode.form.study_pattern')

redirect_to details_publish_provider_recruitment_cycle_course_path(
provider.provider_code,
recruitment_cycle.year,
course.course_code
)
end
else
render :edit
end
Expand All @@ -33,7 +47,7 @@ def update
def study_mode_params
return { study_mode: nil } if params[:publish_course_study_mode_form].blank?

params.require(:publish_course_study_mode_form).permit(study_mode: [])
params.require(:publish_course_study_mode_form).permit(:previous_tda_course, study_mode: [])
end

def current_step
Expand Down
5 changes: 5 additions & 0 deletions app/forms/publish/course_funding_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CourseFundingForm < Form
funding_type
can_sponsor_skilled_worker_visa
can_sponsor_student_visa
previous_tda_course
].freeze

attr_accessor(*FIELDS)
Expand Down Expand Up @@ -52,6 +53,10 @@ def skilled_worker_visa?
visa_type == :skilled_worker
end

def fields_to_ignore_before_save
super + [:previous_tda_course]
end

private

def reset_enrichment_attributes
Expand Down
3 changes: 2 additions & 1 deletion app/models/concerns/publish/course_basic_detail_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def course_params
:goto_confirmation,
:skip_languages_goto_confirmation,
:goto_visa,
:language_ids
:language_ids,
:previous_tda_course
).permit(
policy(Course.new).permitted_new_course_attributes,
study_mode: [],
Expand Down
8 changes: 8 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,14 @@ def is_fee_based?
funding_type == 'fee'
end

def visa_type
is_fee_based? ? :student : :skilled_worker
end

def student_visa?
visa_type == :student
end

# https://www.gov.uk/government/publications/initial-teacher-training-criteria/initial-teacher-training-itt-criteria-and-supporting-advice#c11-gcse-standard-equivalent
def gcse_subjects_required
case level
Expand Down
2 changes: 2 additions & 0 deletions app/views/publish/courses/funding_type/_form_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@
data: { qa: "course__funding_type_apprenticeship" } %>
</div>
</div>

<%= form.hidden_field :previous_tda_course, value: params[:previous_tda_course] %>
</fieldset>
<% end %>
2 changes: 2 additions & 0 deletions app/views/publish/courses/study_mode/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<% end %>
<% end %>

<%= f.hidden_field :previous_tda_course, value: params[:previous_tda_course] %>

<%= f.govuk_submit "Update #{page_title.downcase}" %>
<% end %>

Expand Down

0 comments on commit e7c93f9

Please sign in to comment.