From 20ce7f29e048f6c9ca4a6d2915f830ee7e24823a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 16 Mar 2016 22:28:01 +0100 Subject: [PATCH] FEATURE: new 'manual_polling_enabled' site setting --- app/models/site_setting.rb | 4 ++++ config/locales/server.en.yml | 3 ++- config/site_settings.yml | 2 ++ lib/validators/reply_by_email_enabled_validator.rb | 4 ++-- .../validators/reply_by_email_enabled_validator_spec.rb | 8 ++++---- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 2a7c7e79d..266a482f8 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -105,6 +105,10 @@ class SiteSetting < ActiveRecord::Base nil end + def self.email_polling_enabled? + SiteSetting.manual_polling_enabled? || SiteSetting.pop3_polling_enabled? + end + end # == Schema Information diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index d736e9eb9..f16e0d7e9 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1158,6 +1158,7 @@ en: delete_email_logs_after_days: "Delete email logs after (N) days. 0 to keep indefinitely" + manual_polling_enabled: "Push emails using the API for email replies." pop3_polling_enabled: "Poll via POP3 for email replies." pop3_polling_ssl: "Use SSL while connecting to the POP3 server. (Recommended)" pop3_polling_period_mins: "The period in minutes between checking the POP3 account for email. NOTE: requires restart." @@ -1310,7 +1311,7 @@ en: 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." + email_polling_disabled: "You must enable either manual or POP3 polling before enabling reply by email." user_locale_not_enabled: "You must first enable 'allow user locale' before enabling this setting." notification_types: diff --git a/config/site_settings.yml b/config/site_settings.yml index fe5f85ba9..b4c4da72b 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -525,6 +525,8 @@ email: reply_by_email_address: default: '' validator: "ReplyByEmailAddressValidator" + manual_polling_enabled: + default: false pop3_polling_enabled: default: false validator: "POP3PollingEnabledSettingValidator" diff --git a/lib/validators/reply_by_email_enabled_validator.rb b/lib/validators/reply_by_email_enabled_validator.rb index 063dbe822..e7333de0f 100644 --- a/lib/validators/reply_by_email_enabled_validator.rb +++ b/lib/validators/reply_by_email_enabled_validator.rb @@ -9,14 +9,14 @@ class ReplyByEmailEnabledValidator 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? + SiteSetting.email_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") + I18n.t("site_settings.errors.email_polling_disabled") end end diff --git a/spec/components/validators/reply_by_email_enabled_validator_spec.rb b/spec/components/validators/reply_by_email_enabled_validator_spec.rb index 7596afef9..e7cd318ed 100644 --- a/spec/components/validators/reply_by_email_enabled_validator_spec.rb +++ b/spec/components/validators/reply_by_email_enabled_validator_spec.rb @@ -14,15 +14,15 @@ describe ReplyByEmailEnabledValidator do expect(validator.valid_value?("t")).to eq(false) end - it "returns false if POP3 polling is disabled" do + it "returns false if email polling is disabled" do SiteSetting.expects(:reply_by_email_address).returns("foo.%{reply_key}+42@bar.com") - SiteSetting.expects(:pop3_polling_enabled).returns(false) + SiteSetting.expects(:email_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 + it "returns true when email 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) + SiteSetting.expects(:email_polling_enabled?).returns(true) expect(validator.valid_value?("t")).to eq(true) end