From 9ed5ef9c8075a989f14878d2f3b33fdef7a85fe5 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:45:33 +0100 Subject: [PATCH] Make uploading organisation search and filter by the bulk upload organisation id --- app/components/bulk_upload_summary_component.html.erb | 2 +- app/models/bulk_upload.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/components/bulk_upload_summary_component.html.erb b/app/components/bulk_upload_summary_component.html.erb index 3c6711dee..bbdd35ecd 100644 --- a/app/components/bulk_upload_summary_component.html.erb +++ b/app/components/bulk_upload_summary_component.html.erb @@ -9,7 +9,7 @@

Uploaded by: <%= bulk_upload.user.name %> (<%= bulk_upload.user.email %>)

-

Uploading organisation: <%= bulk_upload.user.organisation.name %>

+

Uploading organisation: <%= bulk_upload.organisation.name %>

Time of upload: <%= bulk_upload.created_at.to_formatted_s(:govuk_date_and_time) %>

diff --git a/app/models/bulk_upload.rb b/app/models/bulk_upload.rb index af5a672d5..c6f62ba7e 100644 --- a/app/models/bulk_upload.rb +++ b/app/models/bulk_upload.rb @@ -15,7 +15,7 @@ class BulkUpload < ApplicationRecord scope :search_by_filename, ->(filename) { where("filename ILIKE ?", "%#{filename}%") } scope :search_by_user_name, ->(name) { where(user_id: User.where("name ILIKE ?", "%#{name}%").select(:id)) } scope :search_by_user_email, ->(email) { where(user_id: User.where("email ILIKE ?", "%#{email}%").select(:id)) } - scope :search_by_organisation_name, ->(name) { where(user_id: User.joins(:organisation).where("organisations.name ILIKE ?", "%#{name}%").select(:id)) } + scope :search_by_organisation_name, ->(name) { where(organisation_id: Organisation.where("name ILIKE ?", "%#{name}%").select(:id)) } scope :search_by, lambda { |param| search_by_filename(param) @@ -34,7 +34,7 @@ class BulkUpload < ApplicationRecord scope :filter_by_uploaded_by, ->(user_id, _user = nil) { where(user_id:) } scope :filter_by_user_text_search, ->(param, _user = nil) { where(user_id: User.search_by(param).select(:id)) } scope :filter_by_user, ->(user_id, _user = nil) { user_id.present? ? where(user_id:) : all } - scope :filter_by_uploading_organisation, ->(organisation_id, _user = nil) { where(user_id: User.where(organisation_id:).select(:id)) } + scope :filter_by_uploading_organisation, ->(organisation_id, _user = nil) { where(organisation_id:) } def completed? incomplete_logs = logs.where.not(status: "completed") @@ -151,6 +151,10 @@ class BulkUpload < ApplicationRecord User.find_by(id: moved_user_id)&.name end + def organisation + Organisation.find_by(id: organisation_id) + end + private def generate_identifier