Project

General

Profile

Feature #8488 » private_issue_watchers_2.2_FIXED_2.diff

Stanislav Židek, 2013-03-06 09:50

View differences:

app/models/issue.rb
72 72

  
73 73
  scope :visible,
74 74
        lambda {|*args| { :include => :project,
75
                          :joins => %Q{LEFT OUTER JOIN `#{Watcher.table_name}` ON `#{Watcher.table_name}`.`watchable_id` = `#{table_name}`.`id` AND `#{Watcher.table_name}`.`watchable_type` = 'Issue'},
75 76
                          :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
76 77

  
77 78
  scope :open, lambda {|*args|
......
100 101
          nil
101 102
        when 'default'
102 103
          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(',')}))"
104
          "(#{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 105
        when 'own'
105 106
          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(',')}))"
107
          "(#{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 108
        else
108 109
          '1=0'
109 110
        end
......
121 122
        when 'all'
122 123
          true
123 124
        when 'default'
124
          !self.is_private? || (self.author == user || user.is_or_belongs_to?(assigned_to))
125
          !self.is_private? || self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
125 126
        when 'own'
126
          self.author == user || user.is_or_belongs_to?(assigned_to)
127
          self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
127 128
        else
128 129
          false
129 130
        end
......
133 134
    end
134 135
  end
135 136

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

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

  
45 45
    includes(:issue => :project).
46
      joins(%Q{LEFT OUTER JOIN `#{Watcher.table_name}` ON `#{Watcher.table_name}`.`watchable_id` = `#{Issue.table_name}`.`id` AND `#{Watcher.table_name}`.`watchable_type` = 'Issue'}).
46 47
      where(Issue.visible_condition(user, *args)).
47 48
      where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
48 49
  }
(9-9/14)