Fix projects visibility in the sidebar [SCI-5338]

This commit is contained in:
Oleksii Kriuchykhin 2020-12-29 20:52:35 +01:00
parent a8991356b5
commit f43340a849
3 changed files with 3 additions and 16 deletions

View file

@ -14,7 +14,7 @@ module ProjectsHelper
end
def sidebar_folders_tree(team, user)
records = user.projects_tree(team) + ProjectFolder.inner_folders(team)
records = team.projects.active.visible_to(user, team) + ProjectFolder.inner_folders(team)
view_state = team.current_view_state(user)
records = case view_state.state.dig('projects', 'active', 'sort')
when 'new'

View file

@ -46,10 +46,8 @@ class Project < ApplicationRecord
scope :visible_to, (lambda do |user, team|
unless user.is_admin_of_team?(team)
left_outer_joins(:user_projects)
.where(
'visibility = 1 OR user_projects.user_id = :id',
id: user.id
).group(:id)
.where('visibility = 1 OR user_projects.user_id = :id', id: user.id)
.group(:id)
end
end)

View file

@ -438,17 +438,6 @@ class User < ApplicationRecord
result || []
end
def projects_tree(team)
result = team.projects
unless is_admin_of_team?(team)
# Only admins see all projects of the team
result = result.joins(:user_projects).where(
'visibility=1 OR user_projects.user_id=:user_id', user_id: id
)
end
result.where(archived: false)
end
# Finds all activities of user that is assigned to project. If user
# is not an owner of the project, user must be also assigned to
# module.