Merge pull request #3038 from okriuchykhin/ok_SCI_5338

Fix projects visibility in the sidebar [SCI-5338]
This commit is contained in:
Alex Kriuchykhin 2021-01-05 13:57:40 +01:00 committed by GitHub
commit cda36a59cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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.