mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
use "do end" instead of {} at ActiveRecord scope lambda of app/models/principal.rb
git-svn-id: http://svn.redmine.org/redmine/trunk@20328 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
31beca84b3
commit
3e6622cd43
@ -41,7 +41,7 @@ class Principal < ActiveRecord::Base
|
|||||||
# Groups and active users
|
# Groups and active users
|
||||||
scope :active, lambda { where(:status => STATUS_ACTIVE) }
|
scope :active, lambda { where(:status => STATUS_ACTIVE) }
|
||||||
|
|
||||||
scope :visible, lambda {|*args|
|
scope :visible, (lambda do |*args|
|
||||||
user = args.first || User.current
|
user = args.first || User.current
|
||||||
|
|
||||||
if user.admin?
|
if user.admin?
|
||||||
@ -64,9 +64,9 @@ class Principal < ActiveRecord::Base
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
end)
|
||||||
|
|
||||||
scope :like, lambda {|q|
|
scope :like, (lambda do |q|
|
||||||
q = q.to_s
|
q = q.to_s
|
||||||
if q.blank?
|
if q.blank?
|
||||||
where({})
|
where({})
|
||||||
@ -85,13 +85,12 @@ class Principal < ActiveRecord::Base
|
|||||||
end.join(' AND ')
|
end.join(' AND ')
|
||||||
sql << ')'
|
sql << ')'
|
||||||
end
|
end
|
||||||
|
|
||||||
where(sql, params)
|
where(sql, params)
|
||||||
end
|
end
|
||||||
}
|
end)
|
||||||
|
|
||||||
# Principals that are members of a collection of projects
|
# Principals that are members of a collection of projects
|
||||||
scope :member_of, lambda {|projects|
|
scope :member_of, (lambda do |projects|
|
||||||
projects = [projects] if projects.is_a?(Project)
|
projects = [projects] if projects.is_a?(Project)
|
||||||
if projects.blank?
|
if projects.blank?
|
||||||
where("1=0")
|
where("1=0")
|
||||||
@ -101,9 +100,9 @@ class Principal < ActiveRecord::Base
|
|||||||
where(:status => [STATUS_LOCKED, STATUS_ACTIVE]).
|
where(:status => [STATUS_LOCKED, STATUS_ACTIVE]).
|
||||||
where("#{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
|
where("#{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
|
||||||
end
|
end
|
||||||
}
|
end)
|
||||||
# Principals that are not members of projects
|
# Principals that are not members of projects
|
||||||
scope :not_member_of, lambda {|projects|
|
scope :not_member_of, (lambda do |projects|
|
||||||
projects = [projects] unless projects.is_a?(Array)
|
projects = [projects] unless projects.is_a?(Array)
|
||||||
if projects.empty?
|
if projects.empty?
|
||||||
where("1=0")
|
where("1=0")
|
||||||
@ -111,7 +110,7 @@ class Principal < ActiveRecord::Base
|
|||||||
ids = projects.map(&:id)
|
ids = projects.map(&:id)
|
||||||
where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
|
where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
|
||||||
end
|
end
|
||||||
}
|
end)
|
||||||
scope :sorted, lambda { order(*Principal.fields_for_order_statement)}
|
scope :sorted, lambda { order(*Principal.fields_for_order_statement)}
|
||||||
|
|
||||||
# Principals that can be added as watchers
|
# Principals that can be added as watchers
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user