Project

General

Profile

Feature #8488 » private_issue_watchers_FIXED_1.4.diff

Daniele Palumbo, 2012-06-13 16:50

View differences:

app/models/issue.rb 2012-06-13 16:30:11.000000000 +0200
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, lambda {|*args|
......
87 87
        nil
88 88
      when 'default'
89 89
        user_ids = [user.id] + user.groups.map(&:id)
90
        "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
90
        "(#{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(',')}))"
91 91
      when 'own'
92 92
        user_ids = [user.id] + user.groups.map(&:id)
93
        "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
93
        "(#{table_name}.author_id = #{user.id} OR #{Watcher.table_name}.user_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
94 94
      else
95 95
        '1=0'
96 96
      end
......
104 104
      when 'all'
105 105
        true
106 106
      when 'default'
107
        !self.is_private? || self.author == user || user.is_or_belongs_to?(assigned_to)
107
	!self.is_private? || self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
108 108
      when 'own'
109
        self.author == user || user.is_or_belongs_to?(assigned_to)
109
	self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to)
110 110
      else
111 111
        false
112 112
      end
113 113
    end
114 114
  end
115 115

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

  
116 124
  def initialize(attributes=nil, *args)
117 125
    super
118 126
    if new_record?
119
-- app/models/journal.rb.orig	2012-06-13 16:27:58.000000000 +0200
127
++ app/models/journal.rb	2012-06-13 16:28:14.000000000 +0200
......
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

  
(4-4/14)