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 %> + +
+
+

+ <%= @accredited_provider.provider_name %> + <%= t("support.providers.accredited_partners.delete.title") %> +

+ + <%= govuk_button_to "Remove accredited partner", + delete_support_recruitment_cycle_provider_accredited_partner_path, + method: :delete, + class: "govuk-button--warning" %> + +

+ <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %> +

+
+
diff --git a/app/views/support/providers/accredited_partners/_cannot_remove.html.erb b/app/views/support/providers/accredited_partners/_cannot_remove.html.erb new file mode 100644 index 0000000000..8eaf4cf7ff --- /dev/null +++ b/app/views/support/providers/accredited_partners/_cannot_remove.html.erb @@ -0,0 +1,23 @@ +<% content_for :page_title, "You cannot remove this accredited partner" %> +<% content_for :before_content do %> + <%= govuk_back_link_to(support_recruitment_cycle_provider_accredited_providers_path) %> +<% end %> + +
+
+

+ <%= @accredited_provider.provider_name %> + You cannot remove this accredited provider +

+ +

+ <%= @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) %> +

+
+
diff --git a/app/views/support/providers/accredited_partners/checks/show.html.erb b/app/views/support/providers/accredited_partners/checks/show.html.erb new file mode 100644 index 0000000000..df89ab4966 --- /dev/null +++ b/app/views/support/providers/accredited_partners/checks/show.html.erb @@ -0,0 +1,42 @@ + +<%= render PageTitle.new( + title: "Check your answers - #{t('.caption', provider_name: @provider.provider_name, code: @provider.provider_code)}" +) %> + +<% content_for :before_content do %> + <%= govuk_back_link_to(new_support_recruitment_cycle_provider_accredited_partner_path) %> +<% end %> + +
+
+ + <%= form_with(url: check_support_recruitment_cycle_provider_accredited_partners_path, method: :put, local: true) do |f| %> +

+ <%= t(".caption", provider_name: @provider.provider_name, code: @provider.provider_code) %> + Check your answers +

+ + <%= render GovukComponent::SummaryListComponent.new do |component| + component.with_row do |row| + row.with_key { "Accredited provider" } + row.with_value { @accredited_provider_form.provider_name } + row.with_action(text: "Change", href: search_support_recruitment_cycle_provider_accredited_providers_path(goto_confirmation: true), visually_hidden_text: "accredited partner name") + end + + component.with_row do |row| + row.with_key { "About the accredited partner" } + row.with_value { @accredited_provider_form.description } + row.with_action(text: "Change", href: new_support_recruitment_cycle_provider_accredited_partner_path(goto_confirmation: true), visually_hidden_text: "accredited partner description") + end + end %> + + <%= govuk_warning_text(text: "All users at #{@accredited_provider_form.provider_name} will be sent an email to let them know they’ve been added.") %> + + <%= f.govuk_submit(t(".add")) %> + <% end %> + +

+ <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %> +

+
+
diff --git a/app/views/support/providers/accredited_partners/delete.html.erb b/app/views/support/providers/accredited_partners/delete.html.erb new file mode 100644 index 0000000000..a6d881ade7 --- /dev/null +++ b/app/views/support/providers/accredited_partners/delete.html.erb @@ -0,0 +1 @@ +<%= render partial: @cannot_delete ? "cannot_remove" : "can_remove" %> diff --git a/app/views/support/providers/accredited_partners/edit.html.erb b/app/views/support/providers/accredited_partners/edit.html.erb new file mode 100644 index 0000000000..6592170509 --- /dev/null +++ b/app/views/support/providers/accredited_partners/edit.html.erb @@ -0,0 +1,41 @@ +<% content_for :page_title, title_with_error_prefix("About the accredited partnership - Edit accredited partnership - #{@provider.name_and_code}", @accredited_provider_form.errors.present?) %> + +
+
+ + <%= content_for(:breadcrumbs) do %> + <%= render GovukComponent::BackLinkComponent.new( + text: "Back", + href: support_recruitment_cycle_provider_accredited_partners_path( + recruitment_cycle_year: @recruitment_cycle.year, + provider_id: @provider.id + ) + ) %> + <% end %> + + <%= form_with( + model: @accredited_provider_form, + url: support_recruitment_cycle_provider_accredited_partner_path, + method: :put + ) do |f| %> + + <%= f.govuk_text_area( + :description, + label: { text: t(".title"), size: "l", tag: "h1" }, + hint: { text: t(".hint") }, + caption: { text: @accredited_provider_form.accredited_provider.provider_name, size: "l" }, + max_words: 100, + rows: 10 + ) %> + <%= f.hidden_field :accredited_provider_id, value: @accredited_provider_form.accredited_provider.id %> + + <%= f.govuk_submit "Update description" %> + +

+ <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %> +

+ + <% end %> + +
+
diff --git a/app/views/support/providers/accredited_partners/index.html.erb b/app/views/support/providers/accredited_partners/index.html.erb index a6a0967f89..7708eb7960 100644 --- a/app/views/support/providers/accredited_partners/index.html.erb +++ b/app/views/support/providers/accredited_partners/index.html.erb @@ -8,11 +8,11 @@ <% @accredited_partnerships.each do |partnership| %> <%= render AccreditedProviderComponent.new( provider_name: govuk_link_to(partnership.accredited_provider.provider_name, support_recruitment_cycle_provider_path(partnership.accredited_provider.recruitment_cycle_year, partnership.accredited_provider)), - remove_path: delete_support_recruitment_cycle_provider_accredited_provider_path( + remove_path: delete_support_recruitment_cycle_provider_accredited_partner_path( accredited_provider_code: partnership.accredited_provider.provider_code ), about_accredited_provider: partnership.description, - change_about_accredited_provider_path: edit_support_recruitment_cycle_provider_accredited_provider_path( + change_about_accredited_provider_path: edit_support_recruitment_cycle_provider_accredited_partner_path( accredited_provider_code: partnership.accredited_provider.provider_code ) ) %> diff --git a/app/views/support/providers/accredited_partners/new.html.erb b/app/views/support/providers/accredited_partners/new.html.erb new file mode 100644 index 0000000000..085a4f15c0 --- /dev/null +++ b/app/views/support/providers/accredited_partners/new.html.erb @@ -0,0 +1,38 @@ +<% content_for :page_title, title_with_error_prefix("About the accredited partner - Add accredited partner - #{@provider.name_and_code}", @accredited_provider_form.errors.present?) %> + +
+
+ + <%= form_with( + model: @accredited_provider_form, + url: support_recruitment_cycle_provider_accredited_partners_path, + method: :post + ) do |f| %> + + <%= content_for(:breadcrumbs) do %> + <%= render GovukComponent::BackLinkComponent.new( + text: "Back", + href: back_link_for_adding_accredited_partner_path(param_form_key: f.object_name.to_sym, params:, recruitment_cycle_year: @recruitment_cycle.year, provider: @provider) + ) %> + <% end %> + + <%= f.govuk_error_summary %> + + <%= f.govuk_text_area( + :description, + label: { text: t(".title"), size: "l", tag: "h1" }, + hint: { text: t(".hint") }, + caption: { text: t(".caption", provider_name: @provider.provider_name, code: @provider.provider_code), size: "l" }, + max_words: 100, + rows: 10 + ) %> + + <%= f.hidden_field :accredited_provider_id, value: accredited_provider_id %> + <%= f.govuk_submit t("continue") %> + <% end %> + +

+ <%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %> +

+
+
diff --git a/app/views/support/providers/accredited_provider_search/new.html.erb b/app/views/support/providers/accredited_provider_search/new.html.erb index 5e7554162a..11a5625b0f 100644 --- a/app/views/support/providers/accredited_provider_search/new.html.erb +++ b/app/views/support/providers/accredited_provider_search/new.html.erb @@ -12,7 +12,7 @@ <%= content_for(:breadcrumbs) do %> <%= render GovukComponent::BackLinkComponent.new( text: "Back", - href: back_link_for_adding_accrediting_provider_path(param_form_key: f.object_name.to_sym, params:, recruitment_cycle_year: @recruitment_cycle.year, provider: @provider) + href: back_link_for_adding_accredited_partner_path(param_form_key: f.object_name.to_sym, params:, recruitment_cycle_year: @recruitment_cycle.year, provider: @provider) ) %> <% end %> @@ -39,7 +39,7 @@ <% end %>

- <%= 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