<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/models/notification_keys.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -25,6 +25,6 @@ and remove the number it had in patch (to give a way for migration with the same
 
     delete from schema_migrations where version in ('995')
 
-This version is based on r1783 of http://redmine.rubyforge.org/svn/trunk.
+This version is based on r2282 of http://redmine.rubyforge.org/svn/trunk (so it's Redmine 0.8.1+).
 
 Contributed by Texuna Technologies.
\ No newline at end of file</diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -47,10 +47,20 @@ class AttachmentsController &lt; ApplicationController
     options.merge!(:type =&gt; @attachment.content_type) if @attachment.content_type
     send_file @attachment.diskfile, options
   end
-  
+
+  def to_notify?
+    notification_key = @attachment.container.notification_key if @attachment.container.respond_to?(:notification_key)
+    notification_key ||= NotificationKeys::FILE_ADDED
+    Setting.notified_events.include?(notification_key)
+  end
+
   def destroy
     # Make sure association callbacks are called
     @attachment.container.attachments.delete(@attachment)
+
+    if to_notify?
+      Mailer.deliver_attachments_removed([@attachment])
+    end
     redirect_to :back
   rescue ::ActionController::RedirectBackError
     redirect_to :controller =&gt; 'projects', :action =&gt; 'show', :id =&gt; @project</diff>
      <filename>app/controllers/attachments_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -193,7 +193,7 @@ class ProjectsController &lt; ApplicationController
     if request.post?
       container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
       attachments = attach_files(container, params[:attachments])
-      if !attachments.empty? &amp;&amp; Setting.notified_events.include?('file_added')
+      if !attachments.empty? &amp;&amp; Setting.notified_events.include?(NotificationKeys::FILE_ADDED)
         Mailer.deliver_attachments_added(attachments)
       end
       redirect_to :controller =&gt; 'projects', :action =&gt; 'list_files', :id =&gt; @project</diff>
      <filename>app/controllers/projects_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,7 @@ class SettingsController &lt; ApplicationController
   end
 
   def edit
-    @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted)
+    @notifiables = NotificationKeys::all
     if request.post? &amp;&amp; params[:settings] &amp;&amp; params[:settings].is_a?(Hash)
       settings = (params[:settings] || {}).dup.symbolize_keys
       settings.each do |name, value|</diff>
      <filename>app/controllers/settings_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -73,7 +73,7 @@ class WikiController &lt; ApplicationController
     else
       if !@page.new_record? &amp;&amp; @content.text == params[:content][:text]
         # don't save if text wasn't changed
-        redirect_to :action =&gt; 'index', :id =&gt; @project, :page =&gt; @page.title
+        redirect_to page_link
         return
       end
       #@content.text = params[:content][:text]
@@ -82,7 +82,7 @@ class WikiController &lt; ApplicationController
       @content.author = User.current
       # if page is new @page.save will also save content, but not if page isn't a new record
       if (@page.new_record? ? @page.save : @content.save)
-        redirect_to :action =&gt; 'index', :id =&gt; @project, :page =&gt; @page.title
+        redirect_to page_link
       end
     end
   rescue ActiveRecord::StaleObjectError
@@ -98,13 +98,13 @@ class WikiController &lt; ApplicationController
     @original_title = @page.pretty_title
     if request.post? &amp;&amp; @page.update_attributes(params[:wiki_page])
       flash[:notice] = l(:notice_successful_update)
-      redirect_to :action =&gt; 'index', :id =&gt; @project, :page =&gt; @page.title
+      redirect_to page_link
     end
   end
   
   def protect
     @page.update_attribute :protected, params[:protected]
-    redirect_to :action =&gt; 'index', :id =&gt; @project, :page =&gt; @page.title
+    redirect_to page_link
   end
 
   # show page history
@@ -177,12 +177,26 @@ class WikiController &lt; ApplicationController
 
   def add_attachment
     return render_403 unless editable?
-    attach_files(@page, params[:attachments])
+    attachments = attach_files(@page, params[:attachments])
+    if !attachments.empty? &amp;&amp;
+        Setting.notified_events.include?(NotificationKeys::WIKI_EDIT)
+      
+      Mailer.deliver_attachments_added(attachments)
+    end
     redirect_to :action =&gt; 'index', :page =&gt; @page.title
   end
 
+
+  def self.page_link(page)
+    {:action =&gt; 'index', :id =&gt; page.project, :page =&gt; page.title}
+  end
+
 private
-  
+
+  def page_link()
+    self.class.page_link(@page)
+  end
+
   def find_wiki
     @project = Project.find(params[:id])
     @wiki = @project.wiki</diff>
      <filename>app/controllers/wiki_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -34,4 +34,8 @@ class Document &lt; ActiveRecord::Base
       self.category ||= Enumeration.default('DCAT')
     end
   end
+
+  def notification_key
+    NotificationKeys::DOCUMENT_ADDED
+  end
 end</diff>
      <filename>app/models/document.rb</filename>
    </modified>
    <modified>
      <diff>@@ -75,26 +75,16 @@ class Mailer &lt; ActionMailer::Base
   end
 
   def attachments_added(attachments)
-    container = attachments.first.container
-    added_to = ''
-    added_to_url = ''
-    case container.class.name
-    when 'Project'
-      added_to_url = url_for(:controller =&gt; 'projects', :action =&gt; 'list_files', :id =&gt; container)
-      added_to = &quot;#{l(:label_project)}: #{container}&quot;
-    when 'Version'
-      added_to_url = url_for(:controller =&gt; 'projects', :action =&gt; 'list_files', :id =&gt; container.project_id)
-      added_to = &quot;#{l(:label_version)}: #{container.name}&quot;
-    when 'Document'
-      added_to_url = url_for(:controller =&gt; 'documents', :action =&gt; 'show', :id =&gt; container.id)
-      added_to = &quot;#{l(:label_document)}: #{container.title}&quot;
+    attachments_action(attachments) do |container|
+      subject &quot;[#{container.project.name}] #{l(:label_attachment_new)}&quot;
+    end
+  end
+
+  def attachments_removed(attachments)
+    attachments_action(attachments) do |container|
+      subject &quot;[%s] %s&quot; % [container.project.name, l(:label_attachment_deleted)]
+      self.template = :attachments_added
     end
-    redmine_headers 'Project' =&gt; container.project.identifier
-    recipients container.project.recipients
-    subject &quot;[#{container.project.name}] #{l(:label_attachment_new)}&quot;
-    body :attachments =&gt; attachments,
-         :added_to =&gt; added_to,
-         :added_to_url =&gt; added_to_url
   end
 
   def news_added(news)
@@ -286,6 +276,34 @@ class Mailer &lt; ActionMailer::Base
     @references_objects ||= []
     @references_objects &lt;&lt; object
   end
+
+  def attachments_action(attachments)
+    container = attachments.first.container
+    added_to = ''
+    added_to_url = ''
+    case container.class.name
+    when 'Project'
+      added_to_url = url_for(:controller =&gt; 'projects', :action =&gt; 'list_files', :id =&gt; container)
+      added_to = &quot;#{l(:label_project)}: #{container}&quot;
+    when 'Version'
+      added_to_url = url_for(:controller =&gt; 'projects', :action =&gt; 'list_files', :id =&gt; container.project_id)
+      added_to = &quot;#{l(:label_version)}: #{container.name}&quot;
+    when 'Document'
+      added_to_url = url_for(:controller =&gt; 'documents', :action =&gt; 'show', :id =&gt; container.id)
+      added_to = &quot;#{l(:label_document)}: #{container.title}&quot;
+    when 'WikiPage'
+      added_to = &quot;#{l(:label_wiki)}: #{container.title}&quot;
+      added_to_url = url_for({:controller =&gt; 'wiki'}.
+          merge(WikiController.page_link(container)))
+    end
+    redmine_headers 'Project' =&gt; container.project.identifier
+    recipients container.project.recipients
+    yield(container)
+    body :attachments =&gt; attachments,
+         :added_to =&gt; added_to,
+         :added_to_url =&gt; added_to_url
+  end
+
 end
 
 # Patch TMail so that message_id is not overwritten</diff>
      <filename>app/models/mailer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -126,6 +126,10 @@ class WikiPage &lt; ActiveRecord::Base
     self.parent = parent_page
   end
   
+  def notification_key
+    NotificationKeys::WIKI_EDIT
+  end
+
   protected
   
   def validate</diff>
      <filename>app/models/wiki_page.rb</filename>
    </modified>
    <modified>
      <diff>@@ -382,6 +382,7 @@ label_history: History
 label_attachment: File
 label_attachment_new: New file
 label_attachment_delete: Delete file
+label_attachment_deleted: File was deleted
 label_attachment_plural: Files
 label_file_added: File added
 label_report: Report</diff>
      <filename>lang/en.yml</filename>
    </modified>
    <modified>
      <diff>@@ -258,6 +258,7 @@ label_associated_revisions: &#1057;&#1074;&#1103;&#1079;&#1072;&#1085;&#1085;&#1099;&#1077; &#1088;&#1077;&#1076;&#1072;&#1082;&#1094;&#1080;&#1080;
 label_attachment: &#1060;&#1072;&#1081;&#1083;
 label_attachment_delete: &#1059;&#1076;&#1072;&#1083;&#1080;&#1090;&#1100; &#1092;&#1072;&#1081;&#1083;
 label_attachment_new: &#1053;&#1086;&#1074;&#1099;&#1081; &#1092;&#1072;&#1081;&#1083;
+label_attachment_deleted: &#1060;&#1072;&#1081;&#1083; &#1091;&#1076;&#1072;&#1083;&#1105;&#1085;
 label_attachment_plural: &#1060;&#1072;&#1081;&#1083;&#1099;
 label_attribute: &#1040;&#1090;&#1088;&#1080;&#1073;&#1091;&#1090;
 label_attribute_plural: &#1072;&#1090;&#1088;&#1080;&#1073;&#1091;&#1090;&#1099;</diff>
      <filename>lang/ru.yml</filename>
    </modified>
    <modified>
      <diff>@@ -168,15 +168,24 @@ class MailerTest &lt; Test::Unit::TestCase
       assert Mailer.deliver_document_added(document)
     end
   end
-  
-  def test_attachments_added
-    attachements = [ Attachment.find_by_container_type('Document') ]
+
+  def test_attachments_action(type, action)
+    attachments = [ Attachment.find_by_container_type(type) ]
+    assert !attachments.empty?
     GLoc.valid_languages.each do |lang|
       Setting.default_language = lang.to_s
-      assert Mailer.deliver_attachments_added(attachements)
+      assert Mailer.send(&quot;deliver_attachments_%s&quot; % action, attachments)
     end
   end
+
+  def test_attachments_added
+    test_attachments_action('Document', :added)
+  end
   
+  def test_attachments_removed
+    test_attachments_action('WikiPage', :removed)
+  end
+
   def test_news_added
     news = News.find(:first)
     GLoc.valid_languages.each do |lang|</diff>
      <filename>test/unit/mailer_test.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>lang/ru.yml.bak</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>10baff4fa02869b27daf599f0fc58e96a7f3d346</id>
    </parent>
  </parents>
  <author>
    <name>Artem Vasiliev</name>
    <email>artem.vasiliev@texunatech.com</email>
  </author>
  <url>http://github.com/artemv/redmine_tt/commit/d86251e4b7787281f81fa0479efe11f0c8270868</url>
  <id>d86251e4b7787281f81fa0479efe11f0c8270868</id>
  <committed-date>2009-01-20T09:55:32-08:00</committed-date>
  <authored-date>2009-01-20T09:55:32-08:00</authored-date>
  <message>Wiki email notification WIP:
done notification on attachments addition;
added notification on attachments removal for all containers (WikiPage, Project/Version, Document)</message>
  <tree>de808e06e1597982f4bbeb78644bd16dd935a854</tree>
  <committer>
    <name>Artem Vasiliev</name>
    <email>artem.vasiliev@texunatech.com</email>
  </committer>
</commit>
