Project

General

Profile

RE: Contacts plugin ยป mailer_patch.rb

Kirill Bezrukov (RedmineUP), 2011-09-27 19:25

 
1
require 'dispatcher'   
2

    
3
module RedmineContacts
4
  module Patches    
5

    
6
    module MailerPatch
7
      module ClassMethods
8
      end
9

    
10
      module InstanceMethods
11
        def note_added(note, parent) 
12
          redmine_headers 'X-Project' => note.source.project.identifier, 
13
          'X-Notable-Id' => note.source.id,
14
          'X-Note-Id' => note.id
15
          message_id note
16
          if parent
17
            recipients (note.source.watcher_recipients + parent.watcher_recipients).uniq
18
          else
19
            recipients note.source.watcher_recipients
20
          end
21

    
22
          subject "[#{note.source.project.name}] - #{parent.name + ' - ' if parent}#{l(:label_note_for)} #{note.source.name}"  
23

    
24
          body :note => note,   
25
          :note_url => url_for(:controller => 'notes', :action => 'show', :note_id => note.id)
26
          render_multipart('note_added', body)
27
        end
28

    
29
        def issue_connected(issue, contact)
30
          redmine_headers 'X-Project' => contact.project.identifier, 
31
          'X-Issue-Id' => issue.id,
32
          'X-Contact-Id' => contact.id
33
          message_id contact
34
          recipients contact.watcher_recipients 
35
          subject "[#{contact.projects.first.name}] - #{l(:label_issue_for)} #{contact.name}"  
36

    
37
          body :contact => contact,
38
          :issue => issue,
39
          :contact_url => url_for(:controller => contact.class.name.pluralize.downcase, :action => 'show', :project_id => contact.project, :id => contact.id),
40
          :issue_url => url_for(:controller => "issues", :action => "show", :id => issue)
41
          render_multipart('issue_connected', body)
42
        end
43

    
44
      end  
45
        
46
      def self.included(receiver)
47
        receiver.extend         ClassMethods
48
        receiver.send :include, InstanceMethods
49
        receiver.class_eval do 
50
          unloadable   
51
          self.instance_variable_get("@inheritable_attributes")[:view_paths] << RAILS_ROOT + "/vendor/plugins/redmine_contacts/app/views"
52
        end  
53
      end
54
      
55
    end
56

    
57
  end
58
end
59

    
60
Dispatcher.to_prepare do  
61

    
62
  unless Mailer.included_modules.include?(RedmineContacts::Patches::MailerPatch)
63
    Mailer.send(:include, RedmineContacts::Patches::MailerPatch)
64
  end   
65

    
66
end
67

    
    (1-1/1)