Removing Settings::General.email_addresses (#13958)

* Replaced Settings::General.email_addresses with Forem.email

* Removed Settings::General.email_addresses remainders

* Fixed schema.rb

* Remove Settings::General.email_addresses record

* Fixed label for default email
This commit is contained in:
Anna Buianova 2021-06-11 12:34:34 +03:00 committed by GitHub
parent a2677cc0a9
commit 26592a3a9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 61 additions and 105 deletions

View file

@ -3,7 +3,6 @@ module Admin
class GeneralSettingsController < Admin::Settings::BaseController
SPECIAL_PARAMS_TO_ADD = %w[
credit_prices_in_cents
email_addresses
meta_keywords
].freeze
@ -27,13 +26,9 @@ module Admin
end
def settings_params
has_emails = params.dig(:settings_general, :email_addresses).present?
params[:settings_general][:email_addresses][:default] = ApplicationConfig["DEFAULT_EMAIL"] if has_emails
params.require(:settings_general)&.permit(
settings_keys.map(&:to_sym),
social_media_handles: ::Settings::General.social_media_handles.keys,
email_addresses: ::Settings::General.email_addresses.keys,
meta_keywords: ::Settings::General.meta_keywords.keys,
credit_prices_in_cents: ::Settings::General.credit_prices_in_cents.keys,
)

View file

@ -73,7 +73,7 @@ module Admin
user = User.find(params[:id])
send_to_admin = params[:send_to_admin].to_boolean
if send_to_admin
email = ::Settings::General.email_addresses[:default]
email = ::ForemInstance.email
receiver = "admin"
else
email = user.email

View file

@ -24,7 +24,7 @@ class ApiSecretsController < ApplicationController
flash[:notice] = "Your API Key has been revoked."
else
flash[:error] =
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:default]}"
"An error occurred. Please try again or send an email to: #{ForemInstance.email}"
end
redirect_back(fallback_location: root_path)

View file

@ -6,7 +6,7 @@ class ConfirmationsController < Devise::ConfirmationsController
self.resource = resource_class.send_confirmation_instructions(resource_params)
resource.errors.clear # Don't leak user information, like paranoid mode.
message = format(FLASH_MESSAGE, email: Settings::General.email_addresses[:default])
message = format(FLASH_MESSAGE, email: ForemInstance.email)
flash.now[:global_notice] = message
render :new
end

View file

@ -134,7 +134,7 @@ class UsersController < ApplicationController
def remove_identity
set_current_tab("account")
error_message = format(REMOVE_IDENTITY_ERROR, email: Settings::General.email_addresses[:default])
error_message = format(REMOVE_IDENTITY_ERROR, email: ForemInstance.email)
unless Authentication::Providers.enabled?(params[:provider])
flash[:error] = error_message
redirect_to user_settings_path(@tab)

View file

@ -19,7 +19,7 @@ module Authentication
def message
format(PREVIOUSLY_SUSPENDED_MESSAGE,
community_name: Settings::Community.community_name,
community_email: Settings::General.email_addresses[:default])
community_email: ForemInstance.email)
end
end
end

View file

@ -195,7 +195,7 @@ module ApplicationHelper
end
def email_link(text: nil, additional_info: nil)
email = Settings::General.email_addresses[:default]
email = ForemInstance.email
mail_to email, text || email, additional_info
end

View file

@ -23,10 +23,6 @@ module Constants
placeholder: ""
}
},
email_addresses: {
description: "Email address",
placeholder: ""
},
favicon_url: {
description: "Used as the site favicon",
placeholder: IMAGE_PLACEHOLDER

View file

@ -12,7 +12,7 @@ class ApplicationMailer < ActionMailer::Base
default(
from: -> { email_from },
template_path: ->(mailer) { "mailers/#{mailer.class.name.underscore}" },
reply_to: -> { Settings::General.email_addresses[:default] },
reply_to: -> { ForemInstance.email },
)
def email_from(topic = "")
@ -22,7 +22,7 @@ class ApplicationMailer < ActionMailer::Base
Settings::Community.community_name
end
"#{community_name} <#{Settings::General.email_addresses[:default]}>"
"#{community_name} <#{ForemInstance.email}>"
end
def generate_unsubscribe_token(id, email_type)

View file

@ -3,7 +3,7 @@ class DeviseMailer < Devise::Mailer
def use_settings_general_values
Devise.mailer_sender =
"#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
"#{Settings::Community.community_name} <#{ForemInstance.email}>"
ActionMailer::Base.default_url_options[:host] = Settings::General.app_domain
end
end

View file

@ -1,6 +1,6 @@
class VerificationMailer < ApplicationMailer
default from: lambda {
"#{Settings::Community.community_name} Email Verification <#{Settings::General.email_addresses[:default]}>"
"#{Settings::Community.community_name} Email Verification <#{ForemInstance.email}>"
}
def account_ownership_verification_email

View file

@ -9,6 +9,10 @@ class ForemInstance
@latest_commit_id ||= ApplicationConfig["FOREM_BUILD_SHA"].presence || ENV["HEROKU_SLUG_COMMIT"].presence
end
def self.email
ApplicationConfig["DEFAULT_EMAIL"]
end
# Return true if we are operating on a local installation, false otherwise
def self.local?
Settings::General.app_domain.include?("localhost")

View file

@ -27,15 +27,6 @@ module Settings
field :health_check_token, type: :string
field :video_encoder_key, type: :string
# Emails
field :email_addresses, type: :hash, default: {
default: ApplicationConfig["DEFAULT_EMAIL"],
contact: ApplicationConfig["DEFAULT_EMAIL"],
business: ApplicationConfig["DEFAULT_EMAIL"],
privacy: ApplicationConfig["DEFAULT_EMAIL"],
members: ApplicationConfig["DEFAULT_EMAIL"]
}
# Email digest frequency
field :periodic_email_digest, type: :integer, default: 2

View file

@ -9,7 +9,7 @@ module ErrorMessages
def self.call(error_message)
return error_message unless error_message.match?(FRONTMATTER_ERROR)
format(REPLACEMENT_ERROR, Settings::General.email_addresses[:default])
format(REPLACEMENT_ERROR, ForemInstance.email)
end
end
end

View file

@ -584,30 +584,28 @@
</div>
<% end %>
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path) do |f| %>
<div class="card mt-3">
<%= render partial: "admin/shared/card_header",
locals: {
header: "Emails",
state: "collapse",
target: "emailBodyContainer",
expanded: false
} %>
<div class="card mt-3">
<%= render partial: "admin/shared/card_header",
locals: {
header: "Emails",
state: "collapse",
target: "emailBodyContainer",
expanded: false
} %>
<div id="emailBodyContainer" class="card-body collapse hide" aria-labelledby="emailBodyContainer">
<fieldset class="grid gap-4">
<div class="crayons-field">
<label for="settings_general_email_addresses_default" class="crayons-field__label">
<label for="forem_instance_email" class="crayons-field__label">
Default
</label>
<div class="crayons-field__description">
Default (set via <span class="ff-monospace">default_email</span> environment variable)
</div>
<input type="text" value="<%= ApplicationConfig["DEFAULT_EMAIL"] %>" class="form-control" readonly>
<input id="forem_instance_email" type="text" value="<%= ForemInstance.email %>" class="form-control" readonly>
</div>
</fieldset>
</div>
</div>
<% end %>
</div>
<%= form_for(Settings::General.new, url: admin_settings_general_settings_path, html: { data: { testid: "emailDigestSectionForm" } }) do |f| %>
<div class="card mt-3">

View file

@ -12,7 +12,7 @@
</p>
<p>
Exporting the data to your admin account will send it to your contact
admin email (<%= Settings::General.email_addresses[:default] %>),
admin email (<%= ForemInstance.email %>),
and exporting to the user will send it to their email (<%= @user.email %>).
</p>
<div style="display: flex;">

View file

@ -9,7 +9,7 @@
Whoops! Did you get stuck trying to open the mobile app?
</p>
<p class="mt-5">
Make sure it's installed and try again. If the problem persists contact <a href="mailto:<%= Settings::General.email_addresses[:default] %>"><%= Settings::General.email_addresses[:contact] %></a>
Make sure it's installed and try again. If the problem persists contact <a href="mailto:<%= ForemInstance.email %>"><%= ForemInstance.email %></a>
</p>
</div>

View file

@ -75,7 +75,7 @@
<span class="timezone">America/New_York</span>
<span class="title"><%= event.title %></span>
<span class="organizer"><%= community_name %></span>
<span class="organizer_email"><%= Settings::General.email_addresses[:default] %></span>
<span class="organizer_email"><%= ForemInstance.email %></span>
<span class="calname">dev-event</span>
<span class="location"><%= event.location_url %></span>
<span class="alarm_reminder">15</span>

View file

@ -1,6 +1,6 @@
Hi <%= @name %>, your account has been successfully deleted.
Contact us at <%= Settings::General.email_addresses[:default] %> if there is anything more we can help with.
Contact us at <%= ForemInstance.email %> if there is anything more we can help with.
Thanks,
The <%= community_name %> Team

View file

@ -20,7 +20,7 @@ When in doubt about how to exercise your new privileges, please ask! If these Co
Tag moderation is something we're continuously iterating on, so you can expect adjustments and expanding features over time as we receive feedback.
We regularly send out a biweekly Mod Newsletter to keep mods up to date on these changes, so look out for it!
Of course, don't hesitate to reach out to us at any moment if you have any feedback — feel free to write to <%= Settings::General.email_addresses[:default] %> and share your thoughts.
Of course, don't hesitate to reach out to us at any moment if you have any feedback — feel free to write to <%= ForemInstance.email %> and share your thoughts.
Thanks so much for volunteering your time to benefit <%= community_name %>. We sincerely appreciate your help!

View file

@ -14,7 +14,7 @@ You may occasionally receive notifications about optional moderation actions; pl
For details on all available features and how to access them, visit our <%= community_name %> Trusted User Guide: <%= app_url("/community-moderation") %>
If you have any questions or feedback for us, please write to <%= Settings::General.email_addresses[:default] %> and share your thoughts.
If you have any questions or feedback for us, please write to <%= ForemInstance.email %> and share your thoughts.
Thanks for being such an awesome member of the community!

View file

@ -79,7 +79,7 @@
Have feedback to improve your Mod experience?
</span>
<span>
Please email <%= Settings::General.email_addresses[:default] %>!
Please email <%= ForemInstance.email %>!
</span>
</div>
</aside>

View file

@ -3,6 +3,6 @@
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName><%= helper.community_name %> Search</ShortName>
<Description>Find posts from <%= helper.community_name %>.</Description>
<Contact><%= Settings::General.email_addresses[:default] %></Contact>
<Contact><%= ForemInstance.email %></Contact>
<Url type="text/html" template="<%= URL.url("search") %>?q={searchTerms}" />
</OpenSearchDescription>

View file

@ -231,7 +231,7 @@
<% end %>
<p>
Questions? Email us at
<a href="<%= Settings::General.email_addresses[:default] %>"><%= Settings::General.email_addresses[:default] %></a>
<a href="<%= ForemInstance.email %>"><%= ForemInstance.email %></a>
for help.
</p>
</div>

View file

@ -1,9 +0,0 @@
module DataUpdateScripts
class RemoveUnusedSiteConfigEmails
def run
Settings::General.email_addresses = {
default: ApplicationConfig["DEFAULT_EMAIL"]
}
end
end
end

View file

@ -0,0 +1,8 @@
module DataUpdateScripts
class RemoveEmailAddressesScripts
def run
DataUpdateScript.delete_by(file_name: "20210509105151_remove_unused_site_config_emails")
Settings::General.delete_by(var: :email_addresses)
end
end
end

View file

@ -161,11 +161,7 @@ RSpec.describe ApplicationHelper, type: :helper do
let(:default_email) { "hi@dev.to" }
before do
allow(Settings::General).to receive(:email_addresses).and_return(
{
default: default_email
},
)
allow(ForemInstance).to receive(:email).and_return(default_email)
end
it "returns an 'a' tag" do

View file

@ -1,23 +0,0 @@
require "rails_helper"
require Rails.root.join(
"lib/data_update_scripts/20210509105151_remove_unused_site_config_emails.rb",
)
describe DataUpdateScripts::RemoveUnusedSiteConfigEmails do
let(:contact_email) { "contact@dev.to" }
before do
Settings::General.email_addresses = {
default: ApplicationConfig["DEFAULT_EMAIL"],
contact: "contact@dev.to",
business: "business@dev.to",
privacy: "privacy@dev.to",
members: "members@dev.to"
}
end
it "removes the unused emails" do
described_class.new.run
expect(Settings::General.email_addresses.symbolize_keys).to eq(default: ApplicationConfig["DEFAULT_EMAIL"])
end
end

View file

@ -11,7 +11,7 @@ RSpec.describe DeviseMailer, type: :mailer do
end
it "renders sender" do
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expected_from = "#{Settings::Community.community_name} <#{ForemInstance.email}>"
expect(email["from"].value).to eq(expected_from)
end

View file

@ -14,8 +14,8 @@ RSpec.describe DigestMailer, type: :mailer do
expect(email.subject).not_to be_nil
expect(email.to).to eq([user.email])
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} Digest <#{Settings::General.email_addresses[:default]}>"
expect(email.from).to eq([ForemInstance.email])
expected_from = "#{Settings::Community.community_name} Digest <#{ForemInstance.email}>"
expect(email["from"].value).to eq(expected_from)
end
end

View file

@ -432,17 +432,17 @@ RSpec.describe NotifyMailer, type: :mailer do
end
it "renders proper sender" do
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expected_from = "#{Settings::Community.community_name} <#{ForemInstance.email}>"
expect(moderator_email.from).to eq([Settings::General.email_addresses[:default]])
expect(moderator_email.from).to eq([ForemInstance.email])
expect(moderator_email["from"].value).to eq(expected_from)
expect(member_email.from).to eq([Settings::General.email_addresses[:default]])
expect(member_email.from).to eq([ForemInstance.email])
expect(member_email["from"].value).to eq(expected_from)
end
it "renders proper reply_to" do
expect(moderator_email["reply_to"].value).to eq(Settings::General.email_addresses[:default])
expect(moderator_email["reply_to"].value).to eq(ForemInstance.email)
end
it "renders proper receiver" do

View file

@ -1,11 +1,11 @@
RSpec.shared_examples "#renders_proper_email_headers" do
it "renders proper sender" do
expect(email.from).to eq([Settings::General.email_addresses[:default]])
expected_from = "#{Settings::Community.community_name} <#{Settings::General.email_addresses[:default]}>"
expect(email.from).to eq([ForemInstance.email])
expected_from = "#{Settings::Community.community_name} <#{ForemInstance.email}>"
expect(email["from"].value).to eq(expected_from)
end
it "renders proper reply_to" do
expect(email["reply_to"].value).to eq(Settings::General.email_addresses[:default])
expect(email["reply_to"].value).to eq(ForemInstance.email)
end
end

View file

@ -9,8 +9,8 @@ RSpec.describe VerificationMailer, type: :mailer do
expect(email.subject).not_to be_nil
expect(email.to).to eq([user.email])
expect(email.from).to eq([Settings::General.email_addresses[:default]])
from = "#{Settings::Community.community_name} Email Verification <#{Settings::General.email_addresses[:default]}>"
expect(email.from).to eq([ForemInstance.email])
from = "#{Settings::Community.community_name} Email Verification <#{ForemInstance.email}>"
expect(email["from"].value).to eq(from)
end
end

View file

@ -289,7 +289,7 @@ RSpec.describe "/admin/customization/config", type: :request do
confirmation: confirmation_message
}
expect(Settings::General.email_addresses[:default]).not_to eq("random@example.com")
expect(ForemInstance.email).not_to eq("random@example.com")
end
end

View file

@ -401,7 +401,7 @@ RSpec.describe "UserSettings", type: :request do
expect(response).to redirect_to("/settings/account")
error =
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:default]}"
"An error occurred. Please try again or send an email to: #{ForemInstance.email}"
expect(flash[:error]).to eq(error)
end
@ -444,7 +444,7 @@ RSpec.describe "UserSettings", type: :request do
delete users_remove_identity_path, params: { provider: provider }
error =
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:default]}"
"An error occurred. Please try again or send an email to: #{ForemInstance.email}"
expect(flash[:error]).to eq(error)
end

View file

@ -94,7 +94,7 @@ RSpec.describe Exporter::Service, type: :service do
context "when emailing an admin" do
it "delivers one email to the contact admin email" do
admin_email = "admin@example.com"
allow(Settings::General).to receive(:email_addresses).and_return({ contact: admin_email })
allow(ForemInstance).to receive(:email).and_return(admin_email)
service = valid_instance(article.user)
service.export(admin_email)
expect(ActionMailer::Base.deliveries.last.to.first).to eq admin_email

View file

@ -8,7 +8,7 @@ RSpec.describe "/confirm-email", type: :system do
expect(page).to have_current_path(user_confirmation_path)
expected_message = format(ConfirmationsController::FLASH_MESSAGE,
email: Settings::General.email_addresses[:default])
email: ForemInstance.email)
expect(page).to have_content(expected_message)
end
end