From 5ad0cf26551baff8f08af8562a8d45e6ec14d71a Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 23 Jan 2020 12:08:38 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/controllers/explore/projects_controller.rb | 33 ++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'app/controllers/explore') diff --git a/app/controllers/explore/projects_controller.rb b/app/controllers/explore/projects_controller.rb index 271f2b4b57d..a8a76b47bbe 100644 --- a/app/controllers/explore/projects_controller.rb +++ b/app/controllers/explore/projects_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class Explore::ProjectsController < Explore::ApplicationController + include PageLimiter include ParamsBackwardCompatibility include RendersMemberAccess include SortingHelper @@ -9,6 +10,13 @@ class Explore::ProjectsController < Explore::ApplicationController before_action :set_non_archived_param before_action :set_sorting + # Limit taken from https://gitlab.com/gitlab-org/gitlab/issues/38357 + before_action only: [:index, :trending, :starred] do + limit_pages(200) + end + + rescue_from PageOutOfBoundsError, with: :page_out_of_bounds + def index @projects = load_projects @@ -53,10 +61,14 @@ class Explore::ProjectsController < Explore::ApplicationController private - # rubocop: disable CodeReuse/ActiveRecord - def load_projects + def load_project_counts @total_user_projects_count = ProjectsFinder.new(params: { non_public: true }, current_user: current_user).execute @total_starred_projects_count = ProjectsFinder.new(params: { starred: true }, current_user: current_user).execute + end + + # rubocop: disable CodeReuse/ActiveRecord + def load_projects + load_project_counts projects = ProjectsFinder.new(current_user: current_user, params: params) .execute @@ -80,4 +92,21 @@ class Explore::ProjectsController < Explore::ApplicationController def sorting_field Project::SORTING_PREFERENCE_FIELD end + + def page_out_of_bounds(error) + load_project_counts + @max_page_number = error.message + + respond_to do |format| + format.html do + render "page_out_of_bounds", status: :bad_request + end + + format.json do + render json: { + html: view_to_html_string("explore/projects/page_out_of_bounds") + }, status: :bad_request + end + end + end end -- cgit v1.2.3