diff --git a/app/controllers/saved_searches_controller.rb b/app/controllers/saved_searches_controller.rb index b13a94713d1..ca3cb4f2cb7 100644 --- a/app/controllers/saved_searches_controller.rb +++ b/app/controllers/saved_searches_controller.rb @@ -10,11 +10,11 @@ class SavedSearchesController < ApplicationController ].freeze def index - searches = organization.users.map(&:saved_searches).flatten - my_search = SavedSearch.for_user(current_user) respond_to do |format| format.html { render "index" } format.json do + searches = organization.users.includes(:saved_searches).map(&:saved_searches).flatten + my_search = SavedSearch.for_user(current_user) render json: { all_searches: SavedSearchSerializer.new(searches).serializable_hash[:data], user_searches: SavedSearchSerializer.new(my_search).serializable_hash[:data] } @@ -24,9 +24,10 @@ def index def show @search = SavedSearch.find_by_id(params[:id]) + @search_json = SavedSearchSerializer.new(@search).serializable_hash[:data] respond_to do |format| format.html { render "show" } - format.json { render json: SavedSearchSerializer.new(@search).serializable_hash[:data] } + format.json { render json: @search_json } end end @@ -48,10 +49,12 @@ def destroy end end + helper_method :organization + private def organization - @organization ||= BusinessLine.find_by(url: params[:decision_review_business_line_slug]) + @organization ||= Organization.find_by(url: params[:decision_review_business_line_slug]) end def save_search_create_params diff --git a/app/models/saved_search.rb b/app/models/saved_search.rb index 76d8844d8c2..98353ca9110 100644 --- a/app/models/saved_search.rb +++ b/app/models/saved_search.rb @@ -7,7 +7,6 @@ class SavedSearch < CaseflowRecord validates :description, presence: true, length: { maximum: 1000 } validate :saved_search_limit - # Ex:- scope :active, -> {where(:active => true)} scope :for_user, ->(user) { where(user: user).order(created_at: :desc) } private diff --git a/app/serializers/saved_search_serializer.rb b/app/serializers/saved_search_serializer.rb index d69943c4eb6..1d13ef81275 100644 --- a/app/serializers/saved_search_serializer.rb +++ b/app/serializers/saved_search_serializer.rb @@ -7,13 +7,13 @@ class SavedSearchSerializer attribute :description attribute :savedSearch, &:saved_search attribute :createdAt, &:created_at - attribute :userCssId do |object| - object.user.css_id - end - attribute :userFullName do |object| - object.user.full_name - end - attribute :userId do |object| - object.user.id + + attribute :user do |object| + user = object.try(:user) + { + css_id: user.try(:css_id), + full_name: user.try(:full_name), + id: user.id + } end end diff --git a/app/views/saved_searches/index.html.erb b/app/views/saved_searches/index.html.erb index af39cb940ef..97e9b9b133b 100644 --- a/app/views/saved_searches/index.html.erb +++ b/app/views/saved_searches/index.html.erb @@ -7,9 +7,12 @@ buildDate: build_date, flash: flash, serverNonComp: { + businessLine: organization.name, + businessLineUrl: organization.url, currentUserCssId: current_user.css_id, }, savedSearches: { + } }) %> <% end %> diff --git a/app/views/saved_searches/show.html.erb b/app/views/saved_searches/show.html.erb index af39cb940ef..5139095c181 100644 --- a/app/views/saved_searches/show.html.erb +++ b/app/views/saved_searches/show.html.erb @@ -10,6 +10,7 @@ currentUserCssId: current_user.css_id, }, savedSearches: { + @search_json } }) %> <% end %> diff --git a/client/app/nonComp/index.jsx b/client/app/nonComp/index.jsx index c4d5ce981b3..fb61c716cd2 100644 --- a/client/app/nonComp/index.jsx +++ b/client/app/nonComp/index.jsx @@ -59,7 +59,7 @@ class NonComp extends React.PureComponent { /> diff --git a/client/app/nonComp/pages/ReportPage.jsx b/client/app/nonComp/pages/ReportPage.jsx index 730454f2412..88500a7dec7 100644 --- a/client/app/nonComp/pages/ReportPage.jsx +++ b/client/app/nonComp/pages/ReportPage.jsx @@ -413,7 +413,7 @@ const ReportPage = ({ history }) => { >

Generate task report

- View saved searches + View saved searches
diff --git a/client/test/app/nonComp/components/reportPage/__snapshots__/DaysWaiting.test.js.snap b/client/test/app/nonComp/components/reportPage/__snapshots__/DaysWaiting.test.js.snap index 815a7ef8163..12599d592e6 100644 --- a/client/test/app/nonComp/components/reportPage/__snapshots__/DaysWaiting.test.js.snap +++ b/client/test/app/nonComp/components/reportPage/__snapshots__/DaysWaiting.test.js.snap @@ -15,7 +15,7 @@ exports[`DaysWaiting renders correctly 1`] = ` View saved searches diff --git a/config/routes.rb b/config/routes.rb index 4c207d0aff9..d305ec5cec2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -308,7 +308,7 @@ get '/remands(/*path)', to: redirect('/supplemental_claims/%{path}') resources :decision_reviews, param: :business_line_slug do - resources :saved_searches, only: [:index, :create, :destroy, :show] + resources :searches, controller: :saved_searches, only: [:index, :create, :destroy, :show] resources :tasks, controller: :decision_reviews, param: :task_id, only: [:show, :update] do member do get :history diff --git a/spec/controllers/saved_searches_controller_spec.rb b/spec/controllers/saved_searches_controller_spec.rb index 6bc0553ef33..9de07b97f96 100644 --- a/spec/controllers/saved_searches_controller_spec.rb +++ b/spec/controllers/saved_searches_controller_spec.rb @@ -3,22 +3,20 @@ describe SavedSearchesController, :postgres, type: :controller do let(:user) { create(:user, :vha_admin_user, :with_saved_search_reports) } let(:saved_search) { create(:saved_search, user: user) } - let(:non_comp_org) { VhaBusinessLine.singleton } let(:default_user) { create(:user) } let(:vha_business_line) { VhaBusinessLine.singleton } - let(:options) { { format: :json, decision_review_business_line_slug: non_comp_org.url } } - let(:delete_param) { { id: user.saved_searches.first.id, decision_review_business_line_slug: non_comp_org.url } } + let(:options) { { format: :json, decision_review_business_line_slug: vha_business_line.url } } + let(:delete_param) { { id: user.saved_searches.first.id, decision_review_business_line_slug: vha_business_line.url } } before do User.stub = user - non_comp_org.add_user(user) end describe "#create" do let(:valid_params) do { - decision_review_business_line_slug: non_comp_org.url, + decision_review_business_line_slug: vha_business_line.url, search: { name: Faker::Name.name, description: Faker::Lorem.sentence, @@ -39,7 +37,7 @@ } end - context "VHA user creating saved search" do + context "VHA admin user creating saved search" do it "should create search" do expect { post :create, params: valid_params } .to change(SavedSearch, :count).by(1) @@ -58,9 +56,9 @@ end end - context "VHA user saved search not exists" do + context "VHA admin user saved search not exists" do it "retunrs a not found error" do - delete :destroy, params: { id: 0, decision_review_business_line_slug: non_comp_org.url } + delete :destroy, params: { id: 0, decision_review_business_line_slug: vha_business_line.url } expect(response).to have_http_status(:not_found) end @@ -122,7 +120,7 @@ subject do get :show, - params: { id: saved_search.id, format: :json, decision_review_business_line_slug: non_comp_org.url } + params: { id: saved_search.id, format: :json, decision_review_business_line_slug: vha_business_line.url } end it "returns specific saved search" do