diff --git a/app/controllers/helpers/filter.rb b/app/controllers/helpers/filter.rb index 0a5b61cd8..9ba65cd8c 100644 --- a/app/controllers/helpers/filter.rb +++ b/app/controllers/helpers/filter.rb @@ -13,9 +13,9 @@ module Helpers::Filter current_user.support? ? logs.all.includes(:owning_organisation, :managing_organisation) : logs end - def set_session_filters + def set_session_filters(specific_org = false) new_filters = session[:case_logs_filters].present? ? JSON.parse(session[:case_logs_filters]) : {} - current_user.case_logs_filters.each { |filter| new_filters[filter] = params[filter] if params[filter].present? } + current_user.case_logs_filters(specific_org).each { |filter| new_filters[filter] = params[filter] if params[filter].present? } new_filters = new_filters.except("organisation") if params["organisation_select"] == "all" session[:case_logs_filters] = new_filters.to_json diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index 7588a15d8..a3e827549 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -45,7 +45,7 @@ class OrganisationsController < ApplicationController end def logs - set_session_filters + set_session_filters(true) if current_user.support? organisation_logs = CaseLog.all.where(owning_organisation_id: @organisation.id) diff --git a/app/models/user.rb b/app/models/user.rb index efbe21b0e..a9a88d808 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -108,8 +108,8 @@ class User < ApplicationRecord ROLES.except(:support) end - def case_logs_filters - if support? + def case_logs_filters(specific_org = false) + if support? && !specific_org %w[status years user organisation] else %w[status years user] diff --git a/app/views/case_logs/_log_filters.erb b/app/views/case_logs/_log_filters.erb index 23f581ccd..b0f3e07be 100644 --- a/app/views/case_logs/_log_filters.erb +++ b/app/views/case_logs/_log_filters.erb @@ -10,7 +10,7 @@ <%= render partial: "filters/checkbox_filter", locals: { f: f, options: years, label: "Collection year", category: "years" } %> <%= render partial: "filters/checkbox_filter", locals: { f: f, options: status_filters, label: "Status", category: "status" } %> <%= render partial: "filters/radio_filter", locals: { f: f, options: all_or_yours, label: "Logs", category: "user", } %> - <% if @current_user.support? %> + <% if @current_user.support? && request.path == "/logs" %> <%= render partial: "filters/radio_filter", locals: { f: f, options: { diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 166f67f25..0d4438231 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -549,6 +549,7 @@ RSpec.describe "User Features" do end end end + context "when the user is logged in as a support user" do let!(:support_user) { FactoryBot.create(:user, :support) } let!(:test_org_1) { FactoryBot.create(:organisation, name: "Test1") } diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index fb2cddde0..64907d407 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -349,11 +349,11 @@ RSpec.describe OrganisationsController, type: :request do end context "with a support user" do - let(:support_user) { FactoryBot.create(:user, :support) } + let(:user) { FactoryBot.create(:user, :support) } before do - allow(support_user).to receive(:need_two_factor_authentication?).and_return(false) - sign_in support_user + allow(user).to receive(:need_two_factor_authentication?).and_return(false) + sign_in user get "/organisations" end @@ -388,6 +388,15 @@ RSpec.describe OrganisationsController, type: :request do expect(page).not_to have_link case_log_id.to_s, href: "/logs/#{case_log_id}" end end + + it "has filters" do + expect(page).to have_content("Filters") + expect(page).to have_content("Collection year") + end + + it "does not have specific organisation filter" do + expect(page).not_to have_content("Specific organisation") + end end end