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 ...@@ -9,8 +9,11 @@ class Projects::StarrersController < Projects::ApplicationController
def index def index
@sort = params[:sort].presence || sort_value_name @sort = params[:sort].presence || sort_value_name
@starrers = UsersStarProjectsFinder.new(params).execute @starrers = UsersStarProjectsFinder.new(params, @project, current_user: @current_user).execute
@starrers = @starrers.by_project(@project)
@total_count = @project.starrers.size
@public_count = @starrers.size
@private_count = @total_count - @public_count
@starrers = @starrers.sort_by_attribute(@sort).page(params[:page]) @starrers = @starrers.sort_by_attribute(@sort).page(params[:page])
end end
......
...@@ -5,13 +5,17 @@ class UsersStarProjectsFinder ...@@ -5,13 +5,17 @@ class UsersStarProjectsFinder
attr_accessor :params attr_accessor :params
def initialize(params = {}) def initialize(params = {}, project, current_user: nil)
@params = params @params = params
@project = project
@current_user = current_user
end end
def execute def execute
stars = UsersStarProject.all.order_id_desc stars = UsersStarProject.all.order_id_desc
stars = by_project(stars)
stars = by_search(stars) stars = by_search(stars)
stars = filter_visible_profiles(stars)
stars stars
end end
...@@ -21,4 +25,12 @@ class UsersStarProjectsFinder ...@@ -21,4 +25,12 @@ class UsersStarProjectsFinder
def by_search(items) def by_search(items)
params[:search].present? ? items.search(params[:search]) : items params[:search].present? ? items.search(params[:search]) : items
end end
def by_project(items)
items.by_project(@project)
end
def filter_visible_profiles(items)
items.with_visible_profile(@current_user)
end
end end
...@@ -15,6 +15,7 @@ class UsersStarProject < ApplicationRecord ...@@ -15,6 +15,7 @@ class UsersStarProject < ApplicationRecord
scope :order_user_name_asc, -> { joins(:user).reorder('"users"."name" ASC') } scope :order_user_name_asc, -> { joins(:user).reorder('"users"."name" ASC') }
scope :order_user_name_desc, -> { joins(:user).reorder('"users"."name" DESC') } scope :order_user_name_desc, -> { joins(:user).reorder('"users"."name" DESC') }
scope :by_project, -> (project) { where(project_id: project.id) } 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 class << self
def sort_by_attribute(method) def sort_by_attribute(method)
......
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
.top-area.adjust .top-area.adjust
.nav-text .nav-text
%span.flex-project-title - full_count_title = "#{@public_count} public and #{@private_count} private"
= _("Starrers of <strong>%{project_name}</strong>").html_safe % { project_name: sanitize_project_name(@project.name) } #{pluralize(@total_count, 'starrer')}: #{full_count_title}
%span.badge.badge-pill= @starrers.total_count
- if @starrers.size > 0 || params[:search].present? - if @starrers.size > 0 || params[:search].present?
.nav-controls .nav-controls
= form_tag request.original_url, method: :get, class: 'form-inline user-search-form flex-users-form' do = 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