validates_length_of :name, :maximum => 30
validates_length_of :description, :maximum => 255
- named_scope :visible, lambda {|*args| { :include => :project,
+ scope :visible, lambda {|*args| { :include => :project,
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
safe_attributes 'name', 'description', 'move_to'
validates_uniqueness_of :revision, :scope => :repository_id
validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
- named_scope :visible, lambda {|*args| { :include => {:repository => :project},
+ scope :visible,
+ lambda {|*args| { :include => {:repository => :project},
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args) } }
after_create :scan_for_issues
validates_presence_of :project, :title, :category
validates_length_of :title, :maximum => 60
- named_scope :visible, lambda {|*args| { :include => :project,
+ scope :visible, lambda {|*args| { :include => :project,
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_documents, *args) } }
safe_attributes 'category_id', 'title', 'description'
validates_uniqueness_of :name, :scope => [:type, :project_id]
validates_length_of :name, :maximum => 30
- named_scope :shared, :conditions => { :project_id => nil }
- named_scope :active, :conditions => { :active => true }
- named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+ scope :shared, :conditions => { :project_id => nil }
+ scope :active, :conditions => { :active => true }
+ scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
def self.default
# Creates a fake default scope so Enumeration.default will check
validates_numericality_of :estimated_hours, :allow_nil => true
validate :validate_issue
- named_scope :visible, lambda {|*args| { :include => :project,
- :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
+ scope :visible,
+ lambda {|*args| { :include => :project,
+ :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
- named_scope :open, lambda {|*args|
+ scope :open, lambda {|*args|
is_closed = args.size > 0 ? !args.first : false
{:conditions => ["#{IssueStatus.table_name}.is_closed = ?", is_closed], :include => :status}
}
- named_scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC"
- named_scope :with_limit, lambda { |limit| { :limit => limit} }
- named_scope :on_active_project, :include => [:status, :project, :tracker],
- :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
+ scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC"
+ scope :with_limit, lambda { |limit| { :limit => limit} }
+ scope :on_active_project, :include => [:status, :project, :tracker],
+ :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
before_create :default_assign
before_save :close_duplicates, :update_done_ratio_from_issue_status
safe_attributes 'name', 'assigned_to_id'
- named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+ scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
alias :destroy_without_reassign :destroy
validates_length_of :name, :maximum => 30
validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true
- named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+ scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
def update_default
IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default?
:conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
- named_scope :visible, lambda {|*args| {
+ scope :visible, lambda {|*args| {
:include => {:issue => :project},
:conditions => Issue.visible_condition(args.shift || User.current, *args)
}}
after_update :update_messages_board
after_destroy :reset_board_counters
- named_scope :visible, lambda {|*args| { :include => {:board => :project},
+ scope :visible, lambda {|*args| { :include => {:board => :project},
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
safe_attributes 'subject', 'content'
after_create :add_author_as_watcher
- named_scope :visible, lambda {|*args| {
+ scope :visible, lambda {|*args| {
:include => :project,
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_news, *args)
}}
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
# Groups and active users
- named_scope :active, :conditions => "#{Principal.table_name}.status = 1"
+ scope :active, :conditions => "#{Principal.table_name}.status = 1"
- named_scope :like, lambda {|q|
+ scope :like, lambda {|q|
if q.blank?
{}
else
}
# Principals that are members of a collection of projects
- named_scope :member_of, lambda {|projects|
+ scope :member_of, lambda {|projects|
projects = [projects] unless projects.is_a?(Array)
if projects.empty?
{:conditions => "1=0"}
end
}
# Principals that are not members of projects
- named_scope :not_member_of, lambda {|projects|
+ scope :not_member_of, lambda {|projects|
projects = [projects] unless projects.is_a?(Array)
if projects.empty?
{:conditions => "1=0"}
before_destroy :delete_all_members
- named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
- named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
- named_scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
- named_scope :all_public, { :conditions => { :is_public => true } }
- named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
- named_scope :allowed_to, lambda {|*args|
+ scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
+ scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
+ scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
+ scope :all_public, { :conditions => { :is_public => true } }
+ scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
+ scope :allowed_to, lambda {|*args|
user = User.current
permission = nil
if args.first.is_a?(Symbol)
end
{ :conditions => Project.allowed_to_condition(user, permission, *args) }
}
- named_scope :like, lambda {|arg|
+ scope :like, lambda {|arg|
if arg.blank?
{}
else
]
cattr_reader :available_columns
- named_scope :visible, lambda {|*args|
+ scope :visible, lambda {|*args|
user = args.shift || User.current
base = Project.allowed_to_condition(user, :view_issues, *args)
user_id = user.logged? ? user.id : 0
['own', :label_issues_visibility_own]
]
- named_scope :sorted, {:order => 'builtin, position'}
- named_scope :givable, { :conditions => "builtin = 0", :order => 'position' }
- named_scope :builtin, lambda { |*args|
+ scope :sorted, {:order => 'builtin, position'}
+ scope :givable, { :conditions => "builtin = 0", :order => 'position' }
+ scope :builtin, lambda { |*args|
compare = 'not' if args.first == true
{ :conditions => "#{compare} builtin = 0" }
}
before_validation :set_project_if_nil
validate :validate_time_entry
- named_scope :visible, lambda {|*args| {
+ scope :visible, lambda {|*args| {
:include => :project,
:conditions => Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args)
}}
- named_scope :on_issue, lambda {|issue| {
+ scope :on_issue, lambda {|issue| {
:include => :issue,
:conditions => "#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}"
}}
- named_scope :on_project, lambda {|project, include_subprojects| {
+ scope :on_project, lambda {|project, include_subprojects| {
:include => :project,
:conditions => project.project_condition(include_subprojects)
}}
- named_scope :spent_between, lambda {|from, to|
+ scope :spent_between, lambda {|from, to|
if from && to
{:conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]}
elsif from
validates_uniqueness_of :name
validates_length_of :name, :maximum => 30
- named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+ scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
def to_s; name end
belongs_to :auth_source
# Active non-anonymous users scope
- named_scope :active, :conditions => "#{User.table_name}.status = #{STATUS_ACTIVE}"
- named_scope :logged, :conditions => "#{User.table_name}.status <> #{STATUS_ANONYMOUS}"
- named_scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
+ scope :active, :conditions => "#{User.table_name}.status = #{STATUS_ACTIVE}"
+ scope :logged, :conditions => "#{User.table_name}.status <> #{STATUS_ANONYMOUS}"
+ scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
acts_as_customizable
before_save :update_hashed_password
before_destroy :remove_references_before_destroy
- named_scope :in_group, lambda {|group|
+ scope :in_group, lambda {|group|
group_id = group.is_a?(Group) ? group.id : group.to_i
{ :conditions => ["#{User.table_name}.id IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] }
}
- named_scope :not_in_group, lambda {|group|
+ scope :not_in_group, lambda {|group|
group_id = group.is_a?(Group) ? group.id : group.to_i
{ :conditions => ["#{User.table_name}.id NOT IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id] }
}
validates_inclusion_of :status, :in => VERSION_STATUSES
validates_inclusion_of :sharing, :in => VERSION_SHARINGS
- named_scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
- named_scope :open, :conditions => {:status => 'open'}
- named_scope :visible, lambda {|*args| { :include => :project,
+ scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}}
+ scope :open, :conditions => {:status => 'open'}
+ scope :visible, lambda {|*args| { :include => :project,
:conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
safe_attributes 'name',
before_save :handle_redirects
# eager load information about last updates, without loading text
- named_scope :with_updated_on, {
+ scope :with_updated_on, {
:select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
:joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
}