private_issue_watchers_2.2.diff

Justin Hahn, 2013-02-28 20:11

Download (2.91 KB)

View differences:

app/models/issue.rb
71 71
  validate :validate_issue, :validate_required_fields
72 72

  
73 73
  scope :visible,
74
        lambda {|*args| { :include => :project,
74
        lambda {|*args| { :include => [:project, :watchers],
75 75
                          :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
76 76

  
77 77
  scope :open, lambda {|*args|
......
100 100
          nil
101 101
        when 'default'
102 102
          user_ids = [user.id] + user.groups.map(&:id)
103
          "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
103
          "(#{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(',')}))"
104 104
        when 'own'
105 105
          user_ids = [user.id] + user.groups.map(&:id)
106
          "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
106
          "(#{table_name}.author_id = #{user.id} OR #{Watcher.table_name}.user_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
107 107
        else
108 108
          '1=0'
109 109
        end
......
121 121
        when 'all'
122 122
          true
123 123
        when 'default'
124
          !self.is_private? || (self.author == user || user.is_or_belongs_to?(assigned_to))
124
          !self.is_private? || self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
125 125
        when 'own'
126
          self.author == user || user.is_or_belongs_to?(assigned_to)
126
          self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
127 127
        else
128 128
          false
129 129
        end
......
133 133
    end
134 134
  end
135 135

  
136
  # Override the acts_as_watchble default to allow any user with view issues
137
  # rights to watch/see this issue.
138
  def addable_watcher_users
139
    users = self.project.users.sort - self.watcher_users
140
    users.reject! {|user| !user.allowed_to?(:view_issues, self.project)}
141
    users
142
  end
143

  
136 144
  def initialize(attributes=nil, *args)
137 145
    super
138 146
    if new_record?
app/models/journal.rb
42 42
  scope :visible, lambda {|*args|
43 43
    user = args.shift || User.current
44 44

  
45
    includes(:issue => :project).
45
    includes(:issue => [:project, :watchers]).
46 46
      where(Issue.visible_condition(user, *args)).
47 47
      where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
48 48
  }