@@ -28,7 +28,7 class Board < ActiveRecord::Base | |||
|
28 | 28 | validates_length_of :name, :maximum => 30 |
|
29 | 29 | validates_length_of :description, :maximum => 255 |
|
30 | 30 | |
|
31 |
|
|
|
31 | scope :visible, lambda {|*args| { :include => :project, | |
|
32 | 32 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } } |
|
33 | 33 | |
|
34 | 34 | safe_attributes 'name', 'description', 'move_to' |
@@ -49,7 +49,8 class Changeset < ActiveRecord::Base | |||
|
49 | 49 | validates_uniqueness_of :revision, :scope => :repository_id |
|
50 | 50 | validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true |
|
51 | 51 | |
|
52 | named_scope :visible, lambda {|*args| { :include => {:repository => :project}, | |
|
52 | scope :visible, | |
|
53 | lambda {|*args| { :include => {:repository => :project}, | |
|
53 | 54 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args) } } |
|
54 | 55 | |
|
55 | 56 | after_create :scan_for_issues |
@@ -30,7 +30,7 class Document < ActiveRecord::Base | |||
|
30 | 30 | validates_presence_of :project, :title, :category |
|
31 | 31 | validates_length_of :title, :maximum => 60 |
|
32 | 32 | |
|
33 |
|
|
|
33 | scope :visible, lambda {|*args| { :include => :project, | |
|
34 | 34 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_documents, *args) } } |
|
35 | 35 | |
|
36 | 36 | safe_attributes 'category_id', 'title', 'description' |
@@ -35,9 +35,9 class Enumeration < ActiveRecord::Base | |||
|
35 | 35 | validates_uniqueness_of :name, :scope => [:type, :project_id] |
|
36 | 36 | validates_length_of :name, :maximum => 30 |
|
37 | 37 | |
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
38 | scope :shared, :conditions => { :project_id => nil } | |
|
39 | scope :active, :conditions => { :active => true } | |
|
40 | scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} | |
|
41 | 41 | |
|
42 | 42 | def self.default |
|
43 | 43 | # Creates a fake default scope so Enumeration.default will check |
@@ -60,17 +60,18 class Issue < ActiveRecord::Base | |||
|
60 | 60 | validates_numericality_of :estimated_hours, :allow_nil => true |
|
61 | 61 | validate :validate_issue |
|
62 | 62 | |
|
63 | named_scope :visible, lambda {|*args| { :include => :project, | |
|
63 | scope :visible, | |
|
64 | lambda {|*args| { :include => :project, | |
|
64 | 65 |
|
|
65 | 66 | |
|
66 |
|
|
|
67 | scope :open, lambda {|*args| | |
|
67 | 68 | is_closed = args.size > 0 ? !args.first : false |
|
68 | 69 | {:conditions => ["#{IssueStatus.table_name}.is_closed = ?", is_closed], :include => :status} |
|
69 | 70 | } |
|
70 | 71 | |
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
72 | scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC" | |
|
73 | scope :with_limit, lambda { |limit| { :limit => limit} } | |
|
74 | scope :on_active_project, :include => [:status, :project, :tracker], | |
|
74 | 75 |
|
|
75 | 76 | |
|
76 | 77 | before_create :default_assign |
@@ -27,7 +27,7 class IssueCategory < ActiveRecord::Base | |||
|
27 | 27 | |
|
28 | 28 | safe_attributes 'name', 'assigned_to_id' |
|
29 | 29 | |
|
30 |
|
|
|
30 | scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} | |
|
31 | 31 | |
|
32 | 32 | alias :destroy_without_reassign :destroy |
|
33 | 33 |
@@ -28,7 +28,7 class IssueStatus < ActiveRecord::Base | |||
|
28 | 28 | validates_length_of :name, :maximum => 30 |
|
29 | 29 | validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true |
|
30 | 30 | |
|
31 |
|
|
|
31 | scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} | |
|
32 | 32 | |
|
33 | 33 | def update_default |
|
34 | 34 | IssueStatus.update_all("is_default=#{connection.quoted_false}", ['id <> ?', id]) if self.is_default? |
@@ -37,7 +37,7 class Journal < ActiveRecord::Base | |||
|
37 | 37 | :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + |
|
38 | 38 | " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} |
|
39 | 39 | |
|
40 |
|
|
|
40 | scope :visible, lambda {|*args| { | |
|
41 | 41 | :include => {:issue => :project}, |
|
42 | 42 | :conditions => Issue.visible_condition(args.shift || User.current, *args) |
|
43 | 43 | }} |
@@ -45,7 +45,7 class Message < ActiveRecord::Base | |||
|
45 | 45 | after_update :update_messages_board |
|
46 | 46 | after_destroy :reset_board_counters |
|
47 | 47 | |
|
48 |
|
|
|
48 | scope :visible, lambda {|*args| { :include => {:board => :project}, | |
|
49 | 49 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } } |
|
50 | 50 | |
|
51 | 51 | safe_attributes 'subject', 'content' |
@@ -34,7 +34,7 class News < ActiveRecord::Base | |||
|
34 | 34 | |
|
35 | 35 | after_create :add_author_as_watcher |
|
36 | 36 | |
|
37 |
|
|
|
37 | scope :visible, lambda {|*args| { | |
|
38 | 38 | :include => :project, |
|
39 | 39 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_news, *args) |
|
40 | 40 | }} |
@@ -24,9 +24,9 class Principal < ActiveRecord::Base | |||
|
24 | 24 | has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify |
|
25 | 25 | |
|
26 | 26 | # Groups and active users |
|
27 |
|
|
|
27 | scope :active, :conditions => "#{Principal.table_name}.status = 1" | |
|
28 | 28 | |
|
29 |
|
|
|
29 | scope :like, lambda {|q| | |
|
30 | 30 | if q.blank? |
|
31 | 31 | {} |
|
32 | 32 | else |
@@ -44,7 +44,7 class Principal < ActiveRecord::Base | |||
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | # Principals that are members of a collection of projects |
|
47 |
|
|
|
47 | scope :member_of, lambda {|projects| | |
|
48 | 48 | projects = [projects] unless projects.is_a?(Array) |
|
49 | 49 | if projects.empty? |
|
50 | 50 | {:conditions => "1=0"} |
@@ -54,7 +54,7 class Principal < ActiveRecord::Base | |||
|
54 | 54 | end |
|
55 | 55 | } |
|
56 | 56 | # Principals that are not members of projects |
|
57 |
|
|
|
57 | scope :not_member_of, lambda {|projects| | |
|
58 | 58 | projects = [projects] unless projects.is_a?(Array) |
|
59 | 59 | if projects.empty? |
|
60 | 60 | {:conditions => "1=0"} |
@@ -82,12 +82,12 class Project < ActiveRecord::Base | |||
|
82 | 82 | |
|
83 | 83 | before_destroy :delete_all_members |
|
84 | 84 | |
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
85 | 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] } } | |
|
86 | scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"} | |
|
87 | scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} } | |
|
88 | scope :all_public, { :conditions => { :is_public => true } } | |
|
89 | scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }} | |
|
90 | scope :allowed_to, lambda {|*args| | |
|
91 | 91 | user = User.current |
|
92 | 92 | permission = nil |
|
93 | 93 | if args.first.is_a?(Symbol) |
@@ -98,7 +98,7 class Project < ActiveRecord::Base | |||
|
98 | 98 | end |
|
99 | 99 | { :conditions => Project.allowed_to_condition(user, permission, *args) } |
|
100 | 100 | } |
|
101 |
|
|
|
101 | scope :like, lambda {|arg| | |
|
102 | 102 | if arg.blank? |
|
103 | 103 | {} |
|
104 | 104 | else |
@@ -153,7 +153,7 class Query < ActiveRecord::Base | |||
|
153 | 153 | ] |
|
154 | 154 | cattr_reader :available_columns |
|
155 | 155 | |
|
156 |
|
|
|
156 | scope :visible, lambda {|*args| | |
|
157 | 157 | user = args.shift || User.current |
|
158 | 158 | base = Project.allowed_to_condition(user, :view_issues, *args) |
|
159 | 159 | user_id = user.logged? ? user.id : 0 |
@@ -26,9 +26,9 class Role < ActiveRecord::Base | |||
|
26 | 26 | ['own', :label_issues_visibility_own] |
|
27 | 27 | ] |
|
28 | 28 | |
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
29 | scope :sorted, {:order => 'builtin, position'} | |
|
30 | scope :givable, { :conditions => "builtin = 0", :order => 'position' } | |
|
31 | scope :builtin, lambda { |*args| | |
|
32 | 32 | compare = 'not' if args.first == true |
|
33 | 33 | { :conditions => "#{compare} builtin = 0" } |
|
34 | 34 | } |
@@ -42,19 +42,19 class TimeEntry < ActiveRecord::Base | |||
|
42 | 42 | before_validation :set_project_if_nil |
|
43 | 43 | validate :validate_time_entry |
|
44 | 44 | |
|
45 |
|
|
|
45 | scope :visible, lambda {|*args| { | |
|
46 | 46 | :include => :project, |
|
47 | 47 | :conditions => Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args) |
|
48 | 48 | }} |
|
49 |
|
|
|
49 | scope :on_issue, lambda {|issue| { | |
|
50 | 50 | :include => :issue, |
|
51 | 51 | :conditions => "#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}" |
|
52 | 52 | }} |
|
53 |
|
|
|
53 | scope :on_project, lambda {|project, include_subprojects| { | |
|
54 | 54 | :include => :project, |
|
55 | 55 | :conditions => project.project_condition(include_subprojects) |
|
56 | 56 | }} |
|
57 |
|
|
|
57 | scope :spent_between, lambda {|from, to| | |
|
58 | 58 | if from && to |
|
59 | 59 | {:conditions => ["#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to]} |
|
60 | 60 | elsif from |
@@ -32,7 +32,7 class Tracker < ActiveRecord::Base | |||
|
32 | 32 | validates_uniqueness_of :name |
|
33 | 33 | validates_length_of :name, :maximum => 30 |
|
34 | 34 | |
|
35 |
|
|
|
35 | scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} | |
|
36 | 36 | |
|
37 | 37 | def to_s; name end |
|
38 | 38 |
@@ -53,9 +53,9 class User < Principal | |||
|
53 | 53 | belongs_to :auth_source |
|
54 | 54 | |
|
55 | 55 | # Active non-anonymous users scope |
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
56 | scope :active, :conditions => "#{User.table_name}.status = #{STATUS_ACTIVE}" | |
|
57 | scope :logged, :conditions => "#{User.table_name}.status <> #{STATUS_ANONYMOUS}" | |
|
58 | scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} } | |
|
59 | 59 | |
|
60 | 60 | acts_as_customizable |
|
61 | 61 | |
@@ -84,11 +84,11 class User < Principal | |||
|
84 | 84 | before_save :update_hashed_password |
|
85 | 85 | before_destroy :remove_references_before_destroy |
|
86 | 86 | |
|
87 |
|
|
|
87 | scope :in_group, lambda {|group| | |
|
88 | 88 | group_id = group.is_a?(Group) ? group.id : group.to_i |
|
89 | 89 | { :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] } |
|
90 | 90 | } |
|
91 |
|
|
|
91 | scope :not_in_group, lambda {|group| | |
|
92 | 92 | group_id = group.is_a?(Group) ? group.id : group.to_i |
|
93 | 93 | { :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] } |
|
94 | 94 | } |
@@ -34,9 +34,9 class Version < ActiveRecord::Base | |||
|
34 | 34 | validates_inclusion_of :status, :in => VERSION_STATUSES |
|
35 | 35 | validates_inclusion_of :sharing, :in => VERSION_SHARINGS |
|
36 | 36 | |
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
37 | scope :named, lambda {|arg| { :conditions => ["LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip]}} | |
|
38 | scope :open, :conditions => {:status => 'open'} | |
|
39 | scope :visible, lambda {|*args| { :include => :project, | |
|
40 | 40 | :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } } |
|
41 | 41 | |
|
42 | 42 | safe_attributes 'name', |
@@ -49,7 +49,7 class WikiPage < ActiveRecord::Base | |||
|
49 | 49 | before_save :handle_redirects |
|
50 | 50 | |
|
51 | 51 | # eager load information about last updates, without loading text |
|
52 |
|
|
|
52 | scope :with_updated_on, { | |
|
53 | 53 | :select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on", |
|
54 | 54 | :joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id" |
|
55 | 55 | } |
General Comments 0
You need to be logged in to leave comments.
Login now