Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add creation channels to TTA, RTTA, Events, Mailing list and Callbacks #4507

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ gem "text"
gem "indefinite_article"

gem "connection_pool"
gem "get_into_teaching_api_client_faraday", ">= 3.1.3", github: "DFE-Digital/get-into-teaching-api-ruby-client", require: "api/client"
gem "get_into_teaching_api_client_faraday", ">= 3.1.3", github: "DFE-Digital/get-into-teaching-api-ruby-client", require: "api/client", branch: "add-creation-channel-to-tta", ref: "f6b52e75af55e039629b00f14996935347fb12b5"
gem "redis"
gem "redis-session-store", ">= 0.11.4"

Expand Down
12 changes: 7 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ GIT

GIT
remote: https://github.com/DFE-Digital/get-into-teaching-api-ruby-client.git
revision: 9b2ba219f9def41b1547e4cb4f766f30f80364ee
revision: f6b52e75af55e039629b00f14996935347fb12b5
ref: f6b52e75af55e039629b00f14996935347fb12b5
branch: add-creation-channel-to-tta
specs:
get_into_teaching_api_client (3.3.0)
get_into_teaching_api_client (3.5.0)
faraday (~> 1.0, >= 1.0.1)
get_into_teaching_api_client_faraday (3.3.0)
get_into_teaching_api_client_faraday (3.5.0)
activesupport
faraday
faraday-encoding
Expand Down Expand Up @@ -255,8 +257,8 @@ GEM
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday (~> 1.0)
faraday_middleware-circuit_breaker (0.5.0)
faraday (>= 0.9, < 2.0)
faraday_middleware-circuit_breaker (0.6.0)
faraday (>= 0.9, < 3.0)
stoplight (>= 2.1, < 4.0)
fastimage (2.3.1)
ffi (1.17.0)
Expand Down
7 changes: 5 additions & 2 deletions app/components/content/adviser_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
<%= f.govuk_text_field :first_name, width: 'two-thirds', autocomplete: "given-name" %>
<%= f.govuk_text_field :last_name, width: 'two-thirds', autocomplete: "family-name" %>
<%= f.govuk_email_field :email, width: 'two-thirds', autocomplete: "email" %>
<%= f.hidden_field :channel_id, value: f.object&.channel_id.presence || params[:channel] %>
<%= f.hidden_field :sub_channel_id, value: f.object&.sub_channel_id.presence || params[:sub_channel] %>
<%= f.hidden_field :channel_id, value: params[:channel].presence || f.object&.channel_id.presence %>
<%= f.hidden_field :creation_channel_source_id, value: params[:channel_source].presence || f.object&.creation_channel_source_id.presence %>
<%= f.hidden_field :creation_channel_service_id, value: params[:channel_service].presence || f.object&.creation_channel_service_id.presence %>
<%= f.hidden_field :creation_channel_activity_id, value: params[:channel_activity].presence || f.object&.creation_channel_activity_id.presence %>
<%= f.hidden_field :sub_channel_id, value: params[:sub_channel].presence || f.object&.sub_channel_id.presence %>
<%= f.hidden_field :accepted_policy_id, value: privacy_policy.id %>

<p>Your details are protected under the terms of our <%= link_to("privacy notice (opens in new tab)", privacy_policy_path(id: privacy_policy.id), { class: "link--black", target: :blank }) %>.</p>
Expand Down
7 changes: 5 additions & 2 deletions app/components/content/mailing_list_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
<%= f.govuk_text_field :first_name, width: 'two-thirds', autocomplete: "given-name" %>
<%= f.govuk_text_field :last_name, width: 'two-thirds', autocomplete: "family-name" %>
<%= f.govuk_email_field :email, width: 'two-thirds', autocomplete: "email" %>
<%= f.hidden_field :channel_id, value: params[:channel] || f.object&.channel_id.presence %>
<%= f.hidden_field :sub_channel_id, value: params[:sub_channel] || f.object&.sub_channel_id.presence %>
<%= f.hidden_field :channel_id, value: params[:channel].presence || f.object&.channel_id.presence %>
<%= f.hidden_field :creation_channel_source_id, value: params[:channel_source].presence || f.object&.creation_channel_source_id.presence %>
<%= f.hidden_field :creation_channel_service_id, value: params[:channel_service].presence || f.object&.creation_channel_service_id.presence %>
<%= f.hidden_field :creation_channel_activity_id, value: params[:channel_activity].presence || f.object&.creation_channel_activity_id.presence %>
<%= f.hidden_field :sub_channel_id, value: params[:sub_channel].presence || f.object&.sub_channel_id.presence %>
<%= f.hidden_field :accepted_policy_id, value: privacy_policy.id %>

<p>Your details are protected under the terms of our <%= link_to("privacy notice (opens in new tab)", privacy_policy_path(id: privacy_policy.id), { class: "link--black", target: :blank }) %>.</p>
Expand Down
3 changes: 3 additions & 0 deletions app/components/home/mailing_list_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<%= f.govuk_text_field :last_name, autocomplete: "family-name" %>
<%= f.govuk_email_field :email, autocomplete: "email" %>
<%= f.hidden_field :channel_id, value: params[:channel] || f.object&.channel_id.presence %>
<%= f.hidden_field :creation_channel_source_id, value: params[:channel_source].presence || f.object&.creation_channel_source_id.presence %>
<%= f.hidden_field :creation_channel_service_id, value: params[:channel_service].presence || f.object&.creation_channel_service_id.presence %>
<%= f.hidden_field :creation_channel_activity_id, value: params[:channel_activity].presence || f.object&.creation_channel_activity_id.presence %>
<%= f.hidden_field :sub_channel_id, value: params[:sub_channel] || f.object&.sub_channel_id.presence %>
<%= f.hidden_field :accepted_policy_id, value: privacy_policy.id %>
<% button_text = helpers.safe_html_format("Next step <span></span>") %>
Expand Down
7 changes: 6 additions & 1 deletion app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def categorise_events(events, params)
OpenStruct.new(
title: Crm::EventRegion.lookup_by_id(event.region_id),
description: description,
path: event_path(event.readable_id, channel: params[:channel], sub_channel: params[:sub_channel]),
path: event_path(event.readable_id,
channel: params[:channel].presence,
channel_source: params[:channel_source].presence,
channel_service: params[:channel_service].presence,
channel_activity: params[:channel_activity].presence,
sub_channel: params[:sub_channel]),
)
end
end
Expand Down
28 changes: 28 additions & 0 deletions app/models/callbacks/steps/personal_details.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
module Callbacks
module Steps
class PersonalDetails < ::GITWizard::Steps::Identity
attribute :creation_channel_source_id, :integer
attribute :creation_channel_service_id, :integer
attribute :creation_channel_activity_id, :integer

DEFAULT_CREATION_CHANNEL_SOURCE_ID = 222_750_003 # GIT Website
DEFAULT_CREATION_CHANNEL_SERVICE_ID = 222_750_005 # Explore Teaching Adviser Service TODO: check this value
DEFAULT_CREATION_CHANNEL_ACTIVITY_ID = nil # default to blank

def save
self.creation_channel_source_id = DEFAULT_CREATION_CHANNEL_SOURCE_ID unless creation_channel_source_id.in?(creation_channel_source_ids)
self.creation_channel_service_id = DEFAULT_CREATION_CHANNEL_SERVICE_ID unless creation_channel_service_id.in?(creation_channel_service_ids)
self.creation_channel_activity_id = DEFAULT_CREATION_CHANNEL_ACTIVITY_ID unless creation_channel_activity_id.in?(creation_channel_activity_ids)
super
end

private

def creation_channel_source_ids
@creation_channel_source_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_sources.map { |obj| obj.id.to_i }
end

def creation_channel_service_ids
@creation_channel_service_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_services.map { |obj| obj.id.to_i }
end

def creation_channel_activity_ids
@creation_channel_activity_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_activities.map { |obj| obj.id.to_i }
end
end
end
end
42 changes: 32 additions & 10 deletions app/models/events/steps/personal_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,58 @@ class PersonalDetails < ::GITWizard::Steps::Identity
attribute :is_walk_in, :boolean
attribute :event_id
attribute :channel_id, :integer
attribute :creation_channel_source_id, :integer
attribute :creation_channel_service_id, :integer
attribute :creation_channel_activity_id, :integer
attribute :sub_channel_id

validates :event_id, presence: true

DEFAULT_CHANNEL_ID = nil
DEFAULT_CREATION_CHANNEL_SOURCE_ID = 222_750_003 # GIT Website
DEFAULT_CREATION_CHANNEL_SERVICE_ID = 222_750_006 # Events
DEFAULT_CREATION_CHANNEL_ACTIVITY_ID = nil # default to blank

def export
super.except("sub_channel_id")
end

def channel_ids
query_channels.map { |channel| channel.id.to_i }
end

def is_walk_in?
is_walk_in.present?
end

def save
self.channel_id = nil unless channel_valid?

if creation_channel_source_id.nil? && channel_id.present? && channel_id.in?(legacy_channel_ids)
# if the new creation_channel_source_id is missing and a valid legacy channel_id is provided, use the legacy channel only
self.creation_channel_source_id = nil
self.creation_channel_service_id = nil
self.creation_channel_activity_id = nil
else
# otherwise set the new creation_channel fields and set the legacy channel_id to be nil
self.channel_id = DEFAULT_CHANNEL_ID # channel_id will always be nil as we use the creation channel structure going forwards
self.creation_channel_source_id = DEFAULT_CREATION_CHANNEL_SOURCE_ID unless creation_channel_source_id.in?(creation_channel_source_ids)
self.creation_channel_service_id = DEFAULT_CREATION_CHANNEL_SERVICE_ID unless creation_channel_service_id.in?(creation_channel_service_ids)
self.creation_channel_activity_id = DEFAULT_CREATION_CHANNEL_ACTIVITY_ID unless creation_channel_activity_id.in?(creation_channel_activity_ids)
end
super
end

private

def channel_valid?
channel_id.present? && channel_id.in?(channel_ids)
def creation_channel_source_ids
@creation_channel_source_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_sources.map { |obj| obj.id.to_i }
end

def creation_channel_service_ids
@creation_channel_service_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_services.map { |obj| obj.id.to_i }
end

def creation_channel_activity_ids
@creation_channel_activity_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_activities.map { |obj| obj.id.to_i }
end

def query_channels
@query_channels ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_candidate_event_subscription_channels
def legacy_channel_ids
@legacy_channel_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_candidate_event_subscription_channels.map { |obj| obj.id.to_i }
end
end
end
Expand Down
40 changes: 31 additions & 9 deletions app/models/mailing_list/steps/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@ module MailingList
module Steps
class Name < ::GITWizard::Steps::Identity
attribute :channel_id, :integer
attribute :creation_channel_source_id, :integer
attribute :creation_channel_service_id, :integer
attribute :creation_channel_activity_id, :integer
attribute :sub_channel_id

def channel_ids
query_channels.map { |channel| channel.id.to_i }
end
DEFAULT_CHANNEL_ID = nil
DEFAULT_CREATION_CHANNEL_SOURCE_ID = 222_750_003 # GIT Website
DEFAULT_CREATION_CHANNEL_SERVICE_ID = 222_750_007 # Mailing List
DEFAULT_CREATION_CHANNEL_ACTIVITY_ID = nil # default to blank

def export
super.without("sub_channel_id")
end

def save
self.channel_id = nil if channel_invalid?

if creation_channel_source_id.nil? && channel_id.present? && channel_id.in?(legacy_channel_ids)
# if the new creation_channel_source_id is missing and a valid legacy channel_id is provided, use the legacy channel only
self.creation_channel_source_id = nil
self.creation_channel_service_id = nil
self.creation_channel_activity_id = nil
else
# otherwise set the new creation_channel fields and set the legacy channel_id to be nil
self.channel_id = DEFAULT_CHANNEL_ID # channel_id will always be nil as we use the creation channel structure going forwards
self.creation_channel_source_id = DEFAULT_CREATION_CHANNEL_SOURCE_ID unless creation_channel_source_id.in?(creation_channel_source_ids)
self.creation_channel_service_id = DEFAULT_CREATION_CHANNEL_SERVICE_ID unless creation_channel_service_id.in?(creation_channel_service_ids)
self.creation_channel_activity_id = DEFAULT_CREATION_CHANNEL_ACTIVITY_ID unless creation_channel_activity_id.in?(creation_channel_activity_ids)
end
super
end

Expand All @@ -24,12 +38,20 @@ def title

private

def channel_invalid?
channel_id.present? && !channel_id.in?(channel_ids)
def creation_channel_source_ids
@creation_channel_source_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_sources.map { |obj| obj.id.to_i }
end

def creation_channel_service_ids
@creation_channel_service_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_services.map { |obj| obj.id.to_i }
end

def creation_channel_activity_ids
@creation_channel_activity_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_activities.map { |obj| obj.id.to_i }
end

def query_channels
@query_channels ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_candidate_mailing_list_subscription_channels
def legacy_channel_ids
@legacy_channel_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_candidate_mailing_list_subscription_channels.map { |obj| obj.id.to_i }
end
end
end
Expand Down
37 changes: 26 additions & 11 deletions app/models/teacher_training_adviser/steps/identity.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
module TeacherTrainingAdviser::Steps
class Identity < GITWizard::Steps::Identity
attribute :channel_id, :integer
attribute :creation_channel_source_id, :integer
attribute :creation_channel_service_id, :integer
attribute :creation_channel_activity_id, :integer
attribute :sub_channel_id

DEFAULT_CHANNEL_ID = nil
DEFAULT_CREATION_CHANNEL_SOURCE_ID = 222_750_003 # GIT Website
DEFAULT_CREATION_CHANNEL_ACTIVITY_ID = nil # default to blank

def export
super.without("sub_channel_id")
end

def reviewable_answers
super.without(%w[channel_id sub_channel_id])
end

def channel_ids
query_channels.map { |channel| channel.id.to_i }
super.without(%w[channel_id sub_channel_id creation_channel_source_id creation_channel_service_id creation_channel_activity_id])
end

def save
self.channel_id = nil if channel_invalid?

if creation_channel_source_id.nil? && channel_id.present? && channel_id.in?(legacy_channel_ids)
# if the new creation_channel_source_id is missing and a valid legacy channel_id is provided, use the legacy channel only
self.creation_channel_source_id = nil
self.creation_channel_activity_id = nil
else
# otherwise set the new creation_channel fields and set the legacy channel_id to be nil
self.channel_id = DEFAULT_CHANNEL_ID # channel_id will always be nil as we use the creation channel structure going forwards
self.creation_channel_source_id = DEFAULT_CREATION_CHANNEL_SOURCE_ID unless creation_channel_source_id.in?(creation_channel_source_ids)
self.creation_channel_activity_id = DEFAULT_CREATION_CHANNEL_ACTIVITY_ID unless creation_channel_activity_id.in?(creation_channel_activity_ids)
end
super
end

Expand All @@ -27,12 +38,16 @@ def title

private

def channel_invalid?
channel_id.present? && !channel_id.in?(channel_ids)
def creation_channel_source_ids
@creation_channel_source_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_sources.map { |obj| obj.id.to_i }
end

def creation_channel_activity_ids
@creation_channel_activity_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_activities.map { |obj| obj.id.to_i }
end

def query_channels
@query_channels ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_candidate_teacher_training_adviser_subscription_channels
def legacy_channel_ids
@legacy_channel_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_candidate_teacher_training_adviser_subscription_channels.map { |obj| obj.id.to_i }
end
end
end
30 changes: 30 additions & 0 deletions app/models/teacher_training_adviser/steps/returning_teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ class ReturningTeacher < GITWizard::Step
OPTIONS = { returning_to_teaching: 222_750_001, interested_in_teaching: 222_750_000 }.freeze

attribute :type_id, :integer
attribute :creation_channel_service_id, :integer

validates :type_id, pick_list_items: { method: :get_candidate_types }

RTTA_DEFAULT_CREATION_CHANNEL_SERVICE_ID = 222_750_009 # Return to Teacher Training Adviser Service
TTA_DEFAULT_CREATION_CHANNEL_SERVICE_ID = 222_750_010 # Teacher Training Adviser Service

def returning_to_teaching
type_id == OPTIONS[:returning_to_teaching]
end
Expand All @@ -15,5 +19,31 @@ def reviewable_answers
"returning_to_teaching" => returning_to_teaching ? "Yes" : "No",
}
end

def save
if creation_channel_source_id.nil? && channel_id.present?
# if the new creation_channel_source_id is missing and a valid legacy channel_id is provided, use the legacy channel only
self.creation_channel_service_id = nil
elsif !creation_channel_service_id.in?(creation_channel_service_ids)
# otherwise set the new creation_channel fields and set the legacy channel_id to be nil

self.creation_channel_service_id = returning_to_teaching ? RTTA_DEFAULT_CREATION_CHANNEL_SERVICE_ID : TTA_DEFAULT_CREATION_CHANNEL_SERVICE_ID
end
super
end

private

def channel_id
other_step(:identity).channel_id
end

def creation_channel_source_id
other_step(:identity).creation_channel_source_id
end

def creation_channel_service_ids
@creation_channel_service_ids ||= GetIntoTeachingApiClient::PickListItemsApi.new.get_contact_creation_channel_services.map { |obj| obj.id.to_i }
end
end
end
3 changes: 3 additions & 0 deletions app/views/callbacks/steps/_personal_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<%= f.govuk_text_field :last_name, autocomplete: "family-name", width: 'two-thirds' %>
<%= f.govuk_email_field :email, autocomplete: "email", width: 'two-thirds' %>
<%= f.hidden_field :accepted_policy_id, value: f.object.latest_privacy_policy.id %>
<%= f.hidden_field :creation_channel_source_id, value: params[:channel_source].presence || f.object&.creation_channel_source_id.presence %>
<%= f.hidden_field :creation_channel_service_id, value: params[:channel_service].presence || f.object&.creation_channel_service_id.presence %>
<%= f.hidden_field :creation_channel_activity_id, value: params[:channel_activity].presence || f.object&.creation_channel_activity_id.presence %>

<p>Your details are protected under the terms of our <%= link_to("privacy notice (opens in new tab)", privacy_policy_path(id: f.object.latest_privacy_policy.id), { target: :blank }) %>.</p>

Expand Down
3 changes: 3 additions & 0 deletions app/views/event_steps/_personal_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<%= f.hidden_field :accepted_policy_id, value: f.object.latest_privacy_policy.id %>
<%= f.hidden_field :event_id, value: @event.id %>
<%= f.hidden_field :channel_id, value: params[:channel] || f.object&.channel_id %>
<%= f.hidden_field :creation_channel_source_id, value: params[:channel_source].presence || f.object&.creation_channel_source_id.presence %>
<%= f.hidden_field :creation_channel_service_id, value: params[:channel_service].presence || f.object&.creation_channel_service_id.presence %>
<%= f.hidden_field :creation_channel_activity_id, value: params[:channel_activity].presence || f.object&.creation_channel_activity_id.presence %>
<%= f.hidden_field :sub_channel_id, value: params[:sub_channel] || f.object&.sub_channel_id %>

<p>Your details are protected under the terms of our <%= link_to("privacy notice (opens in new tab)", privacy_policy_path(id: f.object.latest_privacy_policy.id), { target: :blank }) %>.</p>
Expand Down
Loading
Loading