mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-06 15:05:26 +08:00
Merge pull request #1596 from okriuchykhin/ok_SCI_3173
Fix duplicated projects in new report modal [SCI-3173]
This commit is contained in:
commit
d0a5f4fd6e
2 changed files with 9 additions and 8 deletions
|
@ -451,7 +451,7 @@ class ReportsController < ApplicationController
|
|||
|
||||
def load_visible_projects
|
||||
render_404 unless current_team
|
||||
projects = current_team.projects.visible_from_user_by_name(
|
||||
projects = Project.visible_from_user_by_name(
|
||||
current_user, current_team, search_params[:q]
|
||||
).limit(Constants::SEARCH_LIMIT).select(:id, :name)
|
||||
@visible_projects = projects.collect do |project|
|
||||
|
|
|
@ -54,15 +54,16 @@ class Project < ApplicationRecord
|
|||
scope :templates, -> { where(template: true) }
|
||||
|
||||
def self.visible_from_user_by_name(user, team, name)
|
||||
if user.is_admin_of_team? team
|
||||
return where('projects.archived IS FALSE AND projects.name ILIKE ?',
|
||||
"%#{name}%")
|
||||
end
|
||||
joins(:user_projects)
|
||||
projects = where(team: team).distinct
|
||||
if user.is_admin_of_team?(team)
|
||||
projects.where('projects.archived IS FALSE AND projects.name ILIKE ?', "%#{name}%")
|
||||
else
|
||||
projects.joins(:user_projects)
|
||||
.where('user_projects.user_id = ? OR projects.visibility = 1', user.id)
|
||||
.where('projects.archived IS FALSE AND projects.name ILIKE ?',
|
||||
"%#{name}%")
|
||||
end
|
||||
end
|
||||
|
||||
def self.search(
|
||||
user,
|
||||
|
|
Loading…
Reference in a new issue