Skip to content

Commit

Permalink
Update Support accredited partnerships
Browse files Browse the repository at this point in the history
  • Loading branch information
inulty-dfe committed Dec 17, 2024
1 parent a73e3b8 commit f1e28cf
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -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
45 changes: 28 additions & 17 deletions app/controllers/support/providers/accredited_partners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
)
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/goto_confirmation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @accredited_provider.provider_name %></span>
<%= t("support.providers.accredited_partners.delete.title") %>
</h1>

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

<p class="govuk-body">
<%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %>
</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -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 %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @accredited_provider.provider_name %></span>
You cannot remove this accredited provider
</h1>

<p class="govuk-body">
<%= @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.
</p>

<p class="govuk-body">
<%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %>
</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -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 %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">

<%= form_with(url: check_support_recruitment_cycle_provider_accredited_partners_path, method: :put, local: true) do |f| %>
<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= t(".caption", provider_name: @provider.provider_name, code: @provider.provider_code) %></span>
Check your answers
</h1>

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

<p class="govuk-body">
<%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %>
</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: @cannot_delete ? "cannot_remove" : "can_remove" %>
41 changes: 41 additions & 0 deletions app/views/support/providers/accredited_partners/edit.html.erb
Original file line number Diff line number Diff line change
@@ -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?) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

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

<p class="govuk-body">
<%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %>
</p>

<% end %>

</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
) %>
Expand Down
38 changes: 38 additions & 0 deletions app/views/support/providers/accredited_partners/new.html.erb
Original file line number Diff line number Diff line change
@@ -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?) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">

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

<p class="govuk-body">
<%= govuk_link_to(t("cancel"), support_recruitment_cycle_provider_accredited_partners_path) %>
</p>
</div>
</div>
Loading

0 comments on commit f1e28cf

Please sign in to comment.