Commit 50f5f2e8 authored by Camil Staps's avatar Camil Staps

Remove private profiles from starrers view of projects

parent 66032506
......@@ -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
......
......@@ -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
......@@ -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)
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment