diff --git a/app/services/apis/bops/client.rb b/app/services/apis/bops/client.rb index ff4b376014..32ba477350 100644 --- a/app/services/apis/bops/client.rb +++ b/app/services/apis/bops/client.rb @@ -10,10 +10,8 @@ class Client def call(local_authority, submission) faraday(local_authority).post("planning_applications") do |request| request.options[:timeout] = TIMEOUT - request.body = submission.merge( - "send_email" => "false", - "from_production" => "true" - ).to_json + submission["metadata"]["source"] = "BOPS production" + request.body = submission.to_json end end diff --git a/docs/schema-update.md b/docs/schema-update.md index 93dac3ac36..480604d1e6 100644 --- a/docs/schema-update.md +++ b/docs/schema-update.md @@ -7,6 +7,7 @@ Periodically we need to make changes based on a new release of the [ODP schema][ - Create new version directories at `engines/bops_api/schemas/odp/$VERSION/` and `engines/bops_api/spec/fixtures/examples/odp/$VERSION/` - Update the version number and source URL in `engines/bops_api/lib/bops_api/schemas.rb` - Save a copy of the new `schema.json` as `engines/bops_api/schemas/odp/$VERSION/submission.json` +- Within the `metadata` key, edit the `source` type to be any string as we want to enable different submission services. Currently this is set as `"const": "PlanX"` so this needs to be removed until future versions allow for other sources. - Copy the other JSON files from the previous version to the current version: we manage these ourselves separately from the main release cycle - Retrieve example responses from the [ODP schema examples], using the correct tag and subdirectory for the new version (e.g., tag `v3.1.4` subdirectory `v3.1.4/examples/`) - Note that these do not all match our naming scheme but mostly do correspond in a logical way; e.g., their `lawfulDevelopmentCertificate/existing.json` becomes our `validLawfulDevelopmentCeriticateExisting.json` and so on diff --git a/engines/bops_api/app/jobs/bops_api/planning_application_dependency_job.rb b/engines/bops_api/app/jobs/bops_api/planning_application_dependency_job.rb index c9e3bc56ff..cd9dc71148 100644 --- a/engines/bops_api/app/jobs/bops_api/planning_application_dependency_job.rb +++ b/engines/bops_api/app/jobs/bops_api/planning_application_dependency_job.rb @@ -16,7 +16,7 @@ def perform(planning_application:, user:, files:, params:, email_sending_permitt @user = user @params = params - AnonymisationService.new(planning_application:).call! if planning_application.from_production? + Application::AnonymisationService.new(planning_application:).call! if planning_application.from_production? process_document_checklist_items(planning_application) Application::DocumentsService.new(planning_application:, user:, files:).call! diff --git a/engines/bops_api/app/services/bops_api/application/creation_service.rb b/engines/bops_api/app/services/bops_api/application/creation_service.rb index d803c6eff2..45a17610a0 100644 --- a/engines/bops_api/app/services/bops_api/application/creation_service.rb +++ b/engines/bops_api/app/services/bops_api/application/creation_service.rb @@ -20,7 +20,7 @@ def call! private - attr_reader :local_authority, :params, :user + attr_reader :local_authority, :params, :user, :email_sending_permitted def data_params @data_params ||= params.fetch(:data) @@ -67,14 +67,14 @@ def parsers def other_params { user_role: data_params[:user_role], - from_production: params[:from_production].present? + from_production: from_bops_production? } end def save!(planning_application) PlanningApplication.transaction do if planning_application.save! - PlanningApplicationDependencyJob.perform_later(planning_application:, user:, files:, params:, email_sending_permitted: @email_sending_permitted) + PlanningApplicationDependencyJob.perform_later(planning_application:, user:, files:, params:, email_sending_permitted:) end end @@ -94,6 +94,10 @@ def initialize_from_planning_application(planning_application) def raise_not_permitted_in_production_error raise BopsApi::Errors::NotPermittedError, "Creating planning applications using this endpoint is not permitted in production" end + + def from_bops_production? + params.dig("metadata", "source") == "BOPS production" + end end end end diff --git a/engines/bops_api/schemas/odp/v0.7.0/submission.json b/engines/bops_api/schemas/odp/v0.7.0/submission.json index 59a988107e..19f8dc28bb 100644 --- a/engines/bops_api/schemas/odp/v0.7.0/submission.json +++ b/engines/bops_api/schemas/odp/v0.7.0/submission.json @@ -8464,7 +8464,6 @@ "type": "object" }, "source": { - "const": "PlanX", "type": "string" }, "submittedAt": { diff --git a/engines/bops_api/spec/services/application/creation_service_spec.rb b/engines/bops_api/spec/services/application/creation_service_spec.rb index bfc03cc73a..bbb14eb7ab 100644 --- a/engines/bops_api/spec/services/application/creation_service_spec.rb +++ b/engines/bops_api/spec/services/application/creation_service_spec.rb @@ -534,6 +534,7 @@ before do allow(ENV).to receive(:fetch).and_call_original allow(ENV).to receive(:fetch).with("BOPS_ENVIRONMENT", "development").and_return("production") + params[:metadata][:source] = "BOPS production" end it "calls the post application to staging job" do @@ -541,6 +542,14 @@ expect(BopsApi::PostApplicationToStagingJob).to have_been_enqueued end + + it "calls the anonymisation service" do + expect(BopsApi::Application::AnonymisationService).to receive(:new).and_call_original + expect(BopsApi::Application::DocumentsService).to receive(:new).and_call_original + + create_planning_application + perform_enqueued_jobs + end end end end diff --git a/engines/bops_api/swagger/v2/swagger_doc.yaml b/engines/bops_api/swagger/v2/swagger_doc.yaml index 4a1213eed6..dc7a105f16 100644 --- a/engines/bops_api/swagger/v2/swagger_doc.yaml +++ b/engines/bops_api/swagger/v2/swagger_doc.yaml @@ -5886,7 +5886,6 @@ components: - fee type: object source: - const: PlanX type: string submittedAt: "$ref": "#/components/definitions/DateTime"