Merge pull request #2941 from urbanrotnik/ur-sci-5124

Fix teams query [SCI-5124]
This commit is contained in:
Urban Rotnik 2020-11-06 12:08:54 +01:00 committed by GitHub
commit a06f421c88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,16 +38,15 @@ class Repository < RepositoryBase
scope :archived, -> { where(archived: true) }
scope :accessible_by_teams, lambda { |teams|
left_outer_joins(:team_repositories)
.where('repositories.team_id IN (?) '\
'OR team_repositories.team_id IN (?) '\
'OR repositories.permission_level = ? '\
'OR repositories.permission_level = ? ',
teams,
teams,
Extends::SHARED_INVENTORIES_PERMISSION_LEVELS[:shared_read],
Extends::SHARED_INVENTORIES_PERMISSION_LEVELS[:shared_write])
.distinct
accessible_repositories = left_outer_joins(:team_repositories)
accessible_repositories =
accessible_repositories
.where(team: teams)
.or(accessible_repositories.where(team_repositories: { team: teams }))
.or(accessible_repositories
.where(permission_level: [Extends::SHARED_INVENTORIES_PERMISSION_LEVELS[:shared_read],
Extends::SHARED_INVENTORIES_PERMISSION_LEVELS[:shared_write]]))
accessible_repositories.distinct
}
scope :assigned_to_project, lambda { |project|
@ -75,7 +74,7 @@ class Repository < RepositoryBase
repository = nil,
options = {}
)
repositories = repository&.id || Repository.accessible_by_teams(user.teams.pluck(:id)).pluck(:id)
repositories = repository&.id || Repository.accessible_by_teams(user.teams).pluck(:id)
readable_rows = RepositoryRow.joins(:repository).where(repository_id: repositories)