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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions qiita_core/configuration_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class ConfigurationManager(object):
The script used to start the plugins
plugin_dir : str
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
sysadmin_email : str
The email address, Qiita sends internal notifications to a sys admin

Raises
------
Expand Down Expand Up @@ -234,6 +238,32 @@ def _get_main(self, config):
self.key_file = join(install_dir, 'qiita_core', 'support_files',
'ci_server.key')

self.help_email = config.get('main', 'HELP_EMAIL')
if not self.help_email:
raise ValueError(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe change this to something like:

if self.help_email == '[email protected]':
    warnings.warn("Using the github fake email for HELP_EMAIL, are you sure this is OK?")

"You did not specify the HELP_EMAIL address in the main "
"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 == '[email protected]') 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:
raise ValueError(
"You did not specify the SYSADMIN_EMAIL address in the main "
"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 == '[email protected]') 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"""
self.job_scheduler_owner = config.get(
Expand Down
6 changes: 6 additions & 0 deletions qiita_core/support_files/config_test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ COOKIE_SECRET = SECRET
# The value used to secure JWTs for delegated permission artifact download.
JWT_SECRET = SUPER_SECRET

# Address a user should write to when asking for help
HELP_EMAIL = [email protected]

# The email address, Qiita sends internal notifications to a sys admin
SYSADMIN_EMAIL = [email protected]

# ----------------------------- SMTP settings -----------------------------
[smtp]
# The hostname to connect to
Expand Down
39 changes: 38 additions & 1 deletion 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 @@ -180,6 +182,35 @@ def test_get_main(self):

self.assertEqual(obs.qiita_env, "")

def test_help_email(self):
obs = ConfigurationManager()

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, '[email protected]')
self.assertEqual(obs.sysadmin_email, '[email protected]')

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 [email protected]
self.conf.set('main', 'HELP_EMAIL', '')
with self.assertRaises(ValueError):
obs._get_main(self.conf)

# test if it falls back to [email protected]
self.conf.set('main', 'SYSADMIN_EMAIL', '')
with self.assertRaises(ValueError):
obs._get_main(self.conf)

def test_get_job_scheduler(self):
obs = ConfigurationManager()

Expand Down Expand Up @@ -274,6 +305,12 @@ def test_get_portal(self):
# The value used to secure JWTs for delegated permission artifact download.
JWT_SECRET = SUPER_SECRET

# Address a user should write to when asking for help
HELP_EMAIL = [email protected]

# The email address, Qiita sends internal notifications to a sys admin
SYSADMIN_EMAIL = [email protected]

# ----------------------------- SMTP settings -----------------------------
[smtp]
# The hostname to connect to
Expand Down
4 changes: 2 additions & 2 deletions qiita_db/processing_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def resource_allocation_info(self):
samples, columns, input_size = self.shape
parts = []
error_msg = ('Obvious incorrect allocation. Please '
'contact [email protected]')
'contact %s' % qiita_config.help_email)
for part in allocation.split('--'):
param = ''
if part.startswith('time '):
Expand Down Expand Up @@ -902,7 +902,7 @@ def _set_status(self, value, error_msg=None):
if self.user.level in {'admin', 'wet-lab admin'}:
if value == 'error':
qdb.util.send_email(
'[email protected]', msg['subject'],
qiita_config.sysadmin_email, msg['subject'],
msg['message'])

sql = """UPDATE qiita.processing_job
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/handlers/artifact_handlers/base_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def artifact_patch_request(user, artifact_id, req_op, req_path, req_value=None,

sid = artifact.study.id
if artifact.visibility == 'awaiting_approval':
email_to = '[email protected]'
email_to = qiita_config.help_email
subject = ('QIITA: Artifact %s awaiting_approval. Study %d, '
'Prep %d' % (artifact_id, sid,
artifact.prep_templates[0].id))
Expand Down
12 changes: 7 additions & 5 deletions qiita_pet/handlers/auth_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def post(self):
url_escape(username), url))
except Exception:
msg = ("Unable to send verification email. Please contact the "
"qiita developers at <a href='mailto:qiita.help"
"@gmail.com'>[email protected]</a>")
"qiita developers at <a href='mailto:%s'>%s</a>") % (
qiita_config.help_email, qiita_config.help_email)
self.redirect(u"%s/?level=danger&message=%s"
% (qiita_config.portal_dir, url_escape(msg)))
return
Expand All @@ -75,8 +75,9 @@ def post(self):
"<p>If you don't receive your activation email within a "
"couple of minutes, check your spam folder. If you still "
"don't see it, send us an email at <a "
"href=\"mailto:[email protected]\">[email protected]"
"</a>.</p>")
"href=\"mailto:%s\">%s"
"</a>.</p>") % (qiita_config.help_email,
qiita_config.help_email)
self.redirect(u"%s/?level=success&message=%s" %
(qiita_config.portal_dir, url_escape(msg)))
else:
Expand Down Expand Up @@ -135,7 +136,8 @@ def post(self):
"the verify link. You may need to check your spam "
"folder to find the email.<br/>If a verification email"
" has not arrived in 15 minutes, please email <a href='"
"mailto:[email protected]'>[email protected]</a>")
"mailto:%s'>%s</a>") % (qiita_config.help_email,
qiita_config.help_email)
except QiitaDBUnknownIDError:
msg = "Unknown user"
except RuntimeError:
Expand Down
26 changes: 13 additions & 13 deletions qiita_pet/handlers/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,12 @@ def get(self):
public_raw_download = study.public_raw_download
if study.status != 'public':
raise HTTPError(404, reason='Study is not public. If this '
'is a mistake contact: '
'[email protected]')
'is a mistake contact: %s' %
qiita_config.help_email)
elif data == 'raw' and not public_raw_download:
raise HTTPError(422, reason='No raw data access. If this '
'is a mistake contact: '
'[email protected]')
'is a mistake contact: %s'
% qiita_config.help_email)
else:
# raw data
artifacts = [a for a in study.artifacts(dtype=data_type)
Expand All @@ -466,8 +466,8 @@ def get(self):

if not to_download:
raise HTTPError(422, reason='Nothing to download. If '
'this is a mistake contact: '
'[email protected]')
'this is a mistake contact: %s'
% qiita_config.help_email)
else:
self._write_nginx_file_list(to_download)

Expand Down Expand Up @@ -496,18 +496,18 @@ def get(self):
else:
if artifact.visibility != 'public':
raise HTTPError(404, reason='Artifact is not public. If '
'this is a mistake contact: '
'[email protected]')
'this is a mistake contact: %s'
% qiita_config.help_email)
elif artifact.has_human:
raise HTTPError(404, reason='Artifact has possible human '
'sequences. If this is a mistake contact: '
'[email protected]')
'%s' % qiita_config.help_email)
else:
to_download = self._list_artifact_files_nginx(artifact)
if not to_download:
raise HTTPError(422, reason='Nothing to download. If '
'this is a mistake contact: '
'[email protected]')
'this is a mistake contact: %s'
% qiita_config.help_email)
else:
self._write_nginx_file_list(to_download)

Expand Down Expand Up @@ -600,8 +600,8 @@ def get(self, jti):
to_download = self._list_artifact_files_nginx(artifact)
if not to_download:
raise HTTPError(422, reason='Nothing to download. If '
'this is a mistake contact: '
'[email protected]')
'this is a mistake contact: %s' %
qiita_config.help_email)
else:
self._write_nginx_file_list(to_download)

Expand Down
6 changes: 3 additions & 3 deletions qiita_pet/handlers/study_handlers/sample_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from tornado.web import authenticated, HTTPError

from qiita_core.qiita_settings import r_client
from qiita_core.qiita_settings import r_client, qiita_config
from qiita_pet.handlers.util import to_int
from qiita_pet.handlers.base_handlers import BaseHandler
from qiita_db.util import get_files_from_uploads_folders
Expand Down Expand Up @@ -214,8 +214,8 @@ def sample_template_handler_patch_request(user, req_op, req_path,
# the system
filepath = req_value
if not exists(filepath):
reason = ('Upload file not found (%s), please report to '
'[email protected]' % filepath)
reason = ('Upload file not found (%s), please report to %s'
% (filepath, qiita_config.help_email))
raise HTTPError(404, reason=reason)
else:
# Check if the file exists
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/admin_processing_job.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
$inp.attr('type', 'file');
}
else {
bootstrapAlert("Error: Parameter type (" + p_type + ") not recognized. Please, take a screenshot and <a href='mailto:[email protected]'>contact us</a>", "danger");
bootstrapAlert("Error: Parameter type (" + p_type + ") not recognized. Please, take a screenshot and <a href='mailto:{% raw qiita_config.portal_dir %}'>contact us</a>", "danger");
}
}

Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h1 style="text-align:center">ERROR: CODE {{status_code}}!</h1>
<h2 style="text-align:center">{% raw escape(error) %}</h2>
<p style="text-align:center">The error has been logged and will be looked at.</p>
<p style="text-align:center">Need help? Send us an <a href="mailto:[email protected]">email</a>.</p>
<p style="text-align:center">Need help? Send us an <a href="mailto:{% raw qiita_config.help_email %}">email</a>.</p>
{% if is_admin %}
<p style="text-align:center">Go to the <a href="{% raw qiita_config.portal_dir %}/admin/error/">error page</a> to view the logs</p>
{% end %}
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/list_analyses.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
message.append(' '+data[level]);
// prepend the "Need help" message
if (level == 'warning' || level == 'danger'){
message.append('<p style="text-align:center">Need help? Send us an <a href="mailto:[email protected]">email</a>.</p>');
message.append('<p style="text-align:center">Need help? Send us an <a href="mailto:{% raw qiita_config.portal_dir %}">email</a>.</p>');
}
analyses_all_messages.prepend(message);
}
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/redbiom.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
.fail(function(response, status, error) {
var text = 'The query response is larger than is currently allowed, please try another. <a href="https://github.com/biocore/qiita/issues/2312" target="_blank">Track progress on this issue.</a>';
if (response.status != 504) {
text = 'Status code: "' + response.status + '" - ' + error + '.<br/>Please send a screenshot to <a href="[email protected]">[email protected]</a>.';
text = 'Status code: "' + response.status + '" - ' + error + '.<br/>Please send a screenshot to <a href="mailto:{% raw qiita_config.portal_dir %}">{% raw qiita_config.portal_dir %}</a>.';
}
redbiom_info.html(
`<div class="alert alert-danger alert-dismissible" role="alert">
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/sitebase.html
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ <h4 class="modal-title">File really big.</h4>
<div id="footer" style="font-size: 12px; text-align: center; z-index: 1000;">
Thank you for using Qiita. <a target="_blank" href="{% raw qiita_config.portal_dir %}/static/doc/html/faq.html#how-to-cite-qiita">Citing Qiita?</a>.
<br/>
Questions? <a href="mailto:[email protected]">[email protected]</a>; don't forget to add your study or analysis id.
Questions? <a href="mailto:{% raw qiita_config.help_email %}">{% raw qiita_config.help_email %}</a>; don't forget to add your study or analysis id.
<br/>
Read our <a href="{% raw qiita_config.portal_dir %}/iframe/?iframe=qiita-terms">terms and conditions</a>.
</div>
Expand Down
2 changes: 1 addition & 1 deletion qiita_pet/templates/study_ajax/base_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<input id="studyTags">
<small>
New tags are linked to the user that created them.
Report <a href="mailto:[email protected]">abuse</a>.
Report <a href="mailto:{% raw qiita_config.help_email %}">abuse</a>.
</small>
<br/>
<button type="submit" class="btn btn-default" onclick="tags_patch(); return false;">Save tags</button>
Expand Down
10 changes: 5 additions & 5 deletions qiita_pet/test/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,15 @@ def test_download(self):
response = self.get('/public_download/?data=raw&study_id=1')
self.assertEqual(response.code, 404)
self.assertEqual(response.reason, 'Study is not public. '
'If this is a mistake contact: qiita.help@gmail.com')
'If this is a mistake contact: foo@bar.com')

# 7 is an uploaded biom, which should now be available but as it's a
# biom, only the prep info file will be retrieved
Artifact(7).visibility = 'public'
response = self.get('/public_download/?data=raw&study_id=1')
self.assertEqual(response.code, 422)
self.assertEqual(response.reason, 'No raw data access. '
'If this is a mistake contact: qiita.help@gmail.com')
'If this is a mistake contact: foo@bar.com')

# check success
response = self.get('/public_download/?data=biom&study_id=1')
Expand Down Expand Up @@ -426,12 +426,12 @@ def test_download(self):
'/public_download/?data=raw&study_id=1&data_type=Genomics')
self.assertEqual(response.code, 422)
self.assertEqual(response.reason, 'Nothing to download. If this is a '
'mistake contact: qiita.help@gmail.com')
'mistake contact: foo@bar.com')
response = self.get(
'/public_download/?data=biom&study_id=1&data_type=Genomics')
self.assertEqual(response.code, 422)
self.assertEqual(response.reason, 'Nothing to download. If this is a '
'mistake contact: qiita.help@gmail.com')
'mistake contact: foo@bar.com')

# check success
Artifact(5).visibility = 'public'
Expand Down Expand Up @@ -521,7 +521,7 @@ def test_download(self):
response = self.get('/public_artifact_download/?artifact_id=3')
self.assertEqual(response.code, 404)
self.assertEqual(response.reason, 'Artifact is not public. If this is '
'a mistake contact: qiita.help@gmail.com')
'a mistake contact: foo@bar.com')

# check success
Artifact(5).visibility = 'public'
Expand Down
6 changes: 3 additions & 3 deletions qiita_ware/test/test_private_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def _set_allocation(memory):
self.assertEqual(job.resource_allocation_info, 'Not valid')
self.assertEqual(job.status, 'error')
self.assertEqual(job.log.msg, 'Obvious incorrect allocation. Please '
'contact qiita.help@gmail.com')
'contact foo@bar.com')

# now let's test something that will cause not a number input_size*N
job = self._create_job('build_analysis_files', {
Expand All @@ -412,7 +412,7 @@ def _set_allocation(memory):
self.assertEqual(job.resource_allocation_info, 'Not valid')
self.assertEqual(job.status, 'error')
self.assertEqual(job.log.msg, 'Obvious incorrect allocation. Please '
'contact qiita.help@gmail.com')
'contact foo@bar.com')

# now let's test something that will return a negative number -samples
job = self._create_job('build_analysis_files', {
Expand All @@ -421,7 +421,7 @@ def _set_allocation(memory):
self.assertEqual(job.resource_allocation_info, 'Not valid')
self.assertEqual(job.status, 'error')
self.assertEqual(job.log.msg, 'Obvious incorrect allocation. Please '
'contact qiita.help@gmail.com')
'contact foo@bar.com')

# now let's test a full build_analysis_files job
job = self._create_job('build_analysis_files', {
Expand Down
Loading