Project

General

Profile

Feature #8488 » private_issue_watchers_FIXED.diff

Justin Hahn, 2011-07-28 17:48

View differences:

app/models/issue.rb
59 59
  validates_inclusion_of :done_ratio, :in => 0..100
60 60
  validates_numericality_of :estimated_hours, :allow_nil => true
61 61

  
62
  named_scope :visible, lambda {|*args| { :include => :project,
62
  named_scope :visible, lambda {|*args| { :include => [:project, :watchers],
63 63
                                          :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
64 64

  
65 65
  named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
......
93 93
      when 'all'
94 94
        nil
95 95
      when 'default'
96
        "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id = #{user.id})"
96
        "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id = #{user.id} OR  #{Watcher.table_name}.user_id = #{user.id})"
97 97
      when 'own'
98
        "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id = #{user.id})"
98
        "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id = #{user.id} OR #{Watcher.table_name}.user_id = #{user.id})"
99 99
      else
100 100
        '1=0'
101 101
      end
......
109 109
      when 'all'
110 110
        true
111 111
      when 'default'
112
        !self.is_private? || self.author == user || self.assigned_to == user
112
        !self.is_private? || self.author == user || self.assigned_to == user || self.watched_by?(user)
113 113
      when 'own'
114
        self.author == user || self.assigned_to == user
114
        self.author == user || self.assigned_to == user || self.watched_by?(user)
115 115
      else
116 116
        false
117 117
      end
118 118
    end
119 119
  end
120 120

  
121
  # Override the acts_as_watchble default to allow any user with view issues
122
  # rights to watch/see this issue.
123
  def addable_watcher_users
124
    users = self.project.users.sort - self.watcher_users
125
    users.reject! {|user| !user.allowed_to?(:view_issues, self.project)}
126
    users
127
  end
128

  
121 129
  def after_initialize
122 130
    if new_record?
123 131
      # set default values for new records only
app/models/journal.rb
38 38
                                                             " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
39 39
  
40 40
  named_scope :visible, lambda {|*args| {
41
    :include => {:issue => :project},
41
    :include => {:issue => [:project, :watchers]},
42 42
    :conditions => Issue.visible_condition(args.shift || User.current, *args)
43 43
  }}
44 44
  
(2-2/14)