Project

General

Profile

Feature #8488 » private_issue_watchers_3.1.x.diff

Hang Xie, 2015-11-19 06:58

View differences:

app/models/issue.rb
113 113
  # Returns a SQL conditions string used to find all issues visible by the specified user
114 114
  def self.visible_condition(user, options={})
115 115
    Project.allowed_to_condition(user, :view_issues, options) do |role, user|
116
      # Keep the code DRY
117
      if [ 'default', 'own' ].include?(role.issues_visibility)
118
        user_ids = [user.id] + user.groups.map(&:id).compact
119
        watched_issues = Issue.watched_by(user).map(&:id)
120
        watched_issues_clause = watched_issues.empty? ? "" : " OR #{table_name}.id IN (#{watched_issues.join(',')})"
121
      end
122

  
116 123
      if user.id && user.logged?
117 124
        case role.issues_visibility
118 125
        when 'all'
119 126
          nil
120 127
        when 'default'
121
          user_ids = [user.id] + user.groups.map(&:id).compact
122
          "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
128
         #user_ids = [user.id] + user.groups.map(&:id).compact
129
         #"(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
130
          "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) #{watched_issues_clause})"
123 131
        when 'own'
124
          user_ids = [user.id] + user.groups.map(&:id).compact
125
          "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
132
         #user_ids = [user.id] + user.groups.map(&:id).compact
133
         #"(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
134
          "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) #{watched_issues_clause})"	
126 135
        else
127 136
          '1=0'
128 137
        end
......
140 149
        when 'all'
141 150
          true
142 151
        when 'default'
143
          !self.is_private? || (self.author == user || user.is_or_belongs_to?(assigned_to))
152
         #!self.is_private? || (self.author == user || user.is_or_belongs_to?(assigned_to))
153
          !self.is_private? || (self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to))
144 154
        when 'own'
145
          self.author == user || user.is_or_belongs_to?(assigned_to)
155
         #self.author == user || user.is_or_belongs_to?(assigned_to)
156
          !self.is_private? || (self.author == user || self.watched_by?(user) || user.is_or_belongs_to?(assigned_to))
146 157
        else
147 158
          false
148 159
        end
......
152 163
    end
153 164
  end
154 165

  
166
  # Override the acts_as_watchble default to allow any user with view issues
167
  # rights to watch/see this issue.
168
  def addable_watcher_users
169
    users = self.project.users.sort - self.watcher_users
170
    users.reject! {|user| !user.allowed_to?(:view_issues, self.project)}
171
    users
172
  end
173

  
155 174
  # Returns true if user or current user is allowed to edit or add a note to the issue
156 175
  def editable?(user=User.current)
157 176
    attributes_editable?(user) || user.allowed_to?(:add_issue_notes, project)
(14-14/14)