# 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
\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
# 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
\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
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
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
@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
--- /dev/null
+<%= @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
--- /dev/null
+<%= @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
--- /dev/null
+<%= @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
--- /dev/null
+<%= @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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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