Skip to content

Commit

Permalink
Merge pull request #4726 from DFE-Digital/CPDLP-2938-npq-capping-add-…
Browse files Browse the repository at this point in the history
…funded-place-to-accept-npq-application-endpoint

NPQ capping: add funded place to accept npq application endpoint
  • Loading branch information
mooktakim committed May 17, 2024
2 parents a39756c + a986771 commit 72f36db
Show file tree
Hide file tree
Showing 14 changed files with 573 additions and 112 deletions.
20 changes: 19 additions & 1 deletion app/controllers/api/v1/npq_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def reject
end

def accept
service = ::NPQ::Application::Accept.new(npq_application:)
service = ::NPQ::Application::Accept.new(npq_application:, funded_place:)

render_from_service(service, json_serializer_class)
end
Expand Down Expand Up @@ -68,6 +68,24 @@ def access_scope
def npq_application
@npq_application ||= npq_lead_provider.npq_applications.includes(:cohort, :npq_course, participant_identity: [:user]).find(params[:id])
end

def funded_place
if FeatureFlag.active?(:npq_capping)
accept_permitted_params.dig("attributes", "funded_place")
end
end

def accept_permitted_params
parameters = params
.fetch(:data)
.permit(:type, attributes: %i[funded_place])

return parameters unless parameters["attributes"].empty?

raise ActionController::BadRequest, I18n.t(:invalid_data_structure)
rescue ActionController::ParameterMissing
{}
end
end
end
end
10 changes: 7 additions & 3 deletions app/controllers/api/v3/npq_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
# POST /api/v3/npq-applications/:id/accept
#
def accept
service = ::NPQ::Application::Accept.new({ npq_application: }.merge(accept_npq_application_params["attributes"] || {}))
service = ::NPQ::Application::Accept.new(npq_application:, funded_place:, schedule_identifier:)

render_from_service(service, json_serializer_class)
end
Expand Down Expand Up @@ -46,10 +46,14 @@ def json_serializer_class
Api::V3::NPQApplicationSerializer
end

def accept_npq_application_params
def schedule_identifier
accept_permitted_params.dig("attributes", "schedule_identifier")
end

def accept_permitted_params
parameters = params
.fetch(:data)
.permit(:type, attributes: %i[schedule_identifier])
.permit(:type, attributes: %i[schedule_identifier funded_place])

return parameters unless parameters["attributes"].empty?

Expand Down
2 changes: 2 additions & 0 deletions app/serializers/api/v1/npq_application_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class NPQApplicationSerializer
:status,
:works_in_school

attribute :funded_place, if: -> { FeatureFlag.active?("npq_capping") }, &:funded_place

attribute(:participant_id) do |object|
object.participant_identity.user_id
end
Expand Down
45 changes: 45 additions & 0 deletions app/services/npq/application/accept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ class Accept

attribute :npq_application
attribute :schedule_identifier
attribute :funded_place

validates :npq_application, presence: { message: I18n.t("npq_application.missing_npq_application") }
validate :not_already_accepted
validate :cannot_change_from_rejected
validate :other_accepted_applications_with_same_course?
validate :validate_permitted_schedule_for_course
validate :eligible_for_funded_place
validate :validate_funded_place

def call
return self unless valid?
Expand All @@ -24,6 +27,7 @@ def call
npq_application.update!(lead_provider_approval_status: "accepted")
other_applications_in_same_cohort.update(lead_provider_approval_status: "rejected") # rubocop:disable Rails/SaveBang
deduplicate_by_trn!
set_funded_place_on_npq_application
end

npq_application
Expand Down Expand Up @@ -145,6 +149,47 @@ def validate_permitted_schedule_for_course
errors.add(:schedule_identifier, I18n.t(:schedule_invalid_for_course))
end
end

def set_funded_place_on_npq_application
return unless FeatureFlag.active?("npq_capping")
return unless npq_contract.funding_cap.to_i.positive?

npq_application.update!(funded_place:)
end

def eligible_for_funded_place
return unless FeatureFlag.active?("npq_capping")
return if errors.any?
return unless npq_contract.funding_cap.to_i.positive?

if funded_place && !npq_application.eligible_for_funding
errors.add(:npq_application, I18n.t("npq_application.not_eligible_for_funded_place"))
end
end

def validate_funded_place
return unless FeatureFlag.active?("npq_capping")
return if errors.any?
return unless npq_contract.funding_cap.to_i.positive?

if funded_place.nil?
errors.add(:npq_application, I18n.t("npq_application.funded_place_required"))
end
end

def npq_contract
@npq_contract ||=
NPQContract.where(
cohort_id: cohort.id,
npq_lead_provider_id: npq_application.npq_lead_provider_id,
course_identifier: npq_application.npq_course.identifier,
version: statement.contract_version,
).first
end

def statement
npq_application.npq_lead_provider.next_output_fee_statement(cohort)
end
end
end
end
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ en:
has_already_been_rejected: This NPQ application has already been rejected
cannot_change_from_accepted: Once accepted an application cannot change state
cannot_change_from_rejected: Once rejected an application cannot change state
not_eligible_for_funded_place: "The participant is not eligible for funding, so '#/funded_place' cannot be set to true."
funded_place_required: "Set '#/funded_place' to true or false."
errors:
email: &email_error_messages
blank: "Enter an email address"
Expand Down
200 changes: 97 additions & 103 deletions db/data/npq_contracts/fake-2024.csv
Original file line number Diff line number Diff line change
@@ -1,103 +1,97 @@
provider_name,cohort_year,course_identifier,recruitment_target,per_participant,service_fee_installments,special_course,monthly_service_fee
Ambition Institute,2024,npq-leading-teaching,1000,100,12,FALSE,0.0
Ambition Institute,2024,npq-leading-behaviour-culture,1001,101,13,FALSE,0.0
Ambition Institute,2024,npq-leading-teaching-development,1002,102,14,FALSE,0.0
Ambition Institute,2024,npq-senior-leadership,1003,103,15,FALSE,0.0
Ambition Institute,2024,npq-headship,1004,104,16,FALSE,0.0
Ambition Institute,2024,npq-executive-leadership,1005,105,17,FALSE,0.0
Ambition Institute,2024,npq-leading-literacy,1006,106,18,FALSE,0.0
Ambition Institute,2024,npq-early-years-leadership,1007,107,19,FALSE,0.0
Ambition Institute,2024,npq-senco,450,902,19,FALSE,0,0.0
Best Practice Network,2024,npq-leading-teaching,1008,108,20,FALSE,0.0
Best Practice Network,2024,npq-leading-behaviour-culture,1009,109,21,FALSE,0.0
Best Practice Network,2024,npq-leading-teaching-development,1010,110,22,FALSE,0.0
Best Practice Network,2024,npq-senior-leadership,1011,111,23,FALSE,0.0
Best Practice Network,2024,npq-headship,1012,112,24,FALSE,0.0
Best Practice Network,2024,npq-executive-leadership,1013,113,25,FALSE,0.0
Best Practice Network,2024,npq-senco,283,890,19,FALSE,0,0.0
Church of England,2024,npq-leading-teaching,1014,114,26,FALSE,0.0
Church of England,2024,npq-leading-behaviour-culture,1015,115,27,FALSE,0.0
Church of England,2024,npq-leading-teaching-development,1016,116,28,FALSE,0.0
Church of England,2024,npq-senior-leadership,1017,117,29,FALSE,0.0
Church of England,2024,npq-headship,1018,118,30,FALSE,0.0
Church of England,2024,npq-executive-leadership,1019,119,31,FALSE,0.0
Church of England,2024,npq-senco,200,901,19,FALSE,0,0.0
Education Development Trust,2024,npq-leading-teaching,1020,120,32,FALSE,0.0
Education Development Trust,2024,npq-leading-behaviour-culture,1021,121,33,FALSE,0.0
Education Development Trust,2024,npq-leading-teaching-development,1022,122,34,FALSE,0.0
Education Development Trust,2024,npq-senior-leadership,1023,123,35,FALSE,0.0
Education Development Trust,2024,npq-headship,1024,124,36,FALSE,0.0
Education Development Trust,2024,npq-executive-leadership,1025,125,37,FALSE,0.0
Education Development Trust,2024,npq-leading-literacy,1026,126,38,FALSE,0.0
Education Development Trust,2024,npq-early-years-leadership,1027,127,39,FALSE,0.0
School-Led Network,2024,npq-leading-teaching,1028,128,40,FALSE,0.0
School-Led Network,2024,npq-leading-behaviour-culture,1029,129,41,FALSE,0.0
School-Led Network,2024,npq-leading-teaching-development,1030,130,42,FALSE,0.0
School-Led Network,2024,npq-senior-leadership,1031,131,43,FALSE,0.0
School-Led Network,2024,npq-headship,1032,132,44,FALSE,0.0
School-Led Network,2024,npq-executive-leadership,1033,133,45,FALSE,0.0
School-Led Network,2024,npq-leading-literacy,1034,134,46,FALSE,0.0
School-Led Network,2024,npq-early-years-leadership,1035,135,47,FALSE,0.0
LLSE,2024,npq-leading-teaching,1036,136,48,FALSE,0.0
LLSE,2024,npq-leading-behaviour-culture,1037,137,49,FALSE,0.0
LLSE,2024,npq-leading-teaching-development,1038,138,50,FALSE,0.0
LLSE,2024,npq-senior-leadership,1039,139,51,FALSE,0.0
LLSE,2024,npq-headship,1040,140,52,FALSE,0.0
LLSE,2024,npq-executive-leadership,1041,141,53,FALSE,0.0
LLSE,2024,npq-leading-literacy,1042,142,54,FALSE,0.0
LLSE,2024,npq-early-years-leadership,1043,143,55,FALSE,0.0
Teach First,2024,npq-leading-teaching,1044,144,56,FALSE,0.0
Teach First,2024,npq-leading-behaviour-culture,1045,145,57,FALSE,0.0
Teach First,2024,npq-leading-teaching-development,1046,146,58,FALSE,0.0
Teach First,2024,npq-senior-leadership,1047,147,59,FALSE,0.0
Teach First,2024,npq-headship,1048,148,60,FALSE,0.0
Teach First,2024,npq-executive-leadership,1049,149,61,FALSE,0.0
Teach First,2024,npq-leading-literacy,1050,150,62,FALSE,0.0
Teach First,2024,npq-early-years-leadership,1051,151,63,FALSE,0.0
Teach First,2024,npq-senco,156,895,19,FALSE,0,0.0
Teacher Development Trust,2024,npq-leading-teaching,1052,152,64,FALSE,0.0
Teacher Development Trust,2024,npq-leading-behaviour-culture,1053,153,65,FALSE,0.0
Teacher Development Trust,2024,npq-leading-teaching-development,1054,154,66,FALSE,0.0
Teacher Development Trust,2024,npq-senior-leadership,1055,155,67,FALSE,0.0
Teacher Development Trust,2024,npq-headship,1056,156,68,FALSE,0.0
Teacher Development Trust,2024,npq-executive-leadership,1057,157,69,FALSE,0.0
Teacher Development Trust,2024,npq-leading-literacy,1058,158,70,FALSE,0.0
Teacher Development Trust,2024,npq-early-years-leadership,1059,159,71,FALSE,0.0
UCL Institute of Education,2024,npq-leading-teaching,1060,160,72,FALSE,0.0
UCL Institute of Education,2024,npq-leading-behaviour-culture,1061,161,73,FALSE,0.0
UCL Institute of Education,2024,npq-leading-teaching-development,1062,162,74,FALSE,0.0
UCL Institute of Education,2024,npq-senior-leadership,1063,163,75,FALSE,0.0
UCL Institute of Education,2024,npq-headship,1064,164,76,FALSE,0.0
UCL Institute of Education,2024,npq-executive-leadership,1065,165,77,FALSE,0.0
UCL Institute of Education,2024,npq-leading-literacy,1066,166,78,FALSE,0.0
UCL Institute of Education,2024,npq-early-years-leadership,1067,167,79,FALSE,0.0
UCL Institute of Education,2024,npq-senco,125,902,19,FALSE,0,0.0
Ambition Institute,2024,npq-early-headship-coaching-offer,1068,168,0,FALSE,0.0
Best Practice Network,2024,npq-early-headship-coaching-offer,1069,169,0,FALSE,0.0
Church of England,2024,npq-early-headship-coaching-offer,1070,170,0,FALSE,0.0
Education Development Trust,2024,npq-early-headship-coaching-offer,1071,171,0,FALSE,0.0
School-Led Network,2024,npq-early-headship-coaching-offer,1072,172,0,FALSE,0.0
LLSE,2024,npq-early-headship-coaching-offer,1073,173,0,FALSE,0.0
Teach First,2024,npq-early-headship-coaching-offer,1074,174,0,FALSE,0.0
Teacher Development Trust,2024,npq-early-headship-coaching-offer,1075,175,0,FALSE,0.0
UCL Institute of Education,2024,npq-early-headship-coaching-offer,1076,176,0,FALSE,0.0
National Institute of Teaching,2024,npq-leading-teaching,100,800,24,FALSE,0.0
National Institute of Teaching,2024,npq-leading-behaviour-culture,101,801,24,FALSE,0.0
National Institute of Teaching,2024,npq-leading-teaching-development,102,802,24,FALSE,0.0
National Institute of Teaching,2024,npq-senior-leadership,103,803,24,FALSE,0.0
National Institute of Teaching,2024,npq-headship,104,804,24,FALSE,0.0
National Institute of Teaching,2024,npq-executive-leadership,105,805,24,FALSE,0.0
National Institute of Teaching,2024,npq-leading-literacy,106,806,24,FALSE,0.0
National Institute of Teaching,2024,npq-early-years-leadership,107,807,24,FALSE,0.0
National Institute of Teaching,2024,npq-early-headship-coaching-offer,1000,800,0,FALSE,0.0
National Institute of Teaching,2024,npq-senco,150,902,19,FALSE,0,0.0
Ambition Institute,2024,npq-leading-primary-mathematics,1007,107,19,TRUE
Best Practice Network,2024,npq-leading-primary-mathematics,1013,113,25,TRUE
Church of England,2024,npq-leading-primary-mathematics,1019,119,31,TRUE
Education Development Trust,2024,npq-leading-primary-mathematics,1027,127,39,TRUE
School-Led Network,2024,npq-leading-primary-mathematics,1035,135,47,TRUE
LLSE,2024,npq-leading-primary-mathematics,1043,143,55,TRUE
Teach First,2024,npq-leading-primary-mathematics,1051,151,63,TRUE
Teacher Development Trust,2024,npq-leading-primary-mathematics,1059,159,71,TRUE
UCL Institute of Education,2024,npq-leading-primary-mathematics,1067,167,79,TRUE
National Institute of Teaching,2024,npq-leading-primary-mathematics,1000,800,0,TRUE
provider_name,cohort_year,course_identifier,recruitment_target,per_participant,service_fee_installments,special_course,monthly_service_fee,funding_cap
Ambition Institute,2024,npq-leading-teaching,1000,100,12,FALSE,0,1
Ambition Institute,2024,npq-leading-behaviour-culture,1001,101,13,FALSE,0,1
Ambition Institute,2024,npq-leading-teaching-development,1002,102,14,FALSE,0,1
Ambition Institute,2024,npq-senior-leadership,1003,103,15,FALSE,0,1
Ambition Institute,2024,npq-headship,1004,104,16,FALSE,0,1
Ambition Institute,2024,npq-executive-leadership,1005,105,17,FALSE,0,1
Ambition Institute,2024,npq-leading-literacy,1006,106,18,FALSE,0,1
Ambition Institute,2024,npq-early-years-leadership,1007,107,19,FALSE,0,1
Best Practice Network,2024,npq-leading-teaching,1008,108,20,FALSE,0,1
Best Practice Network,2024,npq-leading-behaviour-culture,1009,109,21,FALSE,0,1
Best Practice Network,2024,npq-leading-teaching-development,1010,110,22,FALSE,0,1
Best Practice Network,2024,npq-senior-leadership,1011,111,23,FALSE,0,1
Best Practice Network,2024,npq-headship,1012,112,24,FALSE,0,1
Best Practice Network,2024,npq-executive-leadership,1013,113,25,FALSE,0,1
Church of England,2024,npq-leading-teaching,1014,114,26,FALSE,0,1
Church of England,2024,npq-leading-behaviour-culture,1015,115,27,FALSE,0,1
Church of England,2024,npq-leading-teaching-development,1016,116,28,FALSE,0,1
Church of England,2024,npq-senior-leadership,1017,117,29,FALSE,0,1
Church of England,2024,npq-headship,1018,118,30,FALSE,0,1
Church of England,2024,npq-executive-leadership,1019,119,31,FALSE,0,1
Education Development Trust,2024,npq-leading-teaching,1020,120,32,FALSE,0,1
Education Development Trust,2024,npq-leading-behaviour-culture,1021,121,33,FALSE,0,1
Education Development Trust,2024,npq-leading-teaching-development,1022,122,34,FALSE,0,1
Education Development Trust,2024,npq-senior-leadership,1023,123,35,FALSE,0,1
Education Development Trust,2024,npq-headship,1024,124,36,FALSE,0,1
Education Development Trust,2024,npq-executive-leadership,1025,125,37,FALSE,0,1
Education Development Trust,2024,npq-leading-literacy,1026,126,38,FALSE,0,1
Education Development Trust,2024,npq-early-years-leadership,1027,127,39,FALSE,0,1
School-Led Network,2024,npq-leading-teaching,1028,128,40,FALSE,0,1
School-Led Network,2024,npq-leading-behaviour-culture,1029,129,41,FALSE,0,1
School-Led Network,2024,npq-leading-teaching-development,1030,130,42,FALSE,0,1
School-Led Network,2024,npq-senior-leadership,1031,131,43,FALSE,0,1
School-Led Network,2024,npq-headship,1032,132,44,FALSE,0,1
School-Led Network,2024,npq-executive-leadership,1033,133,45,FALSE,0,1
School-Led Network,2024,npq-leading-literacy,1034,134,46,FALSE,0,1
School-Led Network,2024,npq-early-years-leadership,1035,135,47,FALSE,0,1
LLSE,2024,npq-leading-teaching,1036,136,48,FALSE,0,1
LLSE,2024,npq-leading-behaviour-culture,1037,137,49,FALSE,0,1
LLSE,2024,npq-leading-teaching-development,1038,138,50,FALSE,0,1
LLSE,2024,npq-senior-leadership,1039,139,51,FALSE,0,1
LLSE,2024,npq-headship,1040,140,52,FALSE,0,1
LLSE,2024,npq-executive-leadership,1041,141,53,FALSE,0,1
LLSE,2024,npq-leading-literacy,1042,142,54,FALSE,0,1
LLSE,2024,npq-early-years-leadership,1043,143,55,FALSE,0,1
Teach First,2024,npq-leading-teaching,1044,144,56,FALSE,0,1
Teach First,2024,npq-leading-behaviour-culture,1045,145,57,FALSE,0,1
Teach First,2024,npq-leading-teaching-development,1046,146,58,FALSE,0,1
Teach First,2024,npq-senior-leadership,1047,147,59,FALSE,0,1
Teach First,2024,npq-headship,1048,148,60,FALSE,0,1
Teach First,2024,npq-executive-leadership,1049,149,61,FALSE,0,1
Teach First,2024,npq-leading-literacy,1050,150,62,FALSE,0,1
Teach First,2024,npq-early-years-leadership,1051,151,63,FALSE,0,1
Teacher Development Trust,2024,npq-leading-teaching,1052,152,64,FALSE,0,1
Teacher Development Trust,2024,npq-leading-behaviour-culture,1053,153,65,FALSE,0,1
Teacher Development Trust,2024,npq-leading-teaching-development,1054,154,66,FALSE,0,1
Teacher Development Trust,2024,npq-senior-leadership,1055,155,67,FALSE,0,1
Teacher Development Trust,2024,npq-headship,1056,156,68,FALSE,0,1
Teacher Development Trust,2024,npq-executive-leadership,1057,157,69,FALSE,0,1
Teacher Development Trust,2024,npq-leading-literacy,1058,158,70,FALSE,0,1
Teacher Development Trust,2024,npq-early-years-leadership,1059,159,71,FALSE,0,1
UCL Institute of Education,2024,npq-leading-teaching,1060,160,72,FALSE,0,1
UCL Institute of Education,2024,npq-leading-behaviour-culture,1061,161,73,FALSE,0,1
UCL Institute of Education,2024,npq-leading-teaching-development,1062,162,74,FALSE,0,1
UCL Institute of Education,2024,npq-senior-leadership,1063,163,75,FALSE,0,1
UCL Institute of Education,2024,npq-headship,1064,164,76,FALSE,0,1
UCL Institute of Education,2024,npq-executive-leadership,1065,165,77,FALSE,0,1
UCL Institute of Education,2024,npq-leading-literacy,1066,166,78,FALSE,0,1
UCL Institute of Education,2024,npq-early-years-leadership,1067,167,79,FALSE,0,1
Ambition Institute,2024,npq-early-headship-coaching-offer,1068,168,0,FALSE,0,1
Best Practice Network,2024,npq-early-headship-coaching-offer,1069,169,0,FALSE,0,1
Church of England,2024,npq-early-headship-coaching-offer,1070,170,0,FALSE,0,1
Education Development Trust,2024,npq-early-headship-coaching-offer,1071,171,0,FALSE,0,1
School-Led Network,2024,npq-early-headship-coaching-offer,1072,172,0,FALSE,0,1
LLSE,2024,npq-early-headship-coaching-offer,1073,173,0,FALSE,0,1
Teach First,2024,npq-early-headship-coaching-offer,1074,174,0,FALSE,0,1
Teacher Development Trust,2024,npq-early-headship-coaching-offer,1075,175,0,FALSE,0,1
UCL Institute of Education,2024,npq-early-headship-coaching-offer,1076,176,0,FALSE,0,1
National Institute of Teaching,2024,npq-leading-teaching,100,800,24,FALSE,0,1
National Institute of Teaching,2024,npq-leading-behaviour-culture,101,801,24,FALSE,0,1
National Institute of Teaching,2024,npq-leading-teaching-development,102,802,24,FALSE,0,1
National Institute of Teaching,2024,npq-senior-leadership,103,803,24,FALSE,0,1
National Institute of Teaching,2024,npq-headship,104,804,24,FALSE,0,1
National Institute of Teaching,2024,npq-executive-leadership,105,805,24,FALSE,0,1
National Institute of Teaching,2024,npq-leading-literacy,106,806,24,FALSE,0,1
National Institute of Teaching,2024,npq-early-years-leadership,107,807,24,FALSE,0,1
National Institute of Teaching,2024,npq-early-headship-coaching-offer,1000,800,0,FALSE,0,1
Ambition Institute,2024,npq-leading-primary-mathematics,1007,107,19,TRUE,,1
Best Practice Network,2024,npq-leading-primary-mathematics,1013,113,25,TRUE,,1
Church of England,2024,npq-leading-primary-mathematics,1019,119,31,TRUE,,1
Education Development Trust,2024,npq-leading-primary-mathematics,1027,127,39,TRUE,,1
School-Led Network,2024,npq-leading-primary-mathematics,1035,135,47,TRUE,,1
LLSE,2024,npq-leading-primary-mathematics,1043,143,55,TRUE,,1
Teach First,2024,npq-leading-primary-mathematics,1051,151,63,TRUE,,1
Teacher Development Trust,2024,npq-leading-primary-mathematics,1059,159,71,TRUE,,1
UCL Institute of Education,2024,npq-leading-primary-mathematics,1067,167,79,TRUE,,1
National Institute of Teaching,2024,npq-leading-primary-mathematics,1000,800,0,TRUE,,1

0 comments on commit 72f36db

Please sign in to comment.