parent
44cdc13307
commit
aace67b63e
@ -0,0 +1,55 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is an open source project management software. |
||||||
|
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License version 3. |
||||||
|
# |
||||||
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||||
|
# Copyright (C) 2010-2013 the ChiliProject Team |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License |
||||||
|
# as published by the Free Software Foundation; either version 2 |
||||||
|
# of the License, or (at your option) any later version. |
||||||
|
# |
||||||
|
# This program is distributed in the hope that it will be useful, |
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
# GNU General Public License for more details. |
||||||
|
# |
||||||
|
# You should have received a copy of the GNU General Public License |
||||||
|
# along with this program; if not, write to the Free Software |
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||||
|
# |
||||||
|
# See COPYRIGHT and LICENSE files for more details. |
||||||
|
#++ |
||||||
|
|
||||||
|
# Sends mails for announcements. |
||||||
|
# For now, it cannot handle sending events on any Announcement model but is rather focused |
||||||
|
# on handing very simple mails where only the recipient, subject and body is provided. |
||||||
|
|
||||||
|
class AnnouncementMailer < ApplicationMailer |
||||||
|
include OpenProject::StaticRouting::UrlHelpers |
||||||
|
include OpenProject::TextFormatting |
||||||
|
helper :mail_notification |
||||||
|
|
||||||
|
def announce(user, subject:, body:, body_header: nil, body_subheader: nil) |
||||||
|
with_locale_for(user) do |
||||||
|
mail to: user.mail, |
||||||
|
subject: subject do |format| |
||||||
|
locals = { |
||||||
|
body: body, |
||||||
|
user: user, |
||||||
|
header_summary: subject, |
||||||
|
body_header: body_header, |
||||||
|
body_subheader: body_subheader |
||||||
|
} |
||||||
|
|
||||||
|
format.html { render locals: locals } |
||||||
|
format.text { render locals: locals } |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,42 @@ |
|||||||
|
<%= render layout: 'mailer/spacer_table' do %> |
||||||
|
<%= render partial: 'mailer/notification_mailer_header', |
||||||
|
locals: { |
||||||
|
summary: header_summary, |
||||||
|
user: user |
||||||
|
} %> |
||||||
|
|
||||||
|
<%= render layout: 'mailer/border_table' do %> |
||||||
|
<tr> |
||||||
|
<%= placeholder_cell('24px', vertical: true) %> |
||||||
|
<td> |
||||||
|
<table> |
||||||
|
<% if body_subheader %> |
||||||
|
<tr> |
||||||
|
<td style="<%= placeholder_text_styles('font-weight': 'bold') %>"> |
||||||
|
<%= format_text body_subheader %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<% end %> |
||||||
|
<% if body_header %> |
||||||
|
<tr> |
||||||
|
<td style="<%= placeholder_text_styles(color: '#333333', 'line-height': '36px', 'font-size': '18px', 'font-weight': 'bold') %>"> |
||||||
|
<%= format_text body_header %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<% end %> |
||||||
|
<tr> |
||||||
|
<td style="<%= placeholder_text_styles %>"> |
||||||
|
<%= format_text body %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
<%= placeholder_cell('24px', vertical: true) %> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<%= placeholder_cell('24px', vertical: false) %> |
||||||
|
</tr> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= render partial: 'mailer/notification_settings_table' %> |
||||||
|
<% end %> |
@ -0,0 +1,13 @@ |
|||||||
|
<%= I18n.t(:'mail.salutation', user: user.firstname) %> |
||||||
|
<%= header_summary %> |
||||||
|
<%= "-" * 100 %> |
||||||
|
|
||||||
|
|
||||||
|
<%= "+" * 50 %> |
||||||
|
<%= strip_tags body_subheader %> |
||||||
|
<%= strip_tags body_header %> |
||||||
|
<%= "+" * 50 %> |
||||||
|
|
||||||
|
<%= strip_tags body %> |
||||||
|
|
||||||
|
<%= "-" * 100 %> |
@ -0,0 +1,21 @@ |
|||||||
|
<table <%= placeholder_table_styles(width:'100%',style: "width:100%;border-width:1px;border-color:#E0E0E0;border-style:solid;border-radius:10px") %>> |
||||||
|
<tr> |
||||||
|
<%= placeholder_cell('12px', vertical: false) %> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<table <%= placeholder_table_styles(width:'100%',style: 'width:100%;font-size:14px;') %>> |
||||||
|
<%= yield %> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<%= placeholder_cell('12px', vertical: false) %> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<%= placeholder_cell('20px', vertical: false) %> |
||||||
|
</tr> |
||||||
|
</table> |
@ -0,0 +1,17 @@ |
|||||||
|
<table <%= placeholder_table_styles(style: 'font-size:14px;') %>> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<table <%= placeholder_table_styles(width:'100%',style: 'width:100%;') %>> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<%= yield %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
<%= placeholder_cell('10px', vertical: true) %> |
||||||
|
<td> |
||||||
|
<%= render partial: 'mailer/notification_settings_button' %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
@ -0,0 +1,21 @@ |
|||||||
|
<table <%= placeholder_table_styles %>> |
||||||
|
<tr> |
||||||
|
<%= placeholder_cell('20px', vertical: false) %> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
<table <%= placeholder_table_styles(width:'100%',style: 'width:100%;max-width:700px;') %>> |
||||||
|
<tr> |
||||||
|
<%= placeholder_cell('12px', vertical: true) %> |
||||||
|
<td> |
||||||
|
<%= yield %> |
||||||
|
|
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<%= placeholder_cell('40px', vertical: false) %> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
<%= placeholder_cell('12px', vertical: true) %> |
||||||
|
</tr> |
||||||
|
</table> |
@ -0,0 +1,13 @@ |
|||||||
|
class QueueNotificationUpdateMail < ActiveRecord::Migration[6.1] |
||||||
|
def up |
||||||
|
User.active.find_each do |user| |
||||||
|
AnnouncementMailer |
||||||
|
.announce(user, |
||||||
|
subject: I18n.t(:'notifications.update_info_mail.subject'), |
||||||
|
body: I18n.t(:'notifications.update_info_mail.body'), |
||||||
|
body_header: I18n.t(:'notifications.update_info_mail.body_header'), |
||||||
|
body_subheader: I18n.t(:'notifications.update_info_mail.body_subheader')) |
||||||
|
.deliver_later |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,63 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is an open source project management software. |
||||||
|
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License version 3. |
||||||
|
# |
||||||
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||||
|
# Copyright (C) 2010-2013 the ChiliProject Team |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License |
||||||
|
# as published by the Free Software Foundation; either version 2 |
||||||
|
# of the License, or (at your option) any later version. |
||||||
|
# |
||||||
|
# This program is distributed in the hope that it will be useful, |
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
# GNU General Public License for more details. |
||||||
|
# |
||||||
|
# You should have received a copy of the GNU General Public License |
||||||
|
# along with this program; if not, write to the Free Software |
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||||
|
# |
||||||
|
# See COPYRIGHT and LICENSE files for more details. |
||||||
|
#++ |
||||||
|
|
||||||
|
require 'spec_helper' |
||||||
|
|
||||||
|
describe AnnouncementMailer, type: :mailer do |
||||||
|
let(:announcement_subject) { 'Some subject' } |
||||||
|
let(:recipient) { FactoryBot.build_stubbed(:user) } |
||||||
|
let(:announcement_body) { 'Some body text' } |
||||||
|
|
||||||
|
describe '#announce' do |
||||||
|
subject(:mail) do |
||||||
|
described_class.announce(recipient, |
||||||
|
subject: announcement_subject, |
||||||
|
body: announcement_body) |
||||||
|
end |
||||||
|
|
||||||
|
it "has a subject" do |
||||||
|
expect(mail.subject) |
||||||
|
.to eq announcement_subject |
||||||
|
end |
||||||
|
|
||||||
|
it 'includes the body' do |
||||||
|
expect(mail.body.encoded) |
||||||
|
.to include(announcement_body) |
||||||
|
end |
||||||
|
|
||||||
|
it "includes the subject in the body as well" do |
||||||
|
expect(mail.body.encoded) |
||||||
|
.to include announcement_subject |
||||||
|
end |
||||||
|
|
||||||
|
it 'sends to the recipient' do |
||||||
|
expect(mail.to) |
||||||
|
.to match_array [recipient.mail] |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue