private_issue_watchers_FIXED_1.3.diff

patch ported to branch 1.3-stable - Bruno Medeiros, 2011-12-09 14:10

Download (2.94 KB)

View differences:

app/models/issue.rb (working copy)
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
  named_scope :visible, lambda {|*args| { :include => [:project, :watchers],
64 64
                                          :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
65 65

  
66 66
  named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
......
95 95
        nil
96 96
      when 'default'
97 97
        user_ids = [user.id] + user.groups.map(&:id)
98
        "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
98
        "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{Watcher.table_name}.user_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
99 99
      when 'own'
100 100
        user_ids = [user.id] + user.groups.map(&:id)
101
        "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
101
        "(#{table_name}.author_id = #{user.id} OR #{Watcher.table_name}.user_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
102 102
      else
103 103
        '1=0'
104 104
      end
......
112 112
      when 'all'
113 113
        true
114 114
      when 'default'
115
        !self.is_private? || self.author == user || user.is_or_belongs_to?(assigned_to)
115
        !self.is_private? || self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
116 116
      when 'own'
117
        self.author == user || user.is_or_belongs_to?(assigned_to)
117
        self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
118 118
      else
119 119
        false
120 120
      end
121 121
    end
122 122
  end
123 123

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

  
124 132
  def after_initialize
125 133
    if new_record?
126 134
      # set default values for new records only
app/models/journal.rb (working copy)
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