From 02a77e0889511790a21d73e8d0ac698f2336b697 Mon Sep 17 00:00:00 2001
From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com>
Date: Tue, 14 Jan 2025 15:04:41 +0000
Subject: [PATCH 1/4] CLDC-3835: Export merged organisations as inactive
(#2896)
* Export active to CDS as false for merged orgs
* Export status to CDS for orgs
---
.../exports/organisation_export_constants.rb | 3 ++-
.../exports/organisation_export_service.rb | 2 ++
spec/fixtures/exports/organisation.xml | 1 +
.../organisation_export_service_spec.rb | 21 +++++++++++++++++++
4 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/app/services/exports/organisation_export_constants.rb b/app/services/exports/organisation_export_constants.rb
index 3a1c5fb48..6c78a55db 100644
--- a/app/services/exports/organisation_export_constants.rb
+++ b/app/services/exports/organisation_export_constants.rb
@@ -22,6 +22,7 @@ module Exports::OrganisationExportConstants
"dsa_signed_at",
"dpo_email",
"profit_status",
- "group"
+ "group",
+ "status"
]
end
diff --git a/app/services/exports/organisation_export_service.rb b/app/services/exports/organisation_export_service.rb
index afcf16cb0..8ceba93a9 100644
--- a/app/services/exports/organisation_export_service.rb
+++ b/app/services/exports/organisation_export_service.rb
@@ -65,6 +65,8 @@ module Exports
attribute_hash["available_from"] = organisation.available_from&.iso8601
attribute_hash["profit_status"] = nil # will need update when we add the field to the org
attribute_hash["group"] = nil # will need update when we add the field to the org
+ attribute_hash["status"] = organisation.status
+ attribute_hash["active"] = attribute_hash["status"] == :active
attribute_hash
end
diff --git a/spec/fixtures/exports/organisation.xml b/spec/fixtures/exports/organisation.xml
index 70c699915..f70ac2b7d 100644
--- a/spec/fixtures/exports/organisation.xml
+++ b/spec/fixtures/exports/organisation.xml
@@ -22,5 +22,6 @@
{dpo_email}
+ active
diff --git a/spec/services/exports/organisation_export_service_spec.rb b/spec/services/exports/organisation_export_service_spec.rb
index 199ee239e..6ef66161a 100644
--- a/spec/services/exports/organisation_export_service_spec.rb
+++ b/spec/services/exports/organisation_export_service_spec.rb
@@ -84,6 +84,27 @@ RSpec.describe Exports::OrganisationExportService do
it "returns the list with correct archive" do
expect(export_service.export_xml_organisations).to eq({ expected_zip_filename.gsub(".zip", "") => start_time })
end
+
+ context "and the organisation is merged" do
+ let(:expected_content) { replace_entity_ids(organisation, xml_export_file.read) }
+
+ before do
+ organisation.update!(merge_date: Time.zone.yesterday)
+ expected_content.sub!("true", "false")
+ expected_content.sub!("", "#{organisation.merge_date.iso8601}")
+ expected_content.sub!("active", "merged")
+ end
+
+ it "generates an XML export file with the expected content within the ZIP file" do
+ expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) do |_, content|
+ entry = Zip::File.open_buffer(content).find_entry(expected_data_filename)
+ expect(entry).not_to be_nil
+ expect(entry.get_input_stream.read).to eq(expected_content)
+ end
+
+ export_service.export_xml_organisations
+ end
+ end
end
context "and multiple organisations are available for export" do
From d8fa3cf7fe65d552fe57ccccdd5fbae55dd6996f Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Wed, 15 Jan 2025 13:06:46 +0000
Subject: [PATCH 2/4] CLDC-3816 Update rails admin styling (#2879)
* Update rails admin console layout
* Update dashboard and view tables
* lint
* More lint
* Inline actions
* Re-add filters
* Update buttons
* Update validation documentation generating (#2894)
* Update documentation generator to use relevant translation files
* Add and use collection_year instead of from/to in log validations
---
app/frontend/styles/_custom-rails-admin.scss | 34 ++++
app/frontend/styles/application.scss | 1 +
app/services/documentation_generator.rb | 58 +++---
.../layouts/rails_admin/_navigation.html.erb | 9 +
.../layouts/rails_admin/application.html.erb | 70 +++++++
.../rails_admin/main/_submit_buttons.html.erb | 25 +++
app/views/rails_admin/main/dashboard.html.erb | 68 +++++++
app/views/rails_admin/main/delete.html.erb | 21 ++
app/views/rails_admin/main/index.html.erb | 187 ++++++++++++++++++
config/initializers/assets.rb | 2 +
.../{financial.yml => financial.en.yml} | 0
.../20250110150609_add_collection_year.rb | 5 +
db/schema.rb | 3 +-
.../generate_lettings_documentation.rake | 1 +
.../set_log_validation_collection_year.rake | 6 +
...set_log_validation_collection_year_spec.rb | 29 +++
spec/services/documentation_generator_spec.rb | 12 +-
17 files changed, 498 insertions(+), 33 deletions(-)
create mode 100644 app/frontend/styles/_custom-rails-admin.scss
create mode 100644 app/views/layouts/rails_admin/_navigation.html.erb
create mode 100644 app/views/layouts/rails_admin/application.html.erb
create mode 100644 app/views/rails_admin/main/_submit_buttons.html.erb
create mode 100644 app/views/rails_admin/main/dashboard.html.erb
create mode 100644 app/views/rails_admin/main/delete.html.erb
create mode 100644 app/views/rails_admin/main/index.html.erb
rename config/locales/validations/lettings/{financial.yml => financial.en.yml} (100%)
create mode 100644 db/migrate/20250110150609_add_collection_year.rb
create mode 100644 lib/tasks/set_log_validation_collection_year.rake
create mode 100644 spec/lib/tasks/set_log_validation_collection_year_spec.rb
diff --git a/app/frontend/styles/_custom-rails-admin.scss b/app/frontend/styles/_custom-rails-admin.scss
new file mode 100644
index 000000000..2652b8480
--- /dev/null
+++ b/app/frontend/styles/_custom-rails-admin.scss
@@ -0,0 +1,34 @@
+.rails-admin-sidescroll {
+ overflow-x: scroll;
+}
+
+.rails-admin-description_field {
+ min-width: 500px;
+}
+
+.rails-admin-case_field {
+ min-width: 500px;
+}
+
+.rails-admin-error_message_field {
+ min-width: 500px;
+}
+
+.rails-admin-actions {
+ min-width: 160px;
+
+ ul {
+ float: right;
+ }
+}
+
+.rails-admin-filters-box {
+ .filter {
+ // stylelint-disable-next-line declaration-no-important
+ display: flex !important;
+ }
+
+ button {
+ min-width: 20%;
+ }
+}
diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss
index 3e75107bd..94135074e 100644
--- a/app/frontend/styles/application.scss
+++ b/app/frontend/styles/application.scss
@@ -48,6 +48,7 @@ $govuk-breakpoints: (
@import "search";
@import "sub-navigation";
@import "unread-notification";
+@import "custom-rails-admin";
// App utilities
.app-\!-colour-muted {
diff --git a/app/services/documentation_generator.rb b/app/services/documentation_generator.rb
index d77a4e093..43426d8d4 100644
--- a/app/services/documentation_generator.rb
+++ b/app/services/documentation_generator.rb
@@ -18,14 +18,16 @@ class DocumentationGenerator
next
end
- validation_source = method(meth).source
+ validation = method(meth)
+ validation_source = validation.source
+ file_path = validation.source_location[0]
helper_methods_source = all_helper_methods.map { |helper_method|
if validation_source.include?(helper_method.to_s)
method(helper_method).source
end
}.compact.join("\n")
- response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form)
+ response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form, file_path)
next unless response
begin
@@ -41,19 +43,19 @@ class DocumentationGenerator
def describe_bu_validations(client, form, row_parser_class, all_validation_methods, all_helper_methods, field_mapping_for_errors, log_type)
all_validation_methods.each do |meth|
- if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: true, from: form.start_date, log_type:).exists?
+ if LogValidation.where(validation_name: meth.to_s, bulk_upload_specific: true, collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}", log_type:).exists?
Rails.logger.info("Validation #{meth} already exists for #{form.start_date.year}")
next
end
-
- validation_source = row_parser_class.instance_method(meth).source
+ validation = row_parser_class.instance_method(meth)
+ validation_source = validation.source
helper_methods_source = all_helper_methods.map { |helper_method|
if validation_source.include?(helper_method.to_s)
row_parser_class.instance_method(helper_method).source
end
}.compact.join("\n")
- response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form)
+ response = describe_hard_validation(client, meth, validation_source, helper_methods_source, form, validation.source_location[0])
next unless response
begin
@@ -69,7 +71,7 @@ class DocumentationGenerator
def describe_soft_validations(client, all_validation_methods, all_helper_methods, log_type)
validation_descriptions = {}
- all_validation_methods.each do |meth|
+ all_validation_methods[0..5].each do |meth|
validation_source = method(meth).source
helper_methods_source = all_helper_methods.map { |helper_method|
if validation_source.include?(helper_method.to_s)
@@ -101,8 +103,8 @@ class DocumentationGenerator
private
- def describe_hard_validation(client, meth, validation_source, helper_methods_source, form)
- en_yml = File.read("./config/locales/en.yml")
+ def describe_hard_validation(client, meth, validation_source, helper_methods_source, form, file_path)
+ en_yml = File.read(translation_file_path(form, file_path))
begin
client.chat(
@@ -166,14 +168,6 @@ private
required: %w[error_message field],
},
},
- from: {
- type: :number,
- description: "the year from which the validation starts. If this validation runs for logs with a startdate after a certain year, specify that year here, only if it is not specified in the validation method, leave this field blank",
- },
- to: {
- type: :number,
- description: "the year in which the validation ends. If this validation runs for logs with a startdate before a certain year, specify that year here, only if it is not specified in the validation method, leave this field blank",
- },
validation_type: {
type: :string,
enum: %w[presence format minimum maximum range inclusion length other],
@@ -271,8 +265,7 @@ Look at these helper methods where needed to understand what is being checked in
error_message: error["error_message"],
case: case_info["case_description"],
section: form.get_question(error["field"], nil)&.subsection&.id,
- from: case_info["from"] || "",
- to: case_info["to"] || "",
+ collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}",
validation_type: case_info["validation_type"],
hard_soft: "hard",
other_validated_models: case_info["other_validated_models"])
@@ -295,8 +288,7 @@ Look at these helper methods where needed to understand what is being checked in
error_message: error["error_message"],
case: case_info["case_description"],
section: form.get_question(error_field, nil)&.subsection&.id,
- from: form.start_date,
- to: form.start_date + 1.year,
+ collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}",
validation_type: case_info["validation_type"],
hard_soft: "hard",
other_validated_models: case_info["other_validated_models"],
@@ -333,7 +325,7 @@ Look at these helper methods where needed to understand what is being checked in
return
end
- if LogValidation.where(validation_name: validation_depends_on_hash.keys.first, field: page_the_validation_applied_to.questions.first.id, from: form.start_date, log_type:).exists?
+ if LogValidation.where(validation_name: validation_depends_on_hash.keys.first, field: page_the_validation_applied_to.questions.first.id, collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}", log_type:).exists?
Rails.logger.info("Validation #{validation_depends_on_hash.keys.first} already exists for #{page_the_validation_applied_to.questions.first.id} for start year #{form.start_date.year}")
return
end
@@ -360,12 +352,30 @@ Look at these helper methods where needed to understand what is being checked in
error_message:,
case: case_info,
section: form.get_question(page_the_validation_applied_to.questions.first.id, nil)&.subsection&.id,
- from: form.start_date,
- to: form.start_date + 1.year,
+ collection_year: "#{form.start_date.year}/#{form.start_date.year + 1}",
validation_type: result["validation_type"],
hard_soft: "soft",
other_validated_models: result["other_validated_models"])
Rails.logger.info("******** described #{validation_depends_on_hash.keys.first} for #{page_the_validation_applied_to.questions.first.id} ********")
end
+
+ TRANSLATION_FILE_MAPPINGS = {
+ "property" => "property_information",
+ }.freeze
+
+ def translation_file_path(form, file_path)
+ return "./config/locales/validations/#{form.type}/#{form.start_date.year}/bulk_upload.en.yml" if file_path.include?("bulk_upload")
+
+ file_name = file_path.split("/").last.gsub("_validations.rb", "")
+ translation_file_name = TRANSLATION_FILE_MAPPINGS[file_name] || file_name
+
+ file_path = "./config/locales/validations/#{form.type}/#{translation_file_name}.en.yml"
+ return file_path if File.exist?(file_path)
+
+ shared_file_path = "./config/locales/validations/#{translation_file_name}.en.yml"
+ return shared_file_path if File.exist?(shared_file_path)
+
+ "./config/locales/en.yml"
+ end
end
diff --git a/app/views/layouts/rails_admin/_navigation.html.erb b/app/views/layouts/rails_admin/_navigation.html.erb
new file mode 100644
index 000000000..6c5f77aa3
--- /dev/null
+++ b/app/views/layouts/rails_admin/_navigation.html.erb
@@ -0,0 +1,9 @@
+<%= govuk_header(
+ classes: "app-header app-header--orange",
+ homepage_url: Rails.application.routes.url_helpers.root_path,
+ navigation_classes: "govuk-header__navigation--end",
+ ) do |component|
+ component.with_product_name(name: t("service_name"))
+ component.with_navigation_item(text: "Your account", href: Rails.application.routes.url_helpers.account_path)
+ component.with_navigation_item(text: "Sign out", href: Rails.application.routes.url_helpers.destroy_user_session_path)
+ end %>
diff --git a/app/views/layouts/rails_admin/application.html.erb b/app/views/layouts/rails_admin/application.html.erb
new file mode 100644
index 000000000..27dc747fd
--- /dev/null
+++ b/app/views/layouts/rails_admin/application.html.erb
@@ -0,0 +1,70 @@
+