mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
add validator for the 'reply_by_email_enabled' site setting
This commit is contained in:
parent
13983c2f80
commit
8944d62aa6
4 changed files with 59 additions and 1 deletions
|
@ -1263,6 +1263,8 @@ en:
|
|||
pop3_polling_username_is_empty: "You must set a 'pop3 polling username' before enabling POP3 polling."
|
||||
pop3_polling_password_is_empty: "You must set a 'pop3 polling password' before enabling POP3 polling."
|
||||
pop3_polling_authentication_failed: "POP3 authentication failed. Please verify your pop3 credentials."
|
||||
reply_by_email_address_is_empty: "You must set a 'reply by email address' before enabling reply by email."
|
||||
pop3_polling_disabled: "You must first enabled POP3 polling before enabling reply by email."
|
||||
|
||||
notification_types:
|
||||
group_mentioned: "%{group_name} was mentioned in %{link}"
|
||||
|
|
|
@ -506,7 +506,9 @@ email:
|
|||
client: true
|
||||
email_custom_headers: 'Auto-Submitted: auto-generated'
|
||||
email_subject: '[%{site_name}] %{optional_pm}%{optional_cat}%{topic_title}'
|
||||
reply_by_email_enabled: false
|
||||
reply_by_email_enabled:
|
||||
default: false
|
||||
validator: "ReplyByEmailEnabledValidator"
|
||||
reply_by_email_address:
|
||||
default: ''
|
||||
validator: "ReplyByEmailAddressValidator"
|
||||
|
|
23
lib/validators/reply_by_email_enabled_validator.rb
Normal file
23
lib/validators/reply_by_email_enabled_validator.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
class ReplyByEmailEnabledValidator
|
||||
|
||||
def initialize(opts={})
|
||||
@opts = opts
|
||||
end
|
||||
|
||||
def valid_value?(val)
|
||||
# only validate when enabling reply by email
|
||||
return true if val == "f"
|
||||
# ensure reply_by_email_address is configured && polling is working
|
||||
SiteSetting.reply_by_email_address.present? &&
|
||||
SiteSetting.pop3_polling_enabled?
|
||||
end
|
||||
|
||||
def error_message
|
||||
if SiteSetting.reply_by_email_address.blank?
|
||||
I18n.t("site_settings.errors.reply_by_email_address_is_empty")
|
||||
else
|
||||
I18n.t("site_settings.errors.pop3_polling_disabled")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,31 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe ReplyByEmailEnabledValidator do
|
||||
|
||||
describe '#valid_value?' do
|
||||
subject(:validator) { described_class.new }
|
||||
|
||||
it "only validates when enabling the setting" do
|
||||
expect(validator.valid_value?("f")).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false if reply_by_email_address is missing" do
|
||||
SiteSetting.expects(:reply_by_email_address).returns("")
|
||||
expect(validator.valid_value?("t")).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false if POP3 polling is disabled" do
|
||||
SiteSetting.expects(:reply_by_email_address).returns("foo.%{reply_key}+42@bar.com")
|
||||
SiteSetting.expects(:pop3_polling_enabled).returns(false)
|
||||
expect(validator.valid_value?("t")).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true when POP3 polling is enabled and the reply_by_email_address is configured" do
|
||||
SiteSetting.expects(:reply_by_email_address).returns("foo.%{reply_key}+42@bar.com")
|
||||
SiteSetting.expects(:pop3_polling_enabled).returns(true)
|
||||
expect(validator.valid_value?("t")).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue