Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make help email address configurable instead of hard coding #3384

Merged
merged 8 commits into from
Mar 21, 2024
12 changes: 10 additions & 2 deletions qiita_core/configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ class ConfigurationManager(object):
The path to the directory containing the plugin configuration files
help_email : str
The email address a user should write to when asking for help
Defaults to qiita.help@gmail.com
sysadmin_email : str
The email address, Qiita sends internal notifications to a sys admin
Defaults to jdereus@health.ucsd.edu

Raises
------
Expand Down Expand Up @@ -247,6 +245,11 @@ def _get_main(self, config):
"section of Qiita's config file. This address is essential "
"for users to ask for help as it is displayed at various "
"location throughout Qiita's web pages.")
if (self.help_email == 'foo@bar.com') and \
(self.test_environment is False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Good idea!

warnings.warn(
"Using the github fake email for HELP_EMAIL, "
"are you sure this is OK?")

self.sysadmin_email = config.get('main', 'SYSADMIN_EMAIL')
if not self.sysadmin_email:
Expand All @@ -255,6 +258,11 @@ def _get_main(self, config):
"section of Qiita's config file. Serious issues will "
"automatically be reported to a sys admin, an according "
"address is therefore required!")
if (self.sysadmin_email == 'jeff@bar.com') and \
(self.test_environment is False):
warnings.warn(
"Using the github fake email for SYSADMIN_EMAIL, "
"are you sure this is OK?")

def _get_job_scheduler(self, config):
"""Get the configuration of the job_scheduler section"""
Expand Down
4 changes: 2 additions & 2 deletions qiita_core/support_files/config_test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ COOKIE_SECRET = SECRET
JWT_SECRET = SUPER_SECRET

# Address a user should write to when asking for help
HELP_EMAIL = qiita.help@gmail.com
HELP_EMAIL = foo@bar.com

# The email address, Qiita sends internal notifications to a sys admin
SYSADMIN_EMAIL = jdereus@health.ucsd.edu
SYSADMIN_EMAIL = jeff@bar.com

# ----------------------------- SMTP settings -----------------------------
[smtp]
Expand Down
22 changes: 18 additions & 4 deletions qiita_core/tests/test_configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUp(self):

self.conf = ConfigParser()
with open(self.conf_fp, newline=None) as f:
self.conf.readfp(f)
self.conf.read_file(f)

def tearDown(self):
if self.old_conf_fp is not None:
Expand Down Expand Up @@ -132,6 +132,8 @@ def test_get_main(self):

# Warning raised if No files will be allowed to be uploaded
# Warning raised if no cookie_secret
self.conf.set('main', 'HELP_EMAIL', 'ignore@me')
self.conf.set('main', 'SYSADMIN_EMAIL', 'ignore@me')
with warnings.catch_warnings(record=True) as warns:
obs._get_main(self.conf)

Expand Down Expand Up @@ -183,9 +185,21 @@ def test_get_main(self):
def test_help_email(self):
obs = ConfigurationManager()

obs._get_main(self.conf)
self.assertEqual(obs.help_email, 'foo@bar.com')
self.assertEqual(obs.sysadmin_email, 'jeff@bar.com')
with warnings.catch_warnings(record=True) as warns:
# warning get only issued when in non test environment
self.conf.set('main', 'TEST_ENVIRONMENT', 'FALSE')

obs._get_main(self.conf)
self.assertEqual(obs.help_email, 'foo@bar.com')
self.assertEqual(obs.sysadmin_email, 'jeff@bar.com')

obs_warns = [str(w.message) for w in warns]
exp_warns = [
'Using the github fake email for HELP_EMAIL, '
'are you sure this is OK?',
'Using the github fake email for SYSADMIN_EMAIL, '
'are you sure this is OK?']
self.assertCountEqual(obs_warns, exp_warns)

# test if it falls back to qiita.help@gmail.com
self.conf.set('main', 'HELP_EMAIL', '')
Expand Down
Loading