]> source.dussan.org Git - redmine.git/commitdiff
mail notifications added when:
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 27 Jan 2007 15:01:19 +0000 (15:01 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 27 Jan 2007 15:01:19 +0000 (15:01 +0000)
* a document is added
* a file is added to the project
* an attachment is added to an issue or a document

git-svn-id: http://redmine.rubyforge.org/svn/trunk@196 e93f8b46-1217-0410-a6f0-8f06a7374b81

13 files changed:
app/controllers/documents_controller.rb
app/controllers/issues_controller.rb
app/controllers/projects_controller.rb
app/models/mailer.rb
app/views/mailer/attachments_add_de.rhtml [new file with mode: 0644]
app/views/mailer/attachments_add_en.rhtml [new file with mode: 0644]
app/views/mailer/attachments_add_es.rhtml [new file with mode: 0644]
app/views/mailer/attachments_add_fr.rhtml [new file with mode: 0644]
app/views/mailer/document_add_de.rhtml [new file with mode: 0644]
app/views/mailer/document_add_en.rhtml [new file with mode: 0644]
app/views/mailer/document_add_es.rhtml [new file with mode: 0644]
app/views/mailer/document_add_fr.rhtml [new file with mode: 0644]
db/migrate/018_set_doc_and_files_notifications.rb [new file with mode: 0644]

index 5ff3583d9cdd31a5ca569e86bb6756136a057896..fe0f2d3485ebe3633c5f7381357fe97866574714 100644 (file)
@@ -1,5 +1,5 @@
 # redMine - project management software\r
-# Copyright (C) 2006  Jean-Philippe Lang\r
+# Copyright (C) 2006-2007  Jean-Philippe Lang\r
 #\r
 # This program is free software; you can redistribute it and/or\r
 # modify it under the terms of the GNU General Public License\r
@@ -46,9 +46,13 @@ class DocumentsController < ApplicationController
   \r
   def add_attachment\r
     # Save the attachments\r
-    params[:attachments].each { |a|\r
-      Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0\r
+    @attachments = []\r
+    params[:attachments].each { |file|\r
+      next unless file.size > 0\r
+      a = Attachment.create(:container => @document, :file => file, :author => logged_in_user)\r
+      @attachments << a unless a.new_record?\r
     } if params[:attachments] and params[:attachments].is_a? Array\r
+    Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?\r
     redirect_to :action => 'show', :id => @document\r
   end\r
   \r
index d37333e37233dbfe55643886645d173ab25d6deb..6ac8bc79b412d5e3a9c40c9dc03cd08ae054273d 100644 (file)
@@ -1,5 +1,5 @@
 # redMine - project management software\r
-# Copyright (C) 2006  Jean-Philippe Lang\r
+# Copyright (C) 2006-2007  Jean-Philippe Lang\r
 #\r
 # This program is free software; you can redistribute it and/or\r
 # modify it under the terms of the GNU General Public License\r
@@ -115,10 +115,13 @@ class IssuesController < ApplicationController
 \r
   def add_attachment\r
     # Save the attachments\r
-    params[:attachments].each { |a|\r
-      @attachment = @issue.attachments.build(:file => a, :author => self.logged_in_user) unless a.size == 0\r
-      @attachment.save\r
+    @attachments = []\r
+    params[:attachments].each { |file|\r
+      next unless file.size > 0\r
+      a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)\r
+      @attachments << a unless a.new_record?\r
     } if params[:attachments] and params[:attachments].is_a? Array\r
+    Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?\r
     redirect_to :action => 'show', :id => @issue\r
   end\r
 \r
index f536c39a23f0f0f7e861974f8355065afee1fe61..e7db204ed63033be6c1b16a7189c4046919726ef 100644 (file)
@@ -184,6 +184,7 @@ class ProjectsController < ApplicationController
         Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0\r
       } if params[:attachments] and params[:attachments].is_a? Array\r
       flash[:notice] = l(:notice_successful_create)\r
+      Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?\r
       redirect_to :action => 'list_documents', :id => @project\r
     end\r
   end\r
@@ -385,9 +386,13 @@ class ProjectsController < ApplicationController
     if request.post?\r
       @version = @project.versions.find_by_id(params[:version_id])\r
       # Save the attachments\r
-      params[:attachments].each { |a|\r
-        Attachment.create(:container => @version, :file => a, :author => logged_in_user) unless a.size == 0\r
+      @attachments = []\r
+      params[:attachments].each { |file|\r
+        next unless file.size > 0\r
+        a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)\r
+        @attachments << a unless a.new_record?\r
       } if params[:attachments] and params[:attachments].is_a? Array\r
+      Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?\r
       redirect_to :controller => 'projects', :action => 'list_files', :id => @project\r
     end\r
     @versions = @project.versions\r
index ba93b5bc7402738d8757f5894fbe4a64ab417990..0da6f967ff45c8467949d8469d09585a3e26218f 100644 (file)
@@ -36,6 +36,36 @@ class Mailer < ActionMailer::Base
     @body['journal']= journal\r
   end\r
   \r
+  def document_add(document)\r
+    @recipients     = document.project.users.collect { |u| u.mail if u.mail_notification }.compact\r
+    @from           = Setting.mail_from\r
+    @subject        = "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"\r
+    @body['document'] = document\r
+  end\r
+  \r
+  def attachments_add(attachments)\r
+    container = attachments.first.container\r
+    url = "http://#{Setting.host_name}/"\r
+    added_to = ""\r
+    case container.class.to_s\r
+    when 'Version'\r
+      url << "projects/list_files/#{container.project_id}"\r
+      added_to = "#{l(:label_version)}: #{container.name}"\r
+    when 'Document'\r
+      url << "documents/show/#{container.id}"\r
+      added_to = "#{l(:label_document)}: #{container.title}"\r
+    when 'Issue'\r
+      url << "issues/show/#{container.id}"\r
+      added_to = "#{container.tracker.name} ##{container.id}: #{container.subject}"\r
+    end\r
+    @recipients     = container.project.users.collect { |u| u.mail if u.mail_notification }.compact\r
+    @from           = Setting.mail_from\r
+    @subject        = "[#{container.project.name}] #{l(:label_attachment_new)}"\r
+    @body['attachments'] = attachments\r
+    @body['url']    = url\r
+    @body['added_to'] = added_to\r
+  end\r
+  \r
   def lost_password(token)\r
     @recipients     = token.user.mail\r
     @from           = Setting.mail_from\r
diff --git a/app/views/mailer/attachments_add_de.rhtml b/app/views/mailer/attachments_add_de.rhtml
new file mode 100644 (file)
index 0000000..f17af9d
--- /dev/null
@@ -0,0 +1,6 @@
+<%= @added_to %>\r
+<%= @attachments.size %> files(s) added.\r
+<% @attachments.each do |attachment | %>\r
+- <%= attachment.filename %><% end %>\r
+\r
+<%= @url %>
\ No newline at end of file
diff --git a/app/views/mailer/attachments_add_en.rhtml b/app/views/mailer/attachments_add_en.rhtml
new file mode 100644 (file)
index 0000000..f17af9d
--- /dev/null
@@ -0,0 +1,6 @@
+<%= @added_to %>\r
+<%= @attachments.size %> files(s) added.\r
+<% @attachments.each do |attachment | %>\r
+- <%= attachment.filename %><% end %>\r
+\r
+<%= @url %>
\ No newline at end of file
diff --git a/app/views/mailer/attachments_add_es.rhtml b/app/views/mailer/attachments_add_es.rhtml
new file mode 100644 (file)
index 0000000..f17af9d
--- /dev/null
@@ -0,0 +1,6 @@
+<%= @added_to %>\r
+<%= @attachments.size %> files(s) added.\r
+<% @attachments.each do |attachment | %>\r
+- <%= attachment.filename %><% end %>\r
+\r
+<%= @url %>
\ No newline at end of file
diff --git a/app/views/mailer/attachments_add_fr.rhtml b/app/views/mailer/attachments_add_fr.rhtml
new file mode 100644 (file)
index 0000000..381b489
--- /dev/null
@@ -0,0 +1,6 @@
+<%= @added_to %>\r
+<%= @attachments.size %> fichier(s) ajouté(s).\r
+<% @attachments.each do |attachment | %>\r
+- <%= attachment.filename %><% end %>\r
+\r
+<%= @url %>
\ No newline at end of file
diff --git a/app/views/mailer/document_add_de.rhtml b/app/views/mailer/document_add_de.rhtml
new file mode 100644 (file)
index 0000000..a022829
--- /dev/null
@@ -0,0 +1,4 @@
+A document has been added to <%= @document.project.name %> (<%= @document.category.name %>):\r
+<%= l(:field_title) %>: <%= @document.title %>\r
+\r
+http://<%= Setting.host_name %>/documents/show/<%= @document.id %>
\ No newline at end of file
diff --git a/app/views/mailer/document_add_en.rhtml b/app/views/mailer/document_add_en.rhtml
new file mode 100644 (file)
index 0000000..a022829
--- /dev/null
@@ -0,0 +1,4 @@
+A document has been added to <%= @document.project.name %> (<%= @document.category.name %>):\r
+<%= l(:field_title) %>: <%= @document.title %>\r
+\r
+http://<%= Setting.host_name %>/documents/show/<%= @document.id %>
\ No newline at end of file
diff --git a/app/views/mailer/document_add_es.rhtml b/app/views/mailer/document_add_es.rhtml
new file mode 100644 (file)
index 0000000..a022829
--- /dev/null
@@ -0,0 +1,4 @@
+A document has been added to <%= @document.project.name %> (<%= @document.category.name %>):\r
+<%= l(:field_title) %>: <%= @document.title %>\r
+\r
+http://<%= Setting.host_name %>/documents/show/<%= @document.id %>
\ No newline at end of file
diff --git a/app/views/mailer/document_add_fr.rhtml b/app/views/mailer/document_add_fr.rhtml
new file mode 100644 (file)
index 0000000..c116c84
--- /dev/null
@@ -0,0 +1,4 @@
+Un document a été ajouté à <%= @document.project.name %> (<%= @document.category.name %>):\r
+<%= l(:field_title) %>: <%= @document.title %>\r
+\r
+http://<%= Setting.host_name %>/documents/show/<%= @document.id %>
\ No newline at end of file
diff --git a/db/migrate/018_set_doc_and_files_notifications.rb b/db/migrate/018_set_doc_and_files_notifications.rb
new file mode 100644 (file)
index 0000000..adbdd3b
--- /dev/null
@@ -0,0 +1,15 @@
+class SetDocAndFilesNotifications < ActiveRecord::Migration
+  def self.up
+    Permission.find_by_controller_and_action("projects", "add_file").update_attribute(:mail_option, true)
+    Permission.find_by_controller_and_action("projects", "add_document").update_attribute(:mail_option, true)
+    Permission.find_by_controller_and_action("documents", "add_attachment").update_attribute(:mail_option, true)
+    Permission.find_by_controller_and_action("issues", "add_attachment").update_attribute(:mail_option, true)
+  end
+
+  def self.down
+    Permission.find_by_controller_and_action("projects", "add_file").update_attribute(:mail_option, false)
+    Permission.find_by_controller_and_action("projects", "add_document").update_attribute(:mail_option, false)
+    Permission.find_by_controller_and_action("documents", "add_attachment").update_attribute(:mail_option, false)
+    Permission.find_by_controller_and_action("issues", "add_attachment").update_attribute(:mail_option, false)
+  end
+end