-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RatifyingCourses flow for courses namespace
- Loading branch information
1 parent
681f959
commit 13ca674
Showing
37 changed files
with
2,007 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<% if required_organisation_details_present? %> | ||
<%= govuk_button_link_to( | ||
"Add course", | ||
new_publish_provider_recruitment_cycle_course_path( | ||
provider_code: provider.provider_code, | ||
recruitment_cycle_year: provider.recruitment_cycle_year | ||
), | ||
class: "govuk-!-margin-bottom-6" | ||
) %> | ||
|
||
<% else %> | ||
|
||
<div class="govuk-inset-text"> | ||
<p class="govuk-body">Before adding a course, you need to:</p> | ||
<ul class="govuk-list govuk-list--bullet"> | ||
<% incomplete_sections.each do |section| %> | ||
<li> | ||
<%= govuk_link_to(section.name, section.path) %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddCourseButtonPartnerships < ViewComponent::Base | ||
include RecruitmentCycleHelper | ||
attr_reader :provider | ||
|
||
Section = Struct.new(:name, :path, keyword_init: true) | ||
|
||
def initialize(provider:) | ||
@provider = provider | ||
super | ||
end | ||
|
||
private | ||
|
||
def incomplete_sections | ||
incomplete_sections_hash.keys.select { |section| send(section) }.map do |section| | ||
Section.new(name: "add #{incomplete_section_article(section)} #{incomplete_section_label_suffix(section)}", path: incomplete_sections_hash[section]) | ||
end | ||
end | ||
|
||
def incomplete_sections_hash | ||
{ | ||
site_not_present?: publish_provider_recruitment_cycle_schools_path(provider.provider_code, provider.recruitment_cycle_year), | ||
accredited_partner_not_present?: publish_provider_recruitment_cycle_accredited_partnerships_path(provider.provider_code, provider.recruitment_cycle_year) | ||
} | ||
end | ||
|
||
def incomplete_section_label_suffix(section) | ||
labels = { | ||
accredited_partner_not_present?: 'accredited partner', | ||
site_not_present?: 'school' | ||
} | ||
|
||
labels[section] | ||
end | ||
|
||
def required_organisation_details_present? | ||
accredited_partner_present? && site_present? | ||
end | ||
|
||
def accredited_partner_present? | ||
return true if accredited_provider? | ||
|
||
provider.accredited_partners.any? | ||
end | ||
|
||
def site_present? | ||
provider.sites.any? | ||
end | ||
|
||
def accredited_partner_not_present? | ||
return false if provider.accredited_provider? | ||
|
||
!accredited_partner_present? | ||
end | ||
|
||
def site_not_present? | ||
!site_present? | ||
end | ||
|
||
def accredited_provider? | ||
provider.accredited_provider? | ||
end | ||
|
||
def incomplete_section_article(section) | ||
incomplete_section_label_suffix(section) == 'accredited partner' ? 'an' : 'a' | ||
end | ||
end |
172 changes: 172 additions & 0 deletions
172
app/controllers/publish/courses/ratifying_provider_controller.rb
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 |
---|---|---|
@@ -0,0 +1,172 @@ | ||
# frozen_string_literal: true | ||
|
||
module Publish | ||
module Courses | ||
class RatifyingProviderController < PublishController | ||
include CourseBasicDetailConcern | ||
before_action :build_course, only: %i[edit update] | ||
before_action :build_course_params, only: :continue | ||
helper_method :accredited_partners | ||
|
||
def accredited_partners | ||
if Settings.features.provider_partnerships | ||
@provider.accredited_partners | ||
else | ||
@provider.accredited_bodies | ||
end | ||
end | ||
|
||
def show | ||
@course = build_course&.decorate | ||
render_not_found if @course.accrediting_provider.blank? | ||
end | ||
|
||
def edit | ||
build_provider | ||
end | ||
|
||
def continue | ||
authorize(@provider, :can_create_course?) | ||
|
||
code = course_params[:accredited_provider_code] | ||
query = @accredited_provider | ||
|
||
@errors = errors_for_search_query(code, query) | ||
|
||
if @errors.present? | ||
render :new | ||
elsif other_selected_with_no_autocompleted_code?(code) | ||
redirect_to( | ||
search_new_publish_provider_recruitment_cycle_courses_accredited_provider_path( | ||
query: @accredited_provider, | ||
course: course_params | ||
) | ||
) | ||
else | ||
params[:course][:accredited_provider_code] = @autocompleted_provider_code if @autocompleted_provider_code.present? | ||
super | ||
end | ||
end | ||
|
||
def search_new | ||
authorize(provider, :can_create_course?) | ||
|
||
# These are not before_action hooks as they conflict with hooks | ||
# defined within the CourseBasicDetailConcern and cannot be overridden | ||
# without causing failures in other routes in this controller | ||
build_new_course | ||
build_provider | ||
build_previous_course_creation_params | ||
@query = params[:query] | ||
@provider_suggestions = recruitment_cycle.providers.with_findable_courses.provider_search(@query).limit(10) | ||
end | ||
|
||
def update | ||
build_provider | ||
begin | ||
code = update_course_params[:accredited_provider_code] | ||
query = update_course_params[:accredited_provider] | ||
rescue ActionController::ParameterMissing | ||
@errors = errors_for_search_query(code, query) | ||
return render :edit if @errors.present? | ||
end | ||
|
||
if update_params[:accredited_provider_code] == 'other' | ||
redirect_to_provider_search | ||
elsif @course.update(update_params) | ||
course_updated_message('Accredited provider') | ||
redirect_to_update_successful | ||
else | ||
@errors = @course.errors.messages | ||
render :edit | ||
end | ||
end | ||
|
||
def search | ||
build_course | ||
@query = params[:query] | ||
@provider_suggestions = recruitment_cycle.providers.with_findable_courses.provider_search(@query).limit(10) | ||
end | ||
|
||
private | ||
|
||
def build_provider | ||
@provider = RecruitmentCycle.find_by(year: params[:recruitment_cycle_year]) | ||
.providers | ||
.find_by(provider_code: params[:provider_code]) | ||
end | ||
|
||
def error_keys | ||
[:accredited_provider_code] | ||
end | ||
|
||
def redirect_to_provider_search | ||
redirect_to( | ||
accredited_provider_search_provider_recruitment_cycle_course_path( | ||
@course.provider_code, | ||
@course.recruitment_cycle_year, | ||
@course.course_code, | ||
query: update_course_params[:accredited_provider] | ||
) | ||
) | ||
end | ||
|
||
def redirect_to_update_successful | ||
redirect_to( | ||
details_publish_provider_recruitment_cycle_course_path( | ||
@course.provider_code, | ||
@course.recruitment_cycle_year, | ||
@course.course_code | ||
) | ||
) | ||
end | ||
|
||
def current_step | ||
:accredited_provider | ||
end | ||
|
||
def build_course_params | ||
@accredited_provider = params[:course].delete(:accredited_provider) | ||
@autocompleted_provider_code = params[:course].delete(:autocompleted_provider_code) | ||
end | ||
|
||
def errors_for_search_query(code, query) | ||
errors = {} | ||
|
||
if other_selected_with_no_autocompleted_code?(code) && query.length < 2 | ||
errors = { accredited_provider: ['Accredited provider search too short, enter 2 or more characters'] } | ||
elsif code.blank? | ||
errors = { accredited_provider_code: ['Select an accredited provider'] } | ||
end | ||
|
||
errors | ||
end | ||
|
||
def update_course_params | ||
params.require(:course).permit( | ||
:autocompleted_provider_code, | ||
:accredited_provider_code, | ||
:accredited_provider | ||
) | ||
end | ||
|
||
def update_params | ||
autocompleted_code = update_course_params[:autocompleted_provider_code] | ||
code = update_course_params[:accredited_provider_code] | ||
|
||
{ | ||
accredited_provider_code: autocompleted_code.presence || code | ||
} | ||
end | ||
|
||
def other_selected_with_no_autocompleted_code?(code) | ||
code == 'other' && @autocompleted_provider_code.blank? | ||
end | ||
|
||
def build_course | ||
super | ||
authorize @course | ||
end | ||
end | ||
end | ||
end |
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
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
Oops, something went wrong.