mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-25 09:13:05 +08:00
Fix project search in quick start controller [SCI-5915]
This commit is contained in:
parent
1d20258a2e
commit
4f4ab05740
3 changed files with 11 additions and 5 deletions
|
@ -20,9 +20,9 @@ module Dashboard
|
|||
end
|
||||
|
||||
def project_filter
|
||||
projects = current_team.projects.search(current_user, false, params[:query], 1, current_team)
|
||||
.where(user_projects: { user_id: current_user.id, role: %i(owner normal_user) })
|
||||
.select(:id, :name)
|
||||
projects = Project.managable_by_user(current_user)
|
||||
.search(current_user, false, params[:query], 1, current_team)
|
||||
.select(:id, :name)
|
||||
projects = projects.map { |i| { value: i.id, label: escape_input(i.name) } }
|
||||
if (projects.map { |i| i[:label] }.exclude? params[:query]) && params[:query].present?
|
||||
projects = [{ value: 0, label: params[:query] }] + projects
|
||||
|
|
|
@ -16,6 +16,12 @@ module Assignable
|
|||
.where('? = ANY(user_roles.permissions)', "::#{self.class.to_s.split('::').first}Permissions".constantize::READ)
|
||||
}
|
||||
|
||||
scope :managable_by_user, lambda { |user|
|
||||
joins(user_assignments: :user_role)
|
||||
.where(user_assignments: { user: user })
|
||||
.where('? = ANY(user_roles.permissions)', "::#{self.class.to_s.split('::').first}Permissions".constantize::MANAGE)
|
||||
}
|
||||
|
||||
after_create_commit do
|
||||
UserAssignment.create!(
|
||||
user: created_by,
|
||||
|
|
|
@ -4,6 +4,7 @@ class Project < ApplicationRecord
|
|||
include SearchableByNameModel
|
||||
include ViewableModel
|
||||
include PermissionCheckableModel
|
||||
include Assignable
|
||||
|
||||
enum visibility: { hidden: 0, visible: 1 }
|
||||
|
||||
|
@ -42,7 +43,6 @@ class Project < ApplicationRecord
|
|||
belongs_to :team, inverse_of: :projects, touch: true
|
||||
belongs_to :project_folder, inverse_of: :projects, optional: true, touch: true
|
||||
has_many :user_projects, inverse_of: :project
|
||||
has_many :user_assignments, as: :assignable, dependent: :destroy
|
||||
has_many :users, through: :user_assignments
|
||||
has_many :experiments, inverse_of: :project
|
||||
has_many :active_experiments, -> { where(archived: false) },
|
||||
|
@ -95,7 +95,7 @@ class Project < ApplicationRecord
|
|||
user.id
|
||||
)
|
||||
end
|
||||
new_query = new_query.where_attributes_like(:name, query, options)
|
||||
new_query = new_query.where_attributes_like('projects.name', query, options)
|
||||
|
||||
if include_archived
|
||||
return new_query
|
||||
|
|
Loading…
Reference in a new issue