#216 having notification emails translated

This commit is contained in:
Karel Picman 2014-02-24 14:38:01 +01:00
parent 17932c2c04
commit 3351ab44a6
22 changed files with 224 additions and 189 deletions

View File

@ -115,7 +115,7 @@ class DmsfController < ApplicationController
render :action => 'email_entries'
return
end
DmsfMailer.send_documents(User.current, @email_params['to'], @email_params['cc'],
DmsfMailer.send_documents(@project, User.current, @email_params['to'], @email_params['cc'],
@email_params['subject'], @email_params['zipped_content'], @email_params['body']).deliver
File.delete(@email_params['zipped_content'])
flash[:notice] = l(:notice_email_sent, @email_params['to'])
@ -190,7 +190,13 @@ class DmsfController < ApplicationController
deleted_files.each do |f|
log_activity(f, 'deleted')
end
DmsfMailer.files_deleted(User.current, deleted_files).deliver
begin
DmsfMailer.get_notify_users(User.current, deleted_files).each do |u|
DmsfMailer.files_deleted(u, deleted_files).deliver
end
rescue Exception => e
Rails.logger.error "Could not send email notifications: #{e.message}"
end
end
if failed_entries.empty?
flash[:notice] = l(:notice_entries_deleted)

View File

@ -69,13 +69,9 @@ class DmsfFilesController < ApplicationController
#TODO: don't create revision if nothing change
def create_revision
unless params[:dmsf_file_revision]
redirect_to :action => 'show', :id => @file
return
end
if params[:dmsf_file_revision]
if @file.locked_for_user?
flash[:error] = l(:error_file_is_locked)
redirect_to :action => 'show', :id => @file
else
#TODO: validate folder_id
@revision = DmsfFileRevision.new(params[:dmsf_file_revision])
@ -121,35 +117,42 @@ class DmsfFilesController < ApplicationController
end
end
@file.save!
@file.reload
@file.set_last_revision @revision
flash[:notice] = (flash[:notice].nil? ? '' : flash[:notice]) + l(:notice_file_revision_created)
log_activity('new revision')
begin
DmsfMailer.files_updated(User.current, [@file]).deliver
DmsfMailer.get_notify_users(User.current, [@file]).each do |u|
DmsfMailer.files_updated(u, [@file]).deliver
end
rescue Exception => e
logger.error "Could not send email notifications: #{e.message}"
end
redirect_to :action => 'show', :id => @file
else
render :action => 'show'
end
end
end
redirect_to :back
end
def delete
if @file
if @file.delete
flash[:notice] = l(:notice_file_deleted)
log_activity('deleted')
DmsfMailer.files_deleted(User.current, [@file]).deliver
begin
DmsfMailer.get_notify_users(User.current, [@file]).each do |u|
DmsfMailer.files_deleted(u, [@file]).deliver
end
rescue Exception => e
Rails.logger.error "Could not send email notifications: #{e.message}"
end
else
@file.errors.each do |e, msg|
flash[:error] = msg
end
end
end
redirect_to :controller => 'dmsf', :action => 'show', :id => @project, :folder_id => @file.folder
redirect_to dmsf_folder_path(:id => @project, :folder_id => @file.folder)
end
def delete_revision

View File

@ -69,13 +69,8 @@ class DmsfFilesCopyController < ApplicationController
flash[:notice] = l(:notice_file_copied)
log_activity(new_file, 'was copied (is copy)')
begin
DmsfMailer.files_updated(User.current, [new_file]).deliver
rescue ActionView::MissingTemplate => e
Rails.logger.error "Could not send email notifications: #{e.message}"
end
redirect_to :controller => 'dmsf_files', :action => 'show', :id => new_file
redirect_to dmsf_file_path(new_file)
end
def move
@ -106,14 +101,8 @@ class DmsfFilesCopyController < ApplicationController
flash[:notice] = l(:notice_file_moved)
log_activity(@file, 'was moved (is copy)')
begin
# TODO: implement proper mail notification
DmsfMailer.files_updated(User.current, [@file]).deliver
rescue ActionView::MissingTemplate => e
Rails.logger.error "Could not send email notifications: #{e.message}"
end
redirect_to :controller => 'dmsf_files', :action => 'show', :id => @file
redirect_to dmsf_file_path(@file)
end
private

View File

@ -70,14 +70,7 @@ class DmsfFoldersCopyController < ApplicationController
flash[:notice] = l(:notice_folder_copied)
log_activity(new_folder, 'was copied (is copy)')
#TODO: implement proper notification for all new files
#begin
# DmsfMailer.files_updated(User.current, [new_file]).deliver
#rescue ActionView::MissingTemplate => e
# Rails.logger.error "Could not send email notifications: " + e
#end
redirect_to :controller => 'dmsf', :action => 'show', :id => @target_project, :folder_id => new_folder
redirect_to dmsf_folder_path(:id => @target_project, :folder_id => new_folder)
end
private

View File

@ -171,8 +171,10 @@ class DmsfUploadController < ApplicationController
unless files.empty?
files.each { |file| log_activity(file, 'uploaded') if file }
begin
DmsfMailer.files_updated(User.current, files).deliver
rescue ActionView::MissingTemplate => e
DmsfMailer.get_notify_users(User.current, files).each do |u|
DmsfMailer.files_updated(u, files).deliver
end
rescue Exception => e
Rails.logger.error "Could not send email notifications: #{e.message}"
end
end
@ -180,7 +182,7 @@ class DmsfUploadController < ApplicationController
flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u['name']}.join(', '))
end
end
redirect_to :controller => 'dmsf', :action => 'show', :id => @project, :folder_id => @folder
redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder)
end
private

View File

@ -225,7 +225,7 @@ class DmsfFile < ActiveRecord::Base
file.name = self.name
file.notification = Setting.plugin_redmine_dmsf['dmsf_default_notifications'].present?
if file.save
if file.save && self.last_revision
new_revision = self.last_revision.clone
new_revision.file = file

View File

@ -1,6 +1,7 @@
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011 Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2011-14 Karel Pičman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -19,46 +20,56 @@
require 'mailer'
class DmsfMailer < Mailer
layout 'mailer'
def files_updated(user, files)
if user && files.count > 0
project = files[0].project
files = files.select { |file| file.notify? }
redmine_headers "Project" => project.identifier
redmine_headers 'Project' => project.identifier if project
@user = user
@files = files
@project = project
mail :to => get_notify_user_emails(user, files),
:subject => "#{project.name}: Dmsf files updated"
set_language_if_valid user.language
mail :to => user.mail,
:subject => l(:text_email_doc_updated_subject, :project => project.name)
end
end
def files_deleted(user, files)
if user && files.count > 0
project = files[0].project
files = files.select { |file| file.notify? }
redmine_headers 'Project' => project.identifier
redmine_headers 'Project' => project.identifier if project
@user = user
@files = files
@project = project
mail :to => get_notify_user_emails(user, files),
:subject => "#{project.name}: Dmsf files deleted"
set_language_if_valid user.language
mail :to => user.mail,
:subject => l(:text_email_doc_deleted_subject, :project => project.name)
end
end
def send_documents(user, email_to, email_cc, email_subject, zipped_content, email_plain_body)
def send_documents(project, user, email_to, email_cc, email_subject, zipped_content, email_plain_body)
zipped_content_data = open(zipped_content, 'rb') {|io| io.read }
redmine_headers 'Project' => project.identifier if project
@body = email_plain_body
attachments['Documents.zip'] = {:content_type => 'application/zip', :content => zipped_content_data}
mail(:to => email_to, :cc => email_cc, :subject => email_subject, :from => user.mail)
mail :to => email_to, :cc => email_cc, :subject => email_subject, :from => user.mail
end
def workflow_notification(user, workflow, revision, subject, text1, text2)
if user && workflow && revision
redmine_headers 'Project' => revision.file.project.identifier if revision.file && revision.file.project
set_language_if_valid user.language
@user = user
@workflow = workflow
@ -69,15 +80,13 @@ class DmsfMailer < Mailer
end
end
private
def get_notify_user_emails(user, files)
def self.get_notify_users(user, files)
return [] if files.empty?
project = files[0].project
notify_members = project.members
notify_members = notify_members.select do |notify_member|
notify_user = notify_member.user
if notify_user.pref[:no_self_notified] == '1' && notify_user == user
if notify_user == user && user.pref.no_self_notified
false
else
unless notify_member.dmsf_mail_notification
@ -97,7 +106,7 @@ class DmsfMailer < Mailer
end
end
notify_members.collect {|m| m.user.mail }
notify_members.collect { |m| m.user }
end
end

View File

@ -18,13 +18,13 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%>
<%= link_to @user, user_path(@user, :only_path => false) %> has just deleted documents of
<%= link_to @project, project_path(@project, :only_path => false) %> as follows:
<%= link_to @user, user_path(@user, :only_path => false) %> <%= l(:text_email_doc_deleted) %>
<%= link_to @project, project_path(@project, :only_path => false) %> <%= l(:text_email_doc_follows) %>
<% @files.each do |file| %>
<p>
<%= h(file.dmsf_path_str) %> (<%= file.name %>)
<% if file.last_revision %>
, <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>
, <%= number_to_human_size(file.last_revision.size) %>, <%= l(:label_version) %> <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>
<% end %>
</p>
<% end %>

View File

@ -18,10 +18,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%>
<%= @user.name %> has just deleted documents of <%= @project.name %> as follows:
<%= @user.name %> <%= l(:text_email_doc_deleted) %> <%= @project.name %> <%= l(:text_email_doc_follows) %>
<% @files.each do |file| %>
<%= file.dmsf_path_str %> (<%= file.name %>)
<%= h(file.dmsf_path_str) %> (<%= file.name %>)
<% if file.last_revision %>
, <%= number_to_human_size(file.last_revision.size) %>, version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>
, <%= number_to_human_size(file.last_revision.size) %>, <%= l(:label_version) %> <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>
<% end %>
<% end %>

View File

@ -18,18 +18,18 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%>
<%= link_to @user, user_path(@user, :only_path => false) %> has just actualized documents of
<%= link_to @project, project_path(@project, :only_path => false) %> as follows:
<%= link_to @user, user_path(@user, :only_path => false) %> <%= l(:text_email_doc_updated) %>
<%= link_to @project, project_path(@project, :only_path => false) %> <%= l(:text_email_doc_follows) %>
<% @files.each do |file| %>
<p>
<%= link_to(h(file.dmsf_path_str),
{:only_path => false, :controller => 'dmsf_files', :action => 'show', :id => file,
:download => ''}) %> (<%= file.name %>),
dmsf_file_path(file, :download => '', :only_path => false)) %>
(<%= file.name %>),
<%= number_to_human_size(file.last_revision.size) %>,
version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>,
<%= l(:label_version) %> <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>,
<%= "#{file.last_revision.workflow_str(true)}," if file.last_revision.workflow_str(true) != l(:title_none) %>
<%= link_to('Details',
{:only_path => false, :controller => 'dmsf_files', :action => 'show', :id => file}) %>
<%= link_to(l(:link_details, :title => h(file.title)),
dmsf_file_path(file, :only_path => false)) %>
<% if file.last_revision.comment.present? %>
<br/><span style="font-size: 0.9em">&nbsp;&nbsp;&nbsp;&nbsp;<em><%= h(file.last_revision.comment) %></em></span>
<% end %>

View File

@ -18,14 +18,15 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%>
<%= @user.name %> has just actualized documents of <%= @project.name %> as follows:
<%= @user.name %> <%= l(:text_email_doc_updated) %>
<%= @project.name %> <%= l(:text_email_doc_follows) %>
<% @files.each do |file| %>
<%= file.dmsf_path_str %> (<%= file.name %>),
<%= h(file.dmsf_path_str) %> (<%= file.name %>),
<%= number_to_human_size(file.last_revision.size) %>,
version: <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>,
<%= l(:label_version) %> <%= file.last_revision.major_version %>.<%= file.last_revision.minor_version %>,
<%= "#{file.last_revision.workflow_str(true)}," if file.last_revision.workflow_str(true) != l(:title_none) %>
<%= url_for({:only_path => false, :controller => 'dmsf_files', :action => 'show', :id => file}) %>
<%= dmsf_file_path(file, :only_path => false) %>
<% if file.last_revision.comment.present? %>
comment: <%= h(file.last_revision.comment) %>
<%= l(:label_comment) %> <%= h(file.last_revision.comment) %>
<% end %>
<% end %>

View File

@ -23,9 +23,11 @@
<p>
<%= @text2 %>
<% unless @revision.folder %>
<%= link_to l(:link_documents), {:controller => 'dmsf', :action => 'show', :id=> @revision.file.project, :only_path => false } %>
<%= link_to l(:link_documents),
dmsf_folder_path(:id => @revision.file.project, :only_path => false) %>
<% else %>
<%= link_to @revision.folder.title, {:controller => 'dmsf', :action => 'show', :id=> @revision.file.project, :folder_id => @revision.folder, :only_path => false } %>
<%= link_to @revision.folder.title,
dmsf_folder_path(:id => @revision.file.project, :folder_id => @revision.folder, :only_path => false) %>
<% end %>.
</p>

View File

@ -16,10 +16,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%>
<%= @user.name %> ,
<%= @user.name %>,
<%= @text1 %>
<% unless @revision.folder %>
<%= @text2 %> <%= url_for(:controller => 'dmsf', :action => 'show', :id => @revision.file.project, :only_path => false) %>.
<%= @text2 %> <%= dmsf_folder_path(:id => @revision.file.project, :only_path => false) %>.
<% else %>
<%= @text2 %> <%= url_for(:controller => 'dmsf', :action => 'show', :id => @revision.file.project, :folder_id => @revision.folder, :only_path => false) %>.
<%= @text2 %> <%= dmsf_folder_path(:id => @revision.file.project, :folder_id => @revision.folder, :only_path => false) %>.
<% end %>

View File

@ -110,10 +110,8 @@ cs:
label_changed: Změněno
info_changed_by_user: "%{changed} uživatelem"
label_filename: Jméno souboru
label_version: Verze
label_mime: Typ
label_size: Velikost
label_comment: Komentář
heading_new_revision: Nová revize
option_version_same: Stejná
option_version_minor: Podružná
@ -281,6 +279,12 @@ cs:
field_target_file: Cílový soubor
title_download_entries: Historie stahování
text_email_doc_updated_subject: "Dokumenty projektu %{project} aktualizovány"
text_email_doc_updated: právě aktualizoval dokumenty projektu
text_email_doc_follows: takto
text_email_doc_deleted_subject: "Dokumenty projektu %{project} smazány"
text_email_doc_deleted: právě smazal dokumety projektu
my:
blocks:
locked_documents: Zamčené dokumenty

View File

@ -109,10 +109,8 @@ de:
label_changed: Geändert
info_changed_by_user: "%{changed} von"
label_filename: Dateiname
label_version: Version
label_mime: Mime
label_size: Größe
label_comment: Kommentar
heading_new_revision: Neue Version
option_version_same: gleiche Version
option_version_minor: Unterversion

View File

@ -111,11 +111,9 @@ en:
label_changed: Changed
info_changed_by_user: "%{changed} by"
label_filename: Filename
label_version: Version
label_approval_workflow: Workflow
label_mime: Mime
label_size: Size
label_comment: Comment
heading_new_revision: New Revision
option_version_same: Same
option_version_minor: Minor
@ -285,6 +283,12 @@ en:
field_target_file: Target file
title_download_entries: Download entries
text_email_doc_updated_subject: "Documents of %{project} updated"
text_email_doc_updated: has just actualized documents of
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
my:
blocks:
locked_documents: Locked documents

View File

@ -111,10 +111,8 @@ es:
label_changed: Changed
info_changed_by_user: "%{changed} by"
label_filename: Filename
label_version: Version
label_mime: Mime
label_size: Size
label_comment: Comment
heading_new_revision: New Revision
option_version_same: Same
option_version_minor: Minor
@ -282,6 +280,12 @@ es:
field_target_file: Target file
title_download_entries: Download entries
text_email_doc_updated_subject: "Documents of %{project} updated"
text_email_doc_updated: has just actualized documents of
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
my:
blocks:
locked_documents: Locked documents

View File

@ -111,11 +111,9 @@ fr:
label_changed: Modifié
info_changed_by_user: "%{changed} par"
label_filename: Fichier
label_version: Version
label_approval_workflow: Flux de validation
label_mime: Type
label_size: Taille
label_comment: Commentaires
heading_new_revision: Nouvelle révision
option_version_same: (identique)
option_version_minor: (modification mineure)
@ -285,6 +283,12 @@ fr:
field_target_file: Target file
title_download_entries: Download entries
text_email_doc_updated_subject: "Documents of %{project} updated"
text_email_doc_updated: has just actualized documents of
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
my:
blocks:
locked_documents: Documents verrouillés

View File

@ -109,10 +109,8 @@ ja:
label_changed: 更新者/日時
info_changed_by_user: "/ %{changed}"
label_filename: ファイル名
label_version: バージョン
label_mime: Mime
label_size: サイズ
label_comment: コメント
heading_new_revision: 新しいリビジョン
option_version_same: 変更なし
option_version_minor: マイナー
@ -282,6 +280,12 @@ ja:
field_target_file: Target file
title_download_entries: Download entries
text_email_doc_updated_subject: "Documents of %{project} updated"
text_email_doc_updated: has just actualized documents of
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
my:
blocks:
locked_documents: Locked documents

View File

@ -109,10 +109,8 @@ ru:
label_changed: Изменен
info_changed_by_user: "%{changed} пользователем"
label_filename: Имя файла
label_version: Версия
label_mime: MIME-тип
label_size: Размер
label_comment: Комментарий
heading_new_revision: Новая редакция
option_version_same: Та же версия
option_version_minor: Незначительные изменения
@ -282,6 +280,12 @@ ru:
field_target_file: Target file
title_download_entries: Download entries
text_email_doc_updated_subject: "Documents of %{project} updated"
text_email_doc_updated: has just actualized documents of
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
my:
blocks:
locked_documents: Locked documents

View File

@ -109,10 +109,8 @@ sl:
label_changed: Spremenjeno
info_changed_by_user: "%{changed} po"
label_filename: Datoteka
label_version: Verzija
label_mime: Mime
label_size: Velikost
label_comment: Komentar
heading_new_revision: Nova verzija
option_version_same: Enako
option_version_minor: Minor
@ -282,6 +280,12 @@ sl:
field_target_file: Target file
title_download_entries: Download entries
text_email_doc_updated_subject: "Documents of %{project} updated"
text_email_doc_updated: has just actualized documents of
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
my:
blocks:
locked_documents: Locked documents

View File

@ -109,10 +109,8 @@ zh:
label_changed: 修改
info_changed_by_user: "%{changed} by"
label_filename: 文件名
label_version: 版本
label_mime: Mime
label_size: 大小
label_comment: 注释
heading_new_revision: 新修订
option_version_same: Same
option_version_minor: Minor
@ -283,6 +281,12 @@ zh:
field_target_file: Target file
title_download_entries: Download entries
text_email_doc_updated_subject: "Documents of %{project} updated"
text_email_doc_updated: has just actualized documents of
text_email_doc_follows: as follows
text_email_doc_deleted_subject: "Documents of %{project} deleted"
text_email_doc_deleted: has just deleted documents of
my:
blocks:
locked_documents: Locked documents