summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2016-02-29 17:00:23 +0000
committerRémy Coutable <remy@rymai.me>2016-03-01 12:13:32 +0100
commite11ab453ee4feb1926464b0060a46e4294e61c35 (patch)
tree8a6f29c37d7ae671884c9eb82a0db366087ff9bd
parent9052086d7b6c46d148854932ac5ee71462936568 (diff)
downloadgitlab-ce-e11ab453ee4feb1926464b0060a46e4294e61c35.tar.gz
Merge branch 'issue_13648' into 'master'
Improve implementation to check read access to forks and add pagination. Fixes #13648 The following optimizations where made: - Pagination was added. - Code to check for read permissions to forks was optimized, in the past we were doing too many queries for each project. See merge request !2991
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/projects/forks_controller.rb22
-rw-r--r--app/views/projects/forks/index.html.haml14
3 files changed, 23 insertions, 14 deletions
diff --git a/CHANGELOG b/CHANGELOG
index a55298c2e53..24fa4e8a808 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@ v 8.5.2
- Don't repeat labels listed on Labels tab
- Bring the "branded appearance" feature from EE to CE
- Fix error 500 when commenting on a commit
+ - Improve implementation to check read access to forks and add pagination
- Update Rails to 4.2.5.2
v 8.5.1
diff --git a/app/controllers/projects/forks_controller.rb b/app/controllers/projects/forks_controller.rb
index 0c551501ca4..a0835c9aad0 100644
--- a/app/controllers/projects/forks_controller.rb
+++ b/app/controllers/projects/forks_controller.rb
@@ -4,12 +4,22 @@ class Projects::ForksController < Projects::ApplicationController
before_action :authorize_download_code!
def index
- @sort = params[:sort] || 'id_desc'
- @all_forks = project.forks.includes(:creator).order_by(@sort)
-
- @public_forks, @protected_forks = @all_forks.partition do |project|
- can?(current_user, :read_project, project)
- end
+ base_query = project.forks.includes(:creator)
+
+ @forks = if current_user
+ base_query.where('projects.visibility_level IN (?) OR projects.id IN (?)',
+ Project.public_and_internal_levels,
+ current_user.authorized_projects.pluck(:id))
+ else
+ base_query.where('projects.visibility_level = ?', Project::PUBLIC)
+ end
+
+ @total_forks_count = base_query.size
+ @private_forks_count = @total_forks_count - @forks.size
+ @public_forks_count = @total_forks_count - @private_forks_count
+
+ @sort = params[:sort] || 'id_desc'
+ @forks = @forks.order_by(@sort).page(params[:page]).per(PER_PAGE)
end
def new
diff --git a/app/views/projects/forks/index.html.haml b/app/views/projects/forks/index.html.haml
index 42fa6fdb782..ace22625d1d 100644
--- a/app/views/projects/forks/index.html.haml
+++ b/app/views/projects/forks/index.html.haml
@@ -1,9 +1,7 @@
.top-area
.nav-text
- - public_count = @public_forks.size
- - protected_count = @protected_forks.size
- - full_count_title = "#{public_count} public and #{protected_count} private"
- == #{pluralize(@all_forks.size, 'fork')}: #{full_count_title}
+ - full_count_title = "#{@public_forks_count} public and #{@private_forks_count} private"
+ == #{pluralize(@total_forks_count, 'fork')}: #{full_count_title}
.nav-controls
= search_field_tag :filter_projects, nil, placeholder: 'Search forks', class: 'projects-list-filter project-filter-form-field form-control input-short',
@@ -41,17 +39,17 @@
.projects-list-holder
- - if @public_forks.blank?
+ - if @forks.blank?
%ul.content-list
%li
.nothing-here-block No forks to show
- else
- = render 'shared/projects/list', projects: @public_forks, use_creator_avatar: true,
+ = render 'shared/projects/list', projects: @forks, use_creator_avatar: true,
forks: true, show_last_commit_as_description: true
- - if protected_count > 0
+ - if @private_forks_count > 0
%ul.projects-list.private-forks-notice
%li.project-row
= icon('lock fw', base: 'circle', class: 'fa-lg private-fork-icon')
- %strong= pluralize(protected_count, 'private fork')
+ %strong= pluralize(@private_forks_count, 'private fork')
%span you have no access to.