diff options
author | Rubén Dávila <rdavila84@gmail.com> | 2016-02-27 03:08:25 +0300 |
---|---|---|
committer | Rubén Dávila <rdavila84@gmail.com> | 2016-02-27 03:34:52 +0300 |
commit | f96ce4079fba7adc25d6e54b87d2f171f43d14b7 (patch) | |
tree | 0acafa89dd4c99f14095b3238a250eb470ef2080 /app/controllers/projects/forks_controller.rb | |
parent | baa5f7fc25ad72db3b208724b7349d0944d219be (diff) |
Improve implementation to check read access to forks and add pagination.
Diffstat (limited to 'app/controllers/projects/forks_controller.rb')
-rw-r--r-- | app/controllers/projects/forks_controller.rb | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/app/controllers/projects/forks_controller.rb b/app/controllers/projects/forks_controller.rb index 0c551501ca4..671162e7649 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, + 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 |