Commit 2d47a6d7 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

mail notifications added when:

* 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
parent 22c2209c
# redMine - project management software
# Copyright (C) 2006 Jean-Philippe Lang
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
......@@ -46,9 +46,13 @@ class DocumentsController < ApplicationController
def add_attachment
# Save the attachments
params[:attachments].each { |a|
Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
@attachments = []
params[:attachments].each { |file|
next unless file.size > 0
a = Attachment.create(:container => @document, :file => file, :author => logged_in_user)
@attachments << a unless a.new_record?
} if params[:attachments] and params[:attachments].is_a? Array
Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
redirect_to :action => 'show', :id => @document
end
......
# redMine - project management software
# Copyright (C) 2006 Jean-Philippe Lang
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
......@@ -115,10 +115,13 @@ class IssuesController < ApplicationController
def add_attachment
# Save the attachments
params[:attachments].each { |a|
@attachment = @issue.attachments.build(:file => a, :author => self.logged_in_user) unless a.size == 0
@attachment.save
@attachments = []
params[:attachments].each { |file|
next unless file.size > 0
a = Attachment.create(:container => @issue, :file => file, :author => logged_in_user)
@attachments << a unless a.new_record?
} if params[:attachments] and params[:attachments].is_a? Array
Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
redirect_to :action => 'show', :id => @issue
end
......
......@@ -184,6 +184,7 @@ class ProjectsController < ApplicationController
Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
} if params[:attachments] and params[:attachments].is_a? Array
flash[:notice] = l(:notice_successful_create)
Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
redirect_to :action => 'list_documents', :id => @project
end
end
......@@ -385,9 +386,13 @@ class ProjectsController < ApplicationController
if request.post?
@version = @project.versions.find_by_id(params[:version_id])
# Save the attachments
params[:attachments].each { |a|
Attachment.create(:container => @version, :file => a, :author => logged_in_user) unless a.size == 0
@attachments = []
params[:attachments].each { |file|
next unless file.size > 0
a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
@attachments << a unless a.new_record?
} if params[:attachments] and params[:attachments].is_a? Array
Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
end
@versions = @project.versions
......
......@@ -36,6 +36,36 @@ class Mailer < ActionMailer::Base
@body['journal']= journal
end
def document_add(document)
@recipients = document.project.users.collect { |u| u.mail if u.mail_notification }.compact
@from = Setting.mail_from
@subject = "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
@body['document'] = document
end
def attachments_add(attachments)
container = attachments.first.container
url = "http://#{Setting.host_name}/"
added_to = ""
case container.class.to_s
when 'Version'
url << "projects/list_files/#{container.project_id}"
added_to = "#{l(:label_version)}: #{container.name}"
when 'Document'
url << "documents/show/#{container.id}"
added_to = "#{l(:label_document)}: #{container.title}"
when 'Issue'
url << "issues/show/#{container.id}"
added_to = "#{container.tracker.name} ##{container.id}: #{container.subject}"
end
@recipients = container.project.users.collect { |u| u.mail if u.mail_notification }.compact
@from = Setting.mail_from
@subject = "[#{container.project.name}] #{l(:label_attachment_new)}"
@body['attachments'] = attachments
@body['url'] = url
@body['added_to'] = added_to
end
def lost_password(token)
@recipients = token.user.mail
@from = Setting.mail_from
......
<%= @added_to %>
<%= @attachments.size %> files(s) added.
<% @attachments.each do |attachment | %>
- <%= attachment.filename %><% end %>
<%= @url %>
\ No newline at end of file
<%= @added_to %>
<%= @attachments.size %> files(s) added.
<% @attachments.each do |attachment | %>
- <%= attachment.filename %><% end %>
<%= @url %>
\ No newline at end of file
<%= @added_to %>
<%= @attachments.size %> files(s) added.
<% @attachments.each do |attachment | %>
- <%= attachment.filename %><% end %>
<%= @url %>
\ No newline at end of file
<%= @added_to %>
<%= @attachments.size %> fichier(s) ajouté(s).
<% @attachments.each do |attachment | %>
- <%= attachment.filename %><% end %>
<%= @url %>
\ No newline at end of file
A document has been added to <%= @document.project.name %> (<%= @document.category.name %>):
<%= l(:field_title) %>: <%= @document.title %>
http://<%= Setting.host_name %>/documents/show/<%= @document.id %>
\ No newline at end of file
A document has been added to <%= @document.project.name %> (<%= @document.category.name %>):
<%= l(:field_title) %>: <%= @document.title %>
http://<%= Setting.host_name %>/documents/show/<%= @document.id %>
\ No newline at end of file
A document has been added to <%= @document.project.name %> (<%= @document.category.name %>):
<%= l(:field_title) %>: <%= @document.title %>
http://<%= Setting.host_name %>/documents/show/<%= @document.id %>
\ No newline at end of file
Un document a été ajouté à <%= @document.project.name %> (<%= @document.category.name %>):
<%= l(:field_title) %>: <%= @document.title %>
http://<%= Setting.host_name %>/documents/show/<%= @document.id %>
\ No newline at end of file
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment