Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-23 15:08:38 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-23 15:08:38 +0300
commit5ad0cf26551baff8f08af8562a8d45e6ec14d71a (patch)
tree57f1a6bad31bcd11efacd3fdfb9cc92f88fb6a86 /app/controllers/explore
parentf47c768fad17d4c876e96524f83f8306f071db66 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/explore')
-rw-r--r--app/controllers/explore/projects_controller.rb33
1 files changed, 31 insertions, 2 deletions
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