Project

General

Profile

Feature #8488 » private_issue_watchers_FIXED_2.1.diff

Abdul Halim Mat Ali, 2012-09-21 08:49

View differences:

app/models/issue.rb Fri Sep 21 11:21:53 2012 +0800 → app/models/issue.rb Fri Sep 21 11:27:37 2012 +0800
60 60
  validates_numericality_of :estimated_hours, :allow_nil => true
61 61
  validate :validate_issue, :validate_required_fields
62 62

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

  
67 66
  scope :open, lambda {|*args|
......
89 88
        nil
90 89
      when 'default'
91 90
        user_ids = [user.id] + user.groups.map(&:id)
92
        "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
91
        "(#{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(',')}))"
93 92
      when 'own'
94 93
        user_ids = [user.id] + user.groups.map(&:id)
95
        "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
94
        "(#{table_name}.author_id = #{user.id} OR #{Watcher.table_name}.user_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
96 95
      else
97 96
        '1=0'
98 97
      end
......
106 105
      when 'all'
107 106
        true
108 107
      when 'default'
109
        !self.is_private? || self.author == user || user.is_or_belongs_to?(assigned_to)
108
	!self.is_private? || self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
110 109
      when 'own'
111
        self.author == user || user.is_or_belongs_to?(assigned_to)
110
	self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
112 111
      else
113 112
        false
114 113
      end
115 114
    end
116 115
  end
117 116

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

  
125
  
118 126
  def initialize(attributes=nil, *args)
119 127
    super
120 128
    if new_record?
app/models/journal.rb Fri Sep 21 11:21:53 2012 +0800 → app/models/journal.rb Fri Sep 21 11:27:37 2012 +0800
38 38
                                                             " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
39 39

  
40 40
  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

  
(6-6/14)