From c1b71e2fa1e49da82b15ee7f12148a372face09c Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Fri, 23 Mar 2018 15:27:15 +0100 Subject: Check if at least one filter is set on dashboard When listing issues and merge requests on dasboard page, make sure that at least one filter is enabled. User's id is used in search autocomplete widget instead of username, which allows presetting user in filter dropdowns. Related to #43246 --- app/controllers/dashboard_controller.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'app/controllers/dashboard_controller.rb') diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 280ed93faf8..d228956d8e3 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -2,9 +2,17 @@ class DashboardController < Dashboard::ApplicationController include IssuesAction include MergeRequestsAction + FILTER_PARAMS = [ + :author_id, + :assignee_id, + :milestone_title, + :label_name + ].freeze + before_action :event_filter, only: :activity before_action :projects, only: [:issues, :merge_requests] before_action :set_show_full_reference, only: [:issues, :merge_requests] + before_action :check_filters_presence, only: [:issues, :merge_requests] respond_to :html @@ -39,4 +47,10 @@ class DashboardController < Dashboard::ApplicationController def set_show_full_reference @show_full_reference = true end + + def check_filters_presence + @no_filters_set = FILTER_PARAMS.none? { |k| params.key?(k) } + + render action: action_name if @no_filters_set + end end -- cgit v1.2.1 From d10416e231a27c63c322ba7338f2ea8279436336 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 27 Mar 2018 17:29:13 +0200 Subject: Fixed dashboard filtering tests --- app/controllers/dashboard_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'app/controllers/dashboard_controller.rb') diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index d228956d8e3..68d328fa797 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -12,7 +12,7 @@ class DashboardController < Dashboard::ApplicationController before_action :event_filter, only: :activity before_action :projects, only: [:issues, :merge_requests] before_action :set_show_full_reference, only: [:issues, :merge_requests] - before_action :check_filters_presence, only: [:issues, :merge_requests] + before_action :check_filters_presence!, only: [:issues, :merge_requests] respond_to :html @@ -48,9 +48,14 @@ class DashboardController < Dashboard::ApplicationController @show_full_reference = true end - def check_filters_presence + def check_filters_presence! @no_filters_set = FILTER_PARAMS.none? { |k| params.key?(k) } - render action: action_name if @no_filters_set + return unless @no_filters_set + + respond_to do |format| + format.html + format.atom { head :bad_request } + end end end -- cgit v1.2.1