Skip to content

Commit

Permalink
Merge branch 'release/14.0' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Apr 12, 2024
2 parents 30e6669 + dc263ad commit 7810d86
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ See COPYRIGHT and LICENSE files for more details.
reason: "#{Storages::Storage.extract_part_from_piped_string(@reason, 0)} - #{Storages::Storage.extract_part_from_piped_string(@reason, 1)}"
}) %>

<%#= render(partial: 'mailer/notification_settings_table',
<%= render(partial: 'mailer/notification_settings_table',
locals: {
button_url: @url,
button_text: I18n.t(:'mail.storages.health.email_notification_settings')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ See COPYRIGHT and LICENSE files for more details.

<%= I18n.t('mail.storages.health.plaintext.healthy.recommendation') %>

<%#= I18n.t('mail.storages.health.plaintext.unhealthy.unsubscribe') %>: <%= @url %>
<%= I18n.t('mail.storages.health.plaintext.unhealthy.unsubscribe') %>: <%= @url %>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ See COPYRIGHT and LICENSE files for more details.
reason: "#{@storage.health_reason_identifier} - #{@storage.health_reason_description}"
}) %>

<%#= render(partial: 'mailer/notification_settings_table',
<%= render(partial: 'mailer/notification_settings_table',
locals: {
button_url: @url,
button_text: I18n.t(:'mail.storages.health.email_notification_settings')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ See COPYRIGHT and LICENSE files for more details.

<%= I18n.t('mail.storages.health.plaintext.unhealthy.recommendation') %>: <%= @url %>

<%#= I18n.t('mail.storages.health.plaintext.unhealthy.unsubscribe') %>: <%= @url %>
<%= I18n.t('mail.storages.health.plaintext.unhealthy.unsubscribe') %>: <%= @url %>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HealthStatusMailerJob < ApplicationJob
total_limit: 2,
enqueue_limit: 1,
perform_limit: 1,
key: -> { "#{self.class.name}-#{arguments.last[:storage]}" }
key: -> { "#{self.class.name}-#{arguments.last[:storage].id}" }
)

discard_on ActiveJob::DeserializationError
Expand Down
47 changes: 47 additions & 0 deletions modules/storages/spec/mailers/storages/storages_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require "rails_helper"

RSpec.describe Storages::StoragesMailer do
let(:admin) { build_stubbed(:admin) }
let(:html_body) do
Capybara.string(mail.body.parts.find { |part| part["Content-Type"].value == "text/html" }.body.to_s)
end

shared_examples "a health notification email" do
it "has the correct headers" do
expect(mail.subject).to eq(expected_subject_text)
expect(mail.to).to eq([admin.mail])
expect(mail.from).to eq(["openproject@example.net"])
end

it "renders a link to the storage settings" do
expect(html_body).to have_link("See storage settings")
link_node = html_body.find_link("See storage settings")
expect(link_node["href"]).to match(%r{/admin/settings/storages/#{storage.id}/edit})
end

it "renders a link to manage email notifications" do
expect(html_body).to have_link("Storage email notification settings")
link_node = html_body.find_link("Storage email notification settings")
expect(link_node["href"]).to match(%r{/admin/settings/storages/#{storage.id}/edit})
end
end

describe "#notify_unhealthy" do
it_behaves_like "a health notification email" do
let(:storage) { build_stubbed(:nextcloud_storage, :as_unhealthy) }
let(:expected_subject_text) { "Storage \"#{storage.name}\" is unhealthy!" }

subject(:mail) { described_class.notify_unhealthy(admin, storage) }
end
end

describe "#notify_healthy" do
it_behaves_like "a health notification email" do
let(:expected_subject_text) { "Storage \"#{storage.name}\" is now healthy!" }
let(:reason) { "thou_shall_not_pass_error" }
let(:storage) { build_stubbed(:one_drive_storage, :as_healthy) }

subject(:mail) { described_class.notify_healthy(admin, storage, reason) }
end
end
end
49 changes: 49 additions & 0 deletions spec/mailers/previews/storages/storages_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 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.
#++

module Storages
class StoragesMailerPreview < ActionMailer::Preview
# Preview emails at http://localhost:3000/rails/mailers/storages/storages_mailer
def notify_unhealthy
admin_user = FactoryBot.build_stubbed(:admin)
storage = FactoryBot.build_stubbed(:nextcloud_storage)

::Storages::StoragesMailer.notify_unhealthy(admin_user, storage)
end

def notify_healthy
admin_user = FactoryBot.build_stubbed(:admin)
storage = FactoryBot.build_stubbed(:one_drive_storage)
reason = "thou_shall_not_pass_error"

::Storages::StoragesMailer.notify_healthy(admin_user, storage, reason)
end
end
end

0 comments on commit 7810d86

Please sign in to comment.