Skip to content

Commit a04415b

Browse files
authored
Merge pull request #22341 from opf/feature/73127-primerize-admin-emails-and-notifications
[73127] Primerize Admin > Emails and notifications
2 parents aa67381 + 9be48d2 commit a04415b

File tree

7 files changed

+229
-133
lines changed

7 files changed

+229
-133
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module Admin
32+
module Settings
33+
class AggregationSettingsForm < ApplicationForm
34+
include Redmine::I18n
35+
36+
settings_form do |f|
37+
f.text_field name: :journal_aggregation_time_minutes,
38+
type: :number,
39+
min: 0,
40+
input_width: :medium,
41+
trailing_visual: { text: { text: I18n.t("datetime.units.minute_abbreviated", count: 2) } }
42+
43+
f.submit
44+
end
45+
end
46+
end
47+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%= render(Primer::Beta::Text.new(tag: :p)) do %>
2+
<%= link_translate("admin.journal_aggregation.caption", links: { webhook_link: url_helpers.admin_outgoing_webhooks_path }) %>
3+
<% end %>
4+
<%= render(Primer::OpenProject::InlineMessage.new(scheme: :warning, size: :small)) do %>
5+
<%= render(Primer::Beta::Text.new(tag: :p)) do %>
6+
<%= I18n.t(:text_hint_disable_with_0) %>
7+
<% end %>
8+
<% end %>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module Admin
32+
module Settings
33+
class MailNotificationsSettingForm < ApplicationForm
34+
include ::Settings::FormHelper
35+
36+
settings_form do |f|
37+
if @deliveries
38+
f.text_field name: :mail_from, input_width: :medium
39+
f.check_box name: :bcc_recipients
40+
f.check_box name: :plain_text_mail
41+
f.select_list name: :emails_salutation,
42+
values: [
43+
[User.human_attribute_name(:firstname), :firstname],
44+
[I18n.t("mail.salutation_full_name"), :name]
45+
],
46+
input_width: :medium
47+
48+
f.fieldset_group(title: "#{I18n.t(:setting_emails_header)} & #{I18n.t(:setting_emails_footer)}", mt: 4) do |fg|
49+
fg.multi_language_text_select(name: :emails_header)
50+
fg.multi_language_text_select(name: :emails_footer)
51+
end
52+
end
53+
54+
unless OpenProject::Configuration["email_delivery_configuration"] == "legacy"
55+
email_methods = %i[smtp sendmail]
56+
email_methods += [:letter_opener] if Rails.env.development?
57+
58+
f.fieldset_group(title: I18n.t(:text_setup_mail_configuration), mt: 4) do |fg|
59+
fg.select_list(
60+
name: :email_delivery_method,
61+
values: email_methods.map { |m| [m.to_s, m] },
62+
input_width: :small,
63+
data: {
64+
show_when_value_selected_target: "cause",
65+
target_name: "email_delivery_method_settings"
66+
}
67+
)
68+
end
69+
70+
f.group(
71+
hidden: { true => Setting.email_delivery_method != :smtp },
72+
data: {
73+
show_when_value_selected_target: "effect",
74+
target_name: "email_delivery_method_settings",
75+
value: "smtp"
76+
}
77+
) do |smtp|
78+
smtp.text_field(name: :smtp_address, input_width: :medium)
79+
smtp.text_field(name: :smtp_port, type: :number, input_width: :xsmall)
80+
smtp.text_field(name: :smtp_domain, input_width: :medium)
81+
smtp.select_list(name: :smtp_authentication,
82+
values: %i[none plain login cram_md5].map { |m| [m.to_s, m] },
83+
input_width: :small)
84+
smtp.text_field(name: :smtp_user_name, input_width: :medium)
85+
smtp.text_field(name: :smtp_password, input_width: :medium)
86+
smtp.check_box(name: :smtp_enable_starttls_auto)
87+
smtp.check_box(name: :smtp_ssl)
88+
end
89+
90+
f.group(
91+
hidden: { true => Setting.email_delivery_method != :sendmail },
92+
data: {
93+
show_when_value_selected_target: "effect",
94+
target_name: "email_delivery_method_settings",
95+
value: "sendmail"
96+
}
97+
) do |sendmail|
98+
sendmail.text_field(name: :sendmail_location)
99+
sendmail.text_field(name: :sendmail_arguments)
100+
end
101+
end
102+
103+
f.submit
104+
end
105+
106+
def initialize(deliveries:)
107+
super()
108+
109+
@deliveries = deliveries
110+
end
111+
end
112+
end
113+
end

app/views/admin/settings/aggregation_settings/show.html.erb

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,13 @@ See COPYRIGHT and LICENSE files for more details.
4040
end
4141
%>
4242

43-
<%= styled_form_tag(admin_settings_aggregation_path, method: :patch) do %>
44-
<div class="form--field">
45-
<%= setting_number_field :journal_aggregation_time_minutes,
46-
unit: t(:label_minute_plural),
47-
min: 0,
48-
container_class: "-xslim" %>
49-
<span class="form--field-instructions">
50-
<%= t(
51-
:"admin.journal_aggregation.explanation.text",
52-
webhook_link: link_to(
53-
t(:"admin.journal_aggregation.explanation.link"),
54-
admin_outgoing_webhooks_path,
55-
target: "_blank"
56-
)
57-
).html_safe %>
58-
<br>
59-
<%= t(:text_hint_disable_with_0) %>
60-
</span>
61-
</div>
62-
63-
<%= styled_button_tag t(:button_save), class: "-primary -with-icon icon-checkmark" %>
64-
<% end %>
43+
<%=
44+
settings_primer_form_with(
45+
url: admin_settings_aggregation_path,
46+
scope: :settings,
47+
method: :patch,
48+
data: { turbo: false }
49+
) do |form|
50+
render Admin::Settings::AggregationSettingsForm.new(form)
51+
end
52+
%>

app/views/admin/settings/incoming_mails_settings/show.html.erb

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,26 @@ See COPYRIGHT and LICENSE files for more details.
4040
end
4141
%>
4242

43-
<%= styled_form_tag(admin_settings_incoming_mails_path, method: :patch) do %>
44-
<section class="form--section">
45-
<div class="form--field">
46-
<%= setting_text_area :mail_handler_body_delimiters, rows: 5, container_class: "-wide" %>
47-
<div class="form--field-instructions"><%= t(:text_line_separated) %></div>
48-
</div>
49-
<div class="form--field">
50-
<%= setting_text_field :mail_handler_body_delimiter_regex, container_class: "-wide" %>
51-
<div class="form--field-instructions"><%= t(:text_regexp_multiline) %></div>
52-
</div>
53-
<div class="form--field">
54-
<%= setting_text_area :mail_handler_ignore_filenames, rows: 5, container_class: "-wide" %>
55-
<div class="form--field-instructions"><%= t("incoming_mails.ignore_filenames") %></div>
56-
</div>
57-
</section>
58-
59-
<%= styled_button_tag t(:button_save), class: "-primary -with-icon icon-checkmark" %>
60-
<% end %>
43+
<%=
44+
settings_primer_form_with(
45+
url: admin_settings_incoming_mails_path,
46+
scope: :settings,
47+
method: :patch,
48+
data: { turbo: false }
49+
) do |form|
50+
render_inline_settings_form(form) do |f|
51+
f.text_area name: :mail_handler_body_delimiters,
52+
rows: 5,
53+
caption: t(:text_line_separated)
54+
55+
f.text_field name: :mail_handler_body_delimiter_regex,
56+
caption: t(:text_regexp_multiline)
57+
58+
f.text_area name: :mail_handler_ignore_filenames,
59+
rows: 5,
60+
caption: t("incoming_mails.ignore_filenames")
61+
62+
f.submit
63+
end
64+
end
65+
%>

app/views/admin/settings/mail_notifications_settings/show.html.erb

Lines changed: 26 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -40,98 +40,34 @@ See COPYRIGHT and LICENSE files for more details.
4040
end
4141
%>
4242

43+
<% unless @deliveries %>
44+
<%=
45+
render Primer::Alpha::Banner.new(scheme: :default) do
46+
t(:text_email_delivery_not_configured)
47+
end
48+
%>
49+
<% end %>
50+
4351
<%=
44-
styled_form_tag(
45-
admin_settings_mail_notifications_path,
52+
settings_primer_form_with(
53+
url: admin_settings_mail_notifications_path,
54+
scope: :settings,
4655
method: :patch,
47-
data: { controller: "show-when-value-selected" }
48-
) do
56+
data: { turbo: false,
57+
controller: "show-when-value-selected" }
58+
) do |form|
59+
render Admin::Settings::MailNotificationsSettingForm.new(form, deliveries: @deliveries)
60+
end
4961
%>
50-
<% if @deliveries %>
51-
<section class="form--section">
52-
<div class="form--field"><%= setting_text_field :mail_from, size: 60, container_class: "-middle" %></div>
53-
<div class="form--field"><%= setting_check_box :bcc_recipients %></div>
54-
<div class="form--field"><%= setting_check_box :plain_text_mail %></div>
55-
<div class="form--field">
56-
<%= setting_select :emails_salutation,
57-
[
58-
[User.human_attribute_name(:firstname), :firstname],
59-
[t("mail.salutation_full_name"), :name]
60-
],
61-
container_class: "-middle" %>
62-
</div>
63-
</section>
64-
65-
<fieldset id="emails_decorators" class="form--fieldset">
66-
<legend class="form--fieldset-legend"><%= t(:setting_emails_header) %>
67-
& <%= I18n.t(:setting_emails_footer) %></legend>
68-
<%= render Settings::TextSettingComponent.new(I18n.locale, name: "emails_header") %>
69-
<%= render Settings::TextSettingComponent.new(I18n.locale, name: "emails_footer") %>
70-
</fieldset>
71-
<% else %>
72-
<div class="nodata">
73-
<%= simple_format(t(:text_email_delivery_not_configured)) %>
74-
</div>
75-
<% end %>
76-
77-
<%
78-
email_methods = %i[smtp sendmail]
79-
email_methods << :letter_opener if Rails.env.development?
80-
%>
81-
<%= content_tag :fieldset, class: "form--fieldset" do %>
82-
<legend class="form--fieldset-legend"><%= t(:text_setup_mail_configuration) %></legend>
83-
<div class="form--field">
84-
<%=
85-
setting_select(
86-
:email_delivery_method,
87-
email_methods,
88-
container_class: "-slim",
89-
data: {
90-
show_when_value_selected_target: "cause",
91-
target_name: "email_delivery_method_settings"
92-
}
93-
)
94-
%>
95-
</div>
96-
<div
97-
data-show-when-value-selected-target="effect"
98-
data-target-name="email_delivery_method_settings"
99-
data-value="smtp"
100-
<%= "hidden" unless Setting.email_delivery_method == :smtp %>>
101-
<div class="form--field"><%= setting_text_field :smtp_address, container_class: "-middle" %></div>
102-
<div class="form--field"><%= setting_text_field :smtp_port, size: 6, container_class: "-xslim" %></div>
103-
<div class="form--field"><%= setting_text_field :smtp_domain, container_class: "-middle" %></div>
104-
<div class="form--field"><%= setting_select(:smtp_authentication, %i[none plain login cram_md5], container_class: "-slim") %></div>
105-
<div class="form--field"><%= setting_text_field :smtp_user_name, container_class: "-middle" %></div>
106-
<div class="form--field"><%= setting_password :smtp_password, container_class: "-middle" %></div>
107-
<div class="form--field"><%= setting_check_box :smtp_enable_starttls_auto %></div>
108-
<div class="form--field"><%= setting_check_box :smtp_ssl %></div>
109-
</div>
110-
<div
111-
data-show-when-value-selected-target="effect"
112-
data-target-name="email_delivery_method_settings"
113-
data-value="sendmail"
114-
<%= "hidden" unless Setting.email_delivery_method == :sendmail %>>
115-
<div class="form--field"><%= setting_text_field :sendmail_location %></div>
116-
<div class="form--field"><%= setting_text_field :sendmail_arguments %></div>
117-
</div>
118-
<div
119-
data-show-when-value-selected-target="effect"
120-
data-target-name="email_delivery_method_settings"
121-
data-value="letter_opener"
122-
<%= "hidden" unless Setting.email_delivery_method == :letter_opener %>>
123-
<p>Letter opener is used to render emails as a file in your Rails tmp folder. Mails will automatically open in
124-
your browser if supported.</p>
125-
</div>
126-
<% end unless OpenProject::Configuration['email_delivery_configuration'] == 'legacy' %>
127-
128-
<%= styled_button_tag t(:button_save), class: "-primary -with-icon icon-checkmark" %>
12962

130-
<% if @deliveries %>
131-
<div style="float:none;display:inline-block;font-weight:bold;">
132-
<%= link_to t(:label_send_test_email),
133-
{ controller: "/admin", action: "test_email" },
134-
data: { turbo_method: :post } %>
135-
</div>
136-
<% end %>
63+
<% if @deliveries %>
64+
<%= render Primer::Beta::Link.new(
65+
href: test_email_admin_index_path,
66+
data: { turbo_method: :post },
67+
font_weight: :bold,
68+
display: :block,
69+
mt: 3
70+
) do
71+
t(:label_send_test_email)
72+
end %>
13773
<% end %>

config/locales/en.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ en:
116116
trial: "Trial"
117117
jemalloc_allocator: Jemalloc memory allocator
118118
journal_aggregation:
119-
explanation:
120-
text: "Individual actions of a user (e.g. updating a work package twice) are aggregated into a single action if their age difference is less than the specified timespan. They will be displayed as a single action within the application. This will also delay notifications by the same amount of time reducing the number of emails being sent and will also affect %{webhook_link} delay."
121-
link: "webhook"
119+
caption: >
120+
Individual actions of a user (e.g. updating a work package twice) are aggregated into a single action if their age difference is less than the specified timespan. They will be displayed as a single action within the application. This will also delay notifications by the same amount of time reducing the number of emails being sent and will also affect the [webhook](webhook_link) delay.
122121
import:
123122
title: "Import"
124123
jira:

0 commit comments

Comments
 (0)