diff --git a/app/controllers/support/providers/accredited_partners/checks_controller.rb b/app/controllers/support/providers/accredited_partners/checks_controller.rb new file mode 100644 index 0000000000..1c2531fba1 --- /dev/null +++ b/app/controllers/support/providers/accredited_partners/checks_controller.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +module Support + module Providers + module AccreditedPartners + class ChecksController < ApplicationController + include ClearStashable + + def show + accredited_provider_form + end + + def update + @partnership = provider.accredited_partnerships.build(accredited_provider_id: accredited_provider_form.accredited_provider_id, + description: accredited_provider_form.description) + if @partnership.save + notify_accredited_provider_users + + redirect_to support_recruitment_cycle_provider_accredited_partners_path( + recruitment_cycle.year, provider.id + ), flash: { success: 'Accredited partner added' } + else + render :show + end + end + + private + + def accredited_provider_form + @accredited_provider_form ||= ProviderPartnershipForm.new(current_user, new_partnership) + end + + def provider + @provider ||= recruitment_cycle.providers.find(params[:provider_id]) + end + + def new_partnership + @new_partnership = provider.accredited_partnerships.build + end + + def partner + Provider.find(accredited_provider_form.accredited_provider_id) + end + + def notify_accredited_provider_users + @partnership.accredited_provider.users.each do |user| + ::Users::OrganisationMailer.added_as_an_organisation_to_training_partner( + recipient: user, + provider: provider, + accredited_provider: @partnership.accredited_provider + ).deliver_later + end + end + end + end + end +end diff --git a/app/controllers/support/providers/accredited_partners_controller.rb b/app/controllers/support/providers/accredited_partners_controller.rb index 6c8cc61b72..09b63a8236 100644 --- a/app/controllers/support/providers/accredited_partners_controller.rb +++ b/app/controllers/support/providers/accredited_partners_controller.rb @@ -20,24 +20,26 @@ def new def edit provider - accredited_provider - @accredited_provider_form = ::AccreditedProviderForm.new(current_user, provider, params: provider.accredited_body(params[:accredited_provider_code])) + provider_partnership = provider.accredited_partnerships.find_by(accredited_provider: partner) + params = { accredited_provider_id: partner.id, description: provider_partnership.description } + @accredited_provider_form = ::ProviderPartnershipForm.new(current_user, provider_partnership, params:) end def create - @accredited_provider_form = ::AccreditedProviderForm.new(current_user, provider, params: accredited_provider_params) + @accredited_provider_form = ::ProviderPartnershipForm.new(current_user, provider, params: accredited_provider_params) if @accredited_provider_form.stash - redirect_to check_support_recruitment_cycle_provider_accredited_providers_path + redirect_to check_support_recruitment_cycle_provider_accredited_partners_path(accredited_provider_id: partnership_params[:accredited_provider_id]) else render :new end end def update - @accredited_provider_form = ::AccreditedProviderForm.new(current_user, provider, params: accredited_provider_params) + provider_partnership = provider.accredited_partnerships.find_by(accredited_provider: partner) + @accredited_provider_form = ::ProviderPartnershipForm.new(current_user, provider_partnership, params: accredited_provider_params) if @accredited_provider_form.save! - redirect_to support_recruitment_cycle_provider_accredited_providers_path( + redirect_to support_recruitment_cycle_provider_accredited_partners_path( recruitment_cycle_year: @recruitment_cycle.year, provider_id: @provider.id ) @@ -51,17 +53,17 @@ def update def delete cannot_delete + @accredited_provider = partner end def destroy return if cannot_delete - provider.accrediting_provider_enrichments = accrediting_provider_enrichments - provider.save + provider.accredited_partnerships.find_by(accredited_provider_id: partner.id).destroy flash[:success] = t('support.providers.accredited_providers.delete.updated') - redirect_to support_recruitment_cycle_provider_accredited_providers_path( + redirect_to support_recruitment_cycle_provider_accredited_partners_path( recruitment_cycle_year: @recruitment_cycle.year, provider_id: @provider.id ) @@ -70,17 +72,13 @@ def destroy private def cannot_delete - @cannot_delete ||= provider.courses.exists?(accredited_provider_code: accredited_provider.provider_code) + @cannot_delete ||= provider.courses.exists?(accredited_provider_code: partner.provider_code) end def accrediting_provider_enrichments provider.accrediting_provider_enrichments.reject { |enrichment| enrichment.UcasProviderCode == params['accredited_provider_code'] } end - def accredited_provider - @accredited_provider ||= @recruitment_cycle.providers.find_by(provider_code: params[:accredited_provider_code]) - end - def provider @provider ||= recruitment_cycle.providers.find(params[:provider_id]) end @@ -90,13 +88,26 @@ def accredited_provider_id end def accredited_provider_form - @accredited_provider_form ||= ::AccreditedProviderForm.new(current_user, provider) + @accredited_provider_form ||= ::ProviderPartnershipForm.new(current_user, partnership) end def accredited_provider_params - params.require(:accredited_provider_form) + params.require(:provider_partnership_form) .except(:goto_confirmation) - .permit(::AccreditedProviderForm::FIELDS) + .permit(::ProviderPartnershipForm::FIELDS) + end + + def partner + recruitment_cycle.providers.find_by(provider_code: params[:accredited_provider_code]) + end + + def partnership + @partnership = provider.accredited_partnerships.find_or_initialize_by(accredited_provider: partner) + @partnership.description ||= params[:description] + end + + def partnership_params + params.require(:provider_partnership_form).permit(:accredited_provider_id, :description) end end end diff --git a/app/controllers/support/providers/accredited_provider_search_controller.rb b/app/controllers/support/providers/accredited_provider_search_controller.rb index 8d7465e257..c3b5f92331 100644 --- a/app/controllers/support/providers/accredited_provider_search_controller.rb +++ b/app/controllers/support/providers/accredited_provider_search_controller.rb @@ -30,7 +30,7 @@ def update @accredited_provider_select_form = AccreditedProviderSelectForm.new(provider_id: accredited_provider_select_params[:provider_id]) if @accredited_provider_select_form.valid? - redirect_to new_support_recruitment_cycle_provider_accredited_provider_path(accredited_provider_id: accredited_provider_select_params[:provider_id]) + redirect_to new_support_recruitment_cycle_provider_accredited_partner_path(accredited_provider_id: accredited_provider_select_params[:provider_id]) else @accredited_provider_search = ::AccreditedProviders::SearchService.call(query:, recruitment_cycle_year: params[:recruitment_cycle_year]) render :results @@ -76,7 +76,7 @@ def search_result_title_component end def redirect_to_next_step - redirect_to new_support_recruitment_cycle_provider_accredited_provider_path(accredited_provider_id:) + redirect_to new_support_recruitment_cycle_provider_accredited_partner_path(accredited_provider_id:) end end end diff --git a/app/helpers/goto_confirmation_helper.rb b/app/helpers/goto_confirmation_helper.rb index 87423c5883..00f93be7ce 100644 --- a/app/helpers/goto_confirmation_helper.rb +++ b/app/helpers/goto_confirmation_helper.rb @@ -19,6 +19,16 @@ def back_link_for_onboarding_path(param_form_key:, params:, recruitment_cycle_ye end end + def back_link_for_adding_accredited_partner_path(param_form_key:, params:, recruitment_cycle_year:, provider:) + if goto_confirmation?(param_form_key:, params:) + check_support_recruitment_cycle_provider_accredited_partners_path(recruitment_cycle_year, provider) + elsif param_form_key == :support_accredited_provider_form + search_support_recruitment_cycle_provider_accredited_partners_path + else + support_recruitment_cycle_provider_accredited_partners_path(recruitment_cycle_year, provider) + end + end + def back_link_for_adding_accrediting_provider_path(param_form_key:, params:, recruitment_cycle_year:, provider:) if goto_confirmation?(param_form_key:, params:) check_support_recruitment_cycle_provider_accredited_providers_path(recruitment_cycle_year, provider) diff --git a/app/views/support/providers/accredited_partners/_can_remove.html.erb b/app/views/support/providers/accredited_partners/_can_remove.html.erb new file mode 100644 index 0000000000..c7b5169ae7 --- /dev/null +++ b/app/views/support/providers/accredited_partners/_can_remove.html.erb @@ -0,0 +1,22 @@ +<%= content_for :page_title, t("support.providers.accredited_providers.delete.title") %> +<% content_for :before_content do %> + <%= govuk_back_link_to(support_recruitment_cycle_provider_accredited_partners_path) %> +<% end %> + +
+ <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %> +
++ <%= @accredited_provider.provider_name %> is an + accredited partner for courses run by <%= @provider.provider_name %>. At least one of these courses is + currently published on Find. +
+ ++ <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %> +
++ <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %> +
++ <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %> +
+ + <% end %> + ++ <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %> +
+- <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_providers_path) %> + <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index f3d556321c..b47a3d1a50 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -730,6 +730,24 @@ en: new: title: *accredited_provider_title caption: &accredited_provider_caption "Add accredited provider - %{provider_name} (%{code})" + accredited_partners: + new: + title: About the accredited partner + hint: Tell candidates about the accredited partner. You could mention their academic specialities and achievements. + caption: "Add accredited partner - %{provider_name} (%{code})" + edit: + title: About the accredited partner + hint: Tell candidates about the accredited partner. You could mention their academic specialities and achievements. + caption: "%{provider_name}" + updated: About the accredited partner updated + delete: + title: Are you sure you want to remove this accredited partner? + remove: Remove accredited partner + updated: Accredited partner removed + checks: + show: + caption: "Add accredited partner - %{provider_name} (%{code})" + add: Add accredited partner accredited_providers: new: title: About the accredited provider diff --git a/config/routes/support.rb b/config/routes/support.rb index 1f077f4484..faa9c0f94d 100644 --- a/config/routes/support.rb +++ b/config/routes/support.rb @@ -63,21 +63,23 @@ end constraints(::Constraints::PartnershipFeature.new(:on)) do - resources :accredited_partners, param: :accredited_partner_code, only: %i[index new edit create update], path: 'accredited-partners' do + resources :accredited_partners, param: :accredited_provider_code, only: %i[index new edit create update], path: 'accredited-partners' do member do get :delete delete :delete, to: 'accredited_partners#destroy' end + get '/check', on: :collection, to: 'accredited_partners/checks#show' + put '/check', on: :collection, to: 'accredited_partners/checks#update' + end + + resources :accredited_providers, param: :accredited_provider_code, only: %i[], path: 'accredited-providers' do get '/search', on: :collection, to: 'accredited_provider_search#new' post '/search', on: :collection, to: 'accredited_provider_search#create' put '/search', on: :collection, to: 'accredited_provider_search#update' - - get '/check', on: :collection, to: 'accredited_providers/checks#show' - put '/check', on: :collection, to: 'accredited_providers/checks#update' end - resources :copy_courses, only: %i[new create] end + # rubocop:enable Style/RedundantConstantBase end end resources :users do diff --git a/spec/features/support/providers/accredited_partners_spec.rb b/spec/features/support/providers/accredited_partners_spec.rb index 96c645b68c..65210ca46b 100644 --- a/spec/features/support/providers/accredited_partners_spec.rb +++ b/spec/features/support/providers/accredited_partners_spec.rb @@ -20,24 +20,58 @@ then_i_should_see_the_accredited_provider_name_displayed end + scenario 'i can edit accredited providers on the index page' do + and_my_provider_has_accrediting_providers + and_i_click_on_the_accredited_provider_tab + and_i_click_change + + when_i_click_the_back_link + then_i_return_to_the_index_page + and_i_click_change + + when_i_input_updated_description + then_i_should_see_the_updated_description + and_i_see_the_success_message + end + + scenario 'i cannot delete accredited providers attached to a course' do + and_my_provider_has_accrediting_providers + and_i_click_on_the_accredited_provider_tab + and_i_click_remove + then_i_should_see_the_cannot_remove_text + end + + scenario 'i can delete accredited providers not attached to a course' do + and_i_click_on_the_accredited_provider_tab + and_i_click_add_accredited_provider + and_i_search_for_an_accredited_provider_with_a_valid_query + and_i_select_the_provider + when_i_input_new_information + and_i_confirm_the_changes + and_i_click_remove + and_i_click_remove_ap + then_i_return_to_the_index_page + and_i_see_the_remove_success_message + end + private def and_i_see_the_remove_success_message - expect(page).to have_content('Accredited provider removed') + expect(page).to have_content('Accredited partnership removed') end def and_i_see_the_remove_success_message; end def and_i_click_remove_ap - click_link_or_button 'Remove accredited provider' + click_link_or_button 'Remove accredited partner' end def and_i_confirm_the_changes - click_link_or_button 'Add accredited provider' + click_link_or_button 'Add accredited partner' end def when_i_input_new_information - fill_in 'About the accredited provider', with: 'New AP description' + fill_in 'About the accredited partner', with: 'New AP description' click_link_or_button 'Continue' end @@ -56,7 +90,7 @@ def and_i_search_for_an_accredited_provider_with_a_valid_query end def and_i_click_add_accredited_provider - click_link_or_button 'Add accredited provider' + click_link_or_button 'Add accredited partner' end def and_i_click_remove @@ -79,7 +113,7 @@ def and_there_are_accredited_providers_in_the_database end def then_i_return_to_the_index_page - expect(page).to have_current_path(support_recruitment_cycle_provider_accredited_partnerships_path( + expect(page).to have_current_path(support_recruitment_cycle_provider_accredited_partners_path( recruitment_cycle_year: Settings.current_recruitment_cycle_year, provider_id: @provider.id )) @@ -109,7 +143,7 @@ def then_i_should_see_the_updated_description end def when_i_input_updated_description - fill_in 'About the accredited provider', with: 'update the AP description' + fill_in 'About the accredited partner', with: 'update the AP description' click_link_or_button 'Update description' end