Patch #6864 ยป changeset-mail-notification.patch
| app/models/mailer.rb (working copy) | ||
|---|---|---|
| 271 | 271 | 
        render_multipart('test', body)
   | 
| 272 | 272 | 
    end  | 
| 273 | 273 | |
| 274 | 
    # Builds a tmail object used to email users belonging to the changeset's project.  | 
|
| 275 | 
    #  | 
|
| 276 | 
    # Example:  | 
|
| 277 | 
    # changeset(change) => tmail object  | 
|
| 278 | 
    # Mailer.deliver_changeset(change) => sends an email to the changeset's project recipients  | 
|
| 279 | 
    def changeset(change)  | 
|
| 280 | 
    redmine_headers 'Project' => change.project.identifier  | 
|
| 281 | 
    recipients change.recipients  | 
|
| 282 | 
        subject "[#{change.project.name}] #{change.title}"
   | 
|
| 283 | 
    body :change => change,  | 
|
| 284 | 
    :change_url => url_for(:controller => 'repositories', :action => 'revision', :id => change.repository.project, :rev => change.revision)  | 
|
| 285 | 
        render_multipart('changeset', body)
   | 
|
| 286 | 
    end  | 
|
| 287 | ||
| 274 | 288 | 
    # Overrides default deliver! method to prevent from sending an email  | 
| 275 | 289 | 
    # with no recipient, cc or bcc  | 
| 276 | 290 | 
    def deliver!(mail = @mail)  | 
| app/models/changeset.rb (working copy) | ||
|---|---|---|
| 152 | 152 | 
    to_utf8(str.to_s.strip)  | 
| 153 | 153 | 
    end  | 
| 154 | 154 | |
| 155 | 
    # needed by Mailer  | 
|
| 156 | 
    def visible?(user=nil)  | 
|
| 157 | 
    (user || User.current).allowed_to?(:view_changesets, self.project)  | 
|
| 158 | 
    end  | 
|
| 159 | ||
| 160 | 
    def title  | 
|
| 161 | 
        "#{l(:label_revision)} #{self.revision}" + (self.short_comments.blank? ? '' : (': ' + self.short_comments))
   | 
|
| 162 | 
    end  | 
|
| 163 | 
     | 
|
| 164 | 
    def datetime  | 
|
| 165 | 
    self[:committed_on]  | 
|
| 166 | 
    end  | 
|
| 167 | 
     | 
|
| 168 | 
    def path  | 
|
| 169 | 
    self[:from_path]  | 
|
| 170 | 
    end  | 
|
| 171 | 
     | 
|
| 172 | 
    def diff  | 
|
| 173 | 
    @path = self.path  | 
|
| 174 | 
    @rev = self[:from_revision]  | 
|
| 175 | 
    @rev_to = self.revision  | 
|
| 176 | 
    @diff = repository.diff(@path, @rev_to, @rev)  | 
|
| 177 | 
    if @diff  | 
|
| 178 | 
          return "#{@diff.join}"
   | 
|
| 179 | 
    end  | 
|
| 180 | 
     | 
|
| 181 | 
    end  | 
|
| 182 | 
     | 
|
| 183 | 
    def recipients  | 
|
| 184 | 
    notified = project.notified_users  | 
|
| 185 | 
    notified << author if author && author.active? && author.notify_about?(self)  | 
|
| 186 | 
    notified.uniq!  | 
|
| 187 | 
        notified.reject! {|user| !visible?(user)}
   | 
|
| 188 | 
    notified.collect(&:mail)  | 
|
| 189 | 
    end  | 
|
| 190 | ||
| 155 | 191 | 
    # Creates a new Change from it's common parameters  | 
| 156 | 192 | 
    def create_change(change)  | 
| 157 | 193 | 
    Change.create(:changeset => self,  | 
| ... | ... | |
| 159 | 195 | 
    :path => change[:path],  | 
| 160 | 196 | 
    :from_path => change[:from_path],  | 
| 161 | 197 | 
    :from_revision => change[:from_revision])  | 
| 198 | 
    Mailer.deliver_changeset(self)  | 
|
| 162 | 199 | 
    end  | 
| 163 | 200 | 
     | 
| 164 | 201 | 
    private  |