mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 10:08:11 +08:00
update experiment and my_module search
This commit is contained in:
parent
8997ba10d1
commit
7e4f47f667
4 changed files with 68 additions and 48 deletions
|
@ -35,6 +35,8 @@ module UserAssignments
|
|||
user_role = parent_user_assignment.user_role
|
||||
user = parent_user_assignment.user
|
||||
new_user_assignment = UserAssignment.find_or_initialize_by(user: user, assignable: object)
|
||||
return if new_user_assignment.manually_assigned?
|
||||
|
||||
new_user_assignment.user_role = user_role
|
||||
new_user_assignment.assigned_by = @assigned_by
|
||||
new_user_assignment.assigned = :automatically
|
||||
|
|
|
@ -45,6 +45,13 @@ class Experiment < ApplicationRecord
|
|||
end
|
||||
}
|
||||
|
||||
scope :experiment_search_scope, lambda { |project_ids, user|
|
||||
joins(:user_assignments).where(
|
||||
project: project_ids,
|
||||
user_assignments: { user: user }
|
||||
)
|
||||
}
|
||||
|
||||
def self.search(
|
||||
user,
|
||||
include_archived,
|
||||
|
@ -53,37 +60,30 @@ class Experiment < ApplicationRecord
|
|||
current_team = nil,
|
||||
options = {}
|
||||
)
|
||||
project_ids =
|
||||
experiment_scope = experiment_search_scope(
|
||||
Project
|
||||
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
|
||||
.pluck(:id)
|
||||
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
|
||||
.pluck(:id),
|
||||
user
|
||||
)
|
||||
|
||||
if current_team
|
||||
projects_ids =
|
||||
new_query = experiment_search_scope(
|
||||
Project
|
||||
.search(user,
|
||||
include_archived,
|
||||
nil,
|
||||
1,
|
||||
current_team)
|
||||
.select('id')
|
||||
|
||||
new_query =
|
||||
Experiment
|
||||
.where('experiments.project_id IN (?)', projects_ids)
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
.search(user,
|
||||
include_archived,
|
||||
nil,
|
||||
1,
|
||||
current_team)
|
||||
.select('id'),
|
||||
user
|
||||
).where_attributes_like([:name, :description], query, options)
|
||||
return include_archived ? new_query : new_query.active
|
||||
elsif include_archived
|
||||
new_query =
|
||||
Experiment
|
||||
.where(project: project_ids)
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
new_query = experiment_scope.where_attributes_like([:name, :description], query, options)
|
||||
else
|
||||
new_query =
|
||||
Experiment
|
||||
.active
|
||||
.where(project: project_ids)
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
new_query = experiment_scope.active
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
end
|
||||
|
||||
# Show all results if needed
|
||||
|
|
|
@ -69,6 +69,13 @@ class MyModule < ApplicationRecord
|
|||
scope :workflow_ordered, -> { order(workflow_order: :asc) }
|
||||
scope :uncomplete, -> { where(state: 'uncompleted') }
|
||||
|
||||
scope :my_module_search_scope, lambda { |experiment_ids, user|
|
||||
joins(:user_assignments).where(
|
||||
experiment: experiment_ids,
|
||||
user_assignments: { user: user }
|
||||
).distinct
|
||||
}
|
||||
|
||||
# A module takes this much space in canvas (x, y) in database
|
||||
WIDTH = 30
|
||||
HEIGHT = 14
|
||||
|
@ -81,23 +88,24 @@ class MyModule < ApplicationRecord
|
|||
current_team = nil,
|
||||
options = {}
|
||||
)
|
||||
exp_ids =
|
||||
my_module_scope = my_module_search_scope(
|
||||
Experiment
|
||||
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
|
||||
.pluck(:id)
|
||||
.search(user, include_archived, nil, Constants::SEARCH_NO_LIMIT)
|
||||
.pluck(:id),
|
||||
user
|
||||
)
|
||||
|
||||
if current_team
|
||||
experiments_ids = Experiment
|
||||
.search(user,
|
||||
include_archived,
|
||||
nil,
|
||||
1,
|
||||
current_team)
|
||||
.select('id')
|
||||
new_query = MyModule
|
||||
.distinct
|
||||
.where('my_modules.experiment_id IN (?)', experiments_ids)
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
new_query = my_module_search_scope(
|
||||
Experiment
|
||||
.search(user,
|
||||
include_archived,
|
||||
nil,
|
||||
1,
|
||||
current_team)
|
||||
.select('id'),
|
||||
user
|
||||
).where_attributes_like([:name, :description], query, options)
|
||||
|
||||
if include_archived
|
||||
return new_query
|
||||
|
@ -105,16 +113,10 @@ class MyModule < ApplicationRecord
|
|||
return new_query.where('my_modules.archived = ?', false)
|
||||
end
|
||||
elsif include_archived
|
||||
new_query = MyModule
|
||||
.distinct
|
||||
.where('my_modules.experiment_id IN (?)', exp_ids)
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
new_query = my_module_scope.where_attributes_like([:name, :description], query, options)
|
||||
else
|
||||
new_query = MyModule
|
||||
.distinct
|
||||
.where('my_modules.experiment_id IN (?)', exp_ids)
|
||||
.where('my_modules.archived = ?', false)
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
new_query = my_module_scope.where('my_modules.archived = ?', false)
|
||||
.where_attributes_like([:name, :description], query, options)
|
||||
end
|
||||
|
||||
# Show all results if needed
|
||||
|
|
|
@ -60,10 +60,26 @@ module UserAssignments
|
|||
end
|
||||
|
||||
it 'does not propagate the user assignment if the object was manually assigned' do
|
||||
experiment_assignment = create :user_assignment, assignable: experiment_one, user: user_two, user_role: owner_role, assigned_by: user_one, assigned: :manually
|
||||
experiment_assignment = create :user_assignment,
|
||||
assignable: experiment_one,
|
||||
user: user_two,
|
||||
user_role: owner_role,
|
||||
assigned_by: user_one,
|
||||
assigned: :manually
|
||||
described_class.perform_now(project, user_two, technician_role, user_one)
|
||||
expect(experiment_assignment.reload.user_role).to eq owner_role
|
||||
end
|
||||
|
||||
it 'does propagate the user assignment if the object was automatically assigned' do
|
||||
experiment_assignment = create :user_assignment,
|
||||
assignable: experiment_one,
|
||||
user: user_two,
|
||||
user_role: owner_role,
|
||||
assigned_by: user_one,
|
||||
assigned: :automatically
|
||||
described_class.perform_now(project, user_two, technician_role, user_one)
|
||||
expect(experiment_assignment.reload.user_role).to eq technician_role
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue