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:
authorCamil Staps <info@camilstaps.nl>2019-07-27 09:26:53 +0300
committerCamil Staps <info@camilstaps.nl>2019-08-07 21:49:37 +0300
commitd4078b535c9854695e770cdfb5e0f4846a8cf64a (patch)
treed018c433af17263a419c41473e589f4e9e28ca38 /app/controllers/projects/starrers_controller.rb
parente726ed5e128893158f102b87e1407ec0a36fc3ce (diff)
Fix public/private starrers counts in special cases
Diffstat (limited to 'app/controllers/projects/starrers_controller.rb')
-rw-r--r--app/controllers/projects/starrers_controller.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/app/controllers/projects/starrers_controller.rb b/app/controllers/projects/starrers_controller.rb
index f69cff1b431..c8facea1d70 100644
--- a/app/controllers/projects/starrers_controller.rb
+++ b/app/controllers/projects/starrers_controller.rb
@@ -4,14 +4,31 @@ class Projects::StarrersController < Projects::ApplicationController
include SortingHelper
def index
- @sort = params[:sort].presence || sort_value_name
-
@starrers = UsersStarProjectsFinder.new(@project, params, current_user: @current_user).execute
+ # Normally the number of public starrers is equal to the number of visible
+ # starrers. We need to fix the counts in two cases: when the current user
+ # is an admin (and can see everything) and when the current user has a
+ # private profile and has starred the project (and can see itself).
+ @public_count =
+ if @current_user&.admin?
+ @starrers.with_public_profile.count
+ elsif @current_user&.private_profile && has_starred_project?(@starrers)
+ @starrers.size - 1
+ else
+ @starrers.size
+ end
+
@total_count = @project.starrers.size
- @public_count = @starrers.size
@private_count = @total_count - @public_count
+ @sort = params[:sort].presence || sort_value_name
@starrers = @starrers.sort_by_attribute(@sort).page(params[:page])
end
+
+ private
+
+ def has_starred_project?(starrers)
+ starrers.first { |starrer| starrer.user_id == current_user.id }
+ end
end