summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps <info@camilstaps.nl>2019-02-02 20:22:19 +0100
committerCamil Staps <info@camilstaps.nl>2019-08-07 20:49:16 +0200
commit50f5f2e8aebf7ea3cdc9b2d133c9246925f749c4 (patch)
tree5e60baacc5e040aa917390bca651c1aacc8b91c6
parent66032506b54dc4a9fcce99d2053a65cbaa02d2a2 (diff)
downloadgitlab-ce-50f5f2e8aebf7ea3cdc9b2d133c9246925f749c4.tar.gz
Remove private profiles from starrers view of projects
-rw-r--r--app/controllers/projects/starrers_controller.rb7
-rw-r--r--app/finders/users_star_projects_finder.rb14
-rw-r--r--app/models/users_star_project.rb1
-rw-r--r--app/views/projects/starrers/index.html.haml5
4 files changed, 21 insertions, 6 deletions
diff --git a/app/controllers/projects/starrers_controller.rb b/app/controllers/projects/starrers_controller.rb
index ac105faa550..006898a7427 100644
--- a/app/controllers/projects/starrers_controller.rb
+++ b/app/controllers/projects/starrers_controller.rb
@@ -9,8 +9,11 @@ class Projects::StarrersController < Projects::ApplicationController
def index
@sort = params[:sort].presence || sort_value_name
- @starrers = UsersStarProjectsFinder.new(params).execute
- @starrers = @starrers.by_project(@project)
+ @starrers = UsersStarProjectsFinder.new(params, @project, current_user: @current_user).execute
+
+ @total_count = @project.starrers.size
+ @public_count = @starrers.size
+ @private_count = @total_count - @public_count
@starrers = @starrers.sort_by_attribute(@sort).page(params[:page])
end
diff --git a/app/finders/users_star_projects_finder.rb b/app/finders/users_star_projects_finder.rb
index 5a031a1f0cd..e3657f9915c 100644
--- a/app/finders/users_star_projects_finder.rb
+++ b/app/finders/users_star_projects_finder.rb
@@ -5,13 +5,17 @@ class UsersStarProjectsFinder
attr_accessor :params
- def initialize(params = {})
+ def initialize(params = {}, project, current_user: nil)
@params = params
+ @project = project
+ @current_user = current_user
end
def execute
stars = UsersStarProject.all.order_id_desc
+ stars = by_project(stars)
stars = by_search(stars)
+ stars = filter_visible_profiles(stars)
stars
end
@@ -21,4 +25,12 @@ class UsersStarProjectsFinder
def by_search(items)
params[:search].present? ? items.search(params[:search]) : items
end
+
+ def by_project(items)
+ items.by_project(@project)
+ end
+
+ def filter_visible_profiles(items)
+ items.with_visible_profile(@current_user)
+ end
end
diff --git a/app/models/users_star_project.rb b/app/models/users_star_project.rb
index 62d44aaf955..6eabdebd89c 100644
--- a/app/models/users_star_project.rb
+++ b/app/models/users_star_project.rb
@@ -15,6 +15,7 @@ class UsersStarProject < ApplicationRecord
scope :order_user_name_asc, -> { joins(:user).reorder('"users"."name" ASC') }
scope :order_user_name_desc, -> { joins(:user).reorder('"users"."name" DESC') }
scope :by_project, -> (project) { where(project_id: project.id) }
+ scope :with_visible_profile, -> (user) { joins(:user).where('"users"."private_profile" IS NULL OR "users"."private_profile" = ? OR "users"."id" = ?', false, user.id ) }
class << self
def sort_by_attribute(method)
diff --git a/app/views/projects/starrers/index.html.haml b/app/views/projects/starrers/index.html.haml
index 5d5fb9d74b2..c6665ce1183 100644
--- a/app/views/projects/starrers/index.html.haml
+++ b/app/views/projects/starrers/index.html.haml
@@ -2,9 +2,8 @@
.top-area.adjust
.nav-text
- %span.flex-project-title
- = _("Starrers of <strong>%{project_name}</strong>").html_safe % { project_name: sanitize_project_name(@project.name) }
- %span.badge.badge-pill= @starrers.total_count
+ - full_count_title = "#{@public_count} public and #{@private_count} private"
+ #{pluralize(@total_count, 'starrer')}: #{full_count_title}
- if @starrers.size > 0 || params[:search].present?
.nav-controls
= form_tag request.original_url, method: :get, class: 'form-inline user-search-form flex-users-form' do