Skip to content

Commit d743a81

Browse files
sjanssen2antgonza
andauthored
make help email address configurable instead of hard coding (qiita-spots#3384)
* Update CHANGELOG.md * make help email address configurable instead of hard coding * codestyle * don't default with email addresses but raise Errors * set mail addresses in example configuration, which is also used for testing * addessing Antonios issues + switch to a non deprecated read fct. * updating dummy help email address in tests --------- Co-authored-by: Antonio Gonzalez <[email protected]>
1 parent 62292ca commit d743a81

File tree

16 files changed

+114
-39
lines changed

16 files changed

+114
-39
lines changed

qiita_core/configuration_manager.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class ConfigurationManager(object):
117117
The script used to start the plugins
118118
plugin_dir : str
119119
The path to the directory containing the plugin configuration files
120+
help_email : str
121+
The email address a user should write to when asking for help
122+
sysadmin_email : str
123+
The email address, Qiita sends internal notifications to a sys admin
120124
121125
Raises
122126
------
@@ -234,6 +238,32 @@ def _get_main(self, config):
234238
self.key_file = join(install_dir, 'qiita_core', 'support_files',
235239
'ci_server.key')
236240

241+
self.help_email = config.get('main', 'HELP_EMAIL')
242+
if not self.help_email:
243+
raise ValueError(
244+
"You did not specify the HELP_EMAIL address in the main "
245+
"section of Qiita's config file. This address is essential "
246+
"for users to ask for help as it is displayed at various "
247+
"location throughout Qiita's web pages.")
248+
if (self.help_email == '[email protected]') and \
249+
(self.test_environment is False):
250+
warnings.warn(
251+
"Using the github fake email for HELP_EMAIL, "
252+
"are you sure this is OK?")
253+
254+
self.sysadmin_email = config.get('main', 'SYSADMIN_EMAIL')
255+
if not self.sysadmin_email:
256+
raise ValueError(
257+
"You did not specify the SYSADMIN_EMAIL address in the main "
258+
"section of Qiita's config file. Serious issues will "
259+
"automatically be reported to a sys admin, an according "
260+
"address is therefore required!")
261+
if (self.sysadmin_email == '[email protected]') and \
262+
(self.test_environment is False):
263+
warnings.warn(
264+
"Using the github fake email for SYSADMIN_EMAIL, "
265+
"are you sure this is OK?")
266+
237267
def _get_job_scheduler(self, config):
238268
"""Get the configuration of the job_scheduler section"""
239269
self.job_scheduler_owner = config.get(

qiita_core/support_files/config_test.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ COOKIE_SECRET = SECRET
6868
# The value used to secure JWTs for delegated permission artifact download.
6969
JWT_SECRET = SUPER_SECRET
7070

71+
# Address a user should write to when asking for help
72+
HELP_EMAIL = [email protected]
73+
74+
# The email address, Qiita sends internal notifications to a sys admin
75+
SYSADMIN_EMAIL = [email protected]
76+
7177
# ----------------------------- SMTP settings -----------------------------
7278
[smtp]
7379
# The hostname to connect to

qiita_core/tests/test_configuration_manager.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def setUp(self):
2929

3030
self.conf = ConfigParser()
3131
with open(self.conf_fp, newline=None) as f:
32-
self.conf.readfp(f)
32+
self.conf.read_file(f)
3333

3434
def tearDown(self):
3535
if self.old_conf_fp is not None:
@@ -132,6 +132,8 @@ def test_get_main(self):
132132

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

@@ -180,6 +182,35 @@ def test_get_main(self):
180182

181183
self.assertEqual(obs.qiita_env, "")
182184

185+
def test_help_email(self):
186+
obs = ConfigurationManager()
187+
188+
with warnings.catch_warnings(record=True) as warns:
189+
# warning get only issued when in non test environment
190+
self.conf.set('main', 'TEST_ENVIRONMENT', 'FALSE')
191+
192+
obs._get_main(self.conf)
193+
self.assertEqual(obs.help_email, '[email protected]')
194+
self.assertEqual(obs.sysadmin_email, '[email protected]')
195+
196+
obs_warns = [str(w.message) for w in warns]
197+
exp_warns = [
198+
'Using the github fake email for HELP_EMAIL, '
199+
'are you sure this is OK?',
200+
'Using the github fake email for SYSADMIN_EMAIL, '
201+
'are you sure this is OK?']
202+
self.assertCountEqual(obs_warns, exp_warns)
203+
204+
# test if it falls back to [email protected]
205+
self.conf.set('main', 'HELP_EMAIL', '')
206+
with self.assertRaises(ValueError):
207+
obs._get_main(self.conf)
208+
209+
# test if it falls back to [email protected]
210+
self.conf.set('main', 'SYSADMIN_EMAIL', '')
211+
with self.assertRaises(ValueError):
212+
obs._get_main(self.conf)
213+
183214
def test_get_job_scheduler(self):
184215
obs = ConfigurationManager()
185216

@@ -274,6 +305,12 @@ def test_get_portal(self):
274305
# The value used to secure JWTs for delegated permission artifact download.
275306
JWT_SECRET = SUPER_SECRET
276307
308+
# Address a user should write to when asking for help
309+
HELP_EMAIL = [email protected]
310+
311+
# The email address, Qiita sends internal notifications to a sys admin
312+
SYSADMIN_EMAIL = [email protected]
313+
277314
# ----------------------------- SMTP settings -----------------------------
278315
[smtp]
279316
# The hostname to connect to

qiita_db/processing_job.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ def resource_allocation_info(self):
493493
samples, columns, input_size = self.shape
494494
parts = []
495495
error_msg = ('Obvious incorrect allocation. Please '
496-
'contact [email protected]')
496+
'contact %s' % qiita_config.help_email)
497497
for part in allocation.split('--'):
498498
param = ''
499499
if part.startswith('time '):
@@ -902,7 +902,7 @@ def _set_status(self, value, error_msg=None):
902902
if self.user.level in {'admin', 'wet-lab admin'}:
903903
if value == 'error':
904904
qdb.util.send_email(
905-
'[email protected]', msg['subject'],
905+
qiita_config.sysadmin_email, msg['subject'],
906906
msg['message'])
907907

908908
sql = """UPDATE qiita.processing_job

qiita_pet/handlers/artifact_handlers/base_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def artifact_patch_request(user, artifact_id, req_op, req_path, req_value=None,
370370

371371
sid = artifact.study.id
372372
if artifact.visibility == 'awaiting_approval':
373-
email_to = '[email protected]'
373+
email_to = qiita_config.help_email
374374
subject = ('QIITA: Artifact %s awaiting_approval. Study %d, '
375375
'Prep %d' % (artifact_id, sid,
376376
artifact.prep_templates[0].id))

qiita_pet/handlers/auth_handlers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def post(self):
6262
url_escape(username), url))
6363
except Exception:
6464
msg = ("Unable to send verification email. Please contact the "
65-
"qiita developers at <a href='mailto:qiita.help"
66-
"@gmail.com'>[email protected]</a>")
65+
"qiita developers at <a href='mailto:%s'>%s</a>") % (
66+
qiita_config.help_email, qiita_config.help_email)
6767
self.redirect(u"%s/?level=danger&message=%s"
6868
% (qiita_config.portal_dir, url_escape(msg)))
6969
return
@@ -75,8 +75,9 @@ def post(self):
7575
"<p>If you don't receive your activation email within a "
7676
"couple of minutes, check your spam folder. If you still "
7777
"don't see it, send us an email at <a "
78-
79-
"</a>.</p>")
78+
"href=\"mailto:%s\">%s"
79+
"</a>.</p>") % (qiita_config.help_email,
80+
qiita_config.help_email)
8081
self.redirect(u"%s/?level=success&message=%s" %
8182
(qiita_config.portal_dir, url_escape(msg)))
8283
else:
@@ -135,7 +136,8 @@ def post(self):
135136
"the verify link. You may need to check your spam "
136137
"folder to find the email.<br/>If a verification email"
137138
" has not arrived in 15 minutes, please email <a href='"
138-
139+
"mailto:%s'>%s</a>") % (qiita_config.help_email,
140+
qiita_config.help_email)
139141
except QiitaDBUnknownIDError:
140142
msg = "Unknown user"
141143
except RuntimeError:

qiita_pet/handlers/download.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,12 @@ def get(self):
445445
public_raw_download = study.public_raw_download
446446
if study.status != 'public':
447447
raise HTTPError(404, reason='Study is not public. If this '
448-
'is a mistake contact: '
449-
448+
'is a mistake contact: %s' %
449+
qiita_config.help_email)
450450
elif data == 'raw' and not public_raw_download:
451451
raise HTTPError(422, reason='No raw data access. If this '
452-
'is a mistake contact: '
453-
452+
'is a mistake contact: %s'
453+
% qiita_config.help_email)
454454
else:
455455
# raw data
456456
artifacts = [a for a in study.artifacts(dtype=data_type)
@@ -466,8 +466,8 @@ def get(self):
466466

467467
if not to_download:
468468
raise HTTPError(422, reason='Nothing to download. If '
469-
'this is a mistake contact: '
470-
469+
'this is a mistake contact: %s'
470+
% qiita_config.help_email)
471471
else:
472472
self._write_nginx_file_list(to_download)
473473

@@ -496,18 +496,18 @@ def get(self):
496496
else:
497497
if artifact.visibility != 'public':
498498
raise HTTPError(404, reason='Artifact is not public. If '
499-
'this is a mistake contact: '
500-
499+
'this is a mistake contact: %s'
500+
% qiita_config.help_email)
501501
elif artifact.has_human:
502502
raise HTTPError(404, reason='Artifact has possible human '
503503
'sequences. If this is a mistake contact: '
504-
504+
'%s' % qiita_config.help_email)
505505
else:
506506
to_download = self._list_artifact_files_nginx(artifact)
507507
if not to_download:
508508
raise HTTPError(422, reason='Nothing to download. If '
509-
'this is a mistake contact: '
510-
509+
'this is a mistake contact: %s'
510+
% qiita_config.help_email)
511511
else:
512512
self._write_nginx_file_list(to_download)
513513

@@ -600,8 +600,8 @@ def get(self, jti):
600600
to_download = self._list_artifact_files_nginx(artifact)
601601
if not to_download:
602602
raise HTTPError(422, reason='Nothing to download. If '
603-
'this is a mistake contact: '
604-
603+
'this is a mistake contact: %s' %
604+
qiita_config.help_email)
605605
else:
606606
self._write_nginx_file_list(to_download)
607607

qiita_pet/handlers/study_handlers/sample_template.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from tornado.web import authenticated, HTTPError
1414

15-
from qiita_core.qiita_settings import r_client
15+
from qiita_core.qiita_settings import r_client, qiita_config
1616
from qiita_pet.handlers.util import to_int
1717
from qiita_pet.handlers.base_handlers import BaseHandler
1818
from qiita_db.util import get_files_from_uploads_folders
@@ -214,8 +214,8 @@ def sample_template_handler_patch_request(user, req_op, req_path,
214214
# the system
215215
filepath = req_value
216216
if not exists(filepath):
217-
reason = ('Upload file not found (%s), please report to '
218-
'[email protected]' % filepath)
217+
reason = ('Upload file not found (%s), please report to %s'
218+
% (filepath, qiita_config.help_email))
219219
raise HTTPError(404, reason=reason)
220220
else:
221221
# Check if the file exists

qiita_pet/templates/admin_processing_job.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
$inp.attr('type', 'file');
192192
}
193193
else {
194-
bootstrapAlert("Error: Parameter type (" + p_type + ") not recognized. Please, take a screenshot and <a href='mailto:[email protected]'>contact us</a>", "danger");
194+
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");
195195
}
196196
}
197197

qiita_pet/templates/error.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h1 style="text-align:center">ERROR: CODE {{status_code}}!</h1>
44
<h2 style="text-align:center">{% raw escape(error) %}</h2>
55
<p style="text-align:center">The error has been logged and will be looked at.</p>
6-
<p style="text-align:center">Need help? Send us an <a href="mailto:[email protected]">email</a>.</p>
6+
<p style="text-align:center">Need help? Send us an <a href="mailto:{% raw qiita_config.help_email %}">email</a>.</p>
77
{% if is_admin %}
88
<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>
99
{% end %}

qiita_pet/templates/list_analyses.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
message.append(' '+data[level]);
122122
// prepend the "Need help" message
123123
if (level == 'warning' || level == 'danger'){
124-
message.append('<p style="text-align:center">Need help? Send us an <a href="mailto:[email protected]">email</a>.</p>');
124+
message.append('<p style="text-align:center">Need help? Send us an <a href="mailto:{% raw qiita_config.portal_dir %}">email</a>.</p>');
125125
}
126126
analyses_all_messages.prepend(message);
127127
}

qiita_pet/templates/redbiom.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
.fail(function(response, status, error) {
164164
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>';
165165
if (response.status != 504) {
166-
text = 'Status code: "' + response.status + '" - ' + error + '.<br/>Please send a screenshot to <a href="[email protected]">[email protected]</a>.';
166+
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>.';
167167
}
168168
redbiom_info.html(
169169
`<div class="alert alert-danger alert-dismissible" role="alert">

qiita_pet/templates/sitebase.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ <h4 class="modal-title">File really big.</h4>
588588
<div id="footer" style="font-size: 12px; text-align: center; z-index: 1000;">
589589
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>.
590590
<br/>
591-
Questions? <a href="mailto:[email protected]">[email protected]</a>; don't forget to add your study or analysis id.
591+
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.
592592
<br/>
593593
Read our <a href="{% raw qiita_config.portal_dir %}/iframe/?iframe=qiita-terms">terms and conditions</a>.
594594
</div>

qiita_pet/templates/study_ajax/base_info.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
<input id="studyTags">
160160
<small>
161161
New tags are linked to the user that created them.
162-
Report <a href="mailto:[email protected]">abuse</a>.
162+
Report <a href="mailto:{% raw qiita_config.help_email %}">abuse</a>.
163163
</small>
164164
<br/>
165165
<button type="submit" class="btn btn-default" onclick="tags_patch(); return false;">Save tags</button>

qiita_pet/test/test_download.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,15 @@ def test_download(self):
387387
response = self.get('/public_download/?data=raw&study_id=1')
388388
self.assertEqual(response.code, 404)
389389
self.assertEqual(response.reason, 'Study is not public. '
390-
'If this is a mistake contact: qiita.help@gmail.com')
390+
'If this is a mistake contact: foo@bar.com')
391391

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

400400
# check success
401401
response = self.get('/public_download/?data=biom&study_id=1')
@@ -426,12 +426,12 @@ def test_download(self):
426426
'/public_download/?data=raw&study_id=1&data_type=Genomics')
427427
self.assertEqual(response.code, 422)
428428
self.assertEqual(response.reason, 'Nothing to download. If this is a '
429-
'mistake contact: qiita.help@gmail.com')
429+
'mistake contact: foo@bar.com')
430430
response = self.get(
431431
'/public_download/?data=biom&study_id=1&data_type=Genomics')
432432
self.assertEqual(response.code, 422)
433433
self.assertEqual(response.reason, 'Nothing to download. If this is a '
434-
'mistake contact: qiita.help@gmail.com')
434+
'mistake contact: foo@bar.com')
435435

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

526526
# check success
527527
Artifact(5).visibility = 'public'

qiita_ware/test/test_private_plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _set_allocation(memory):
403403
self.assertEqual(job.resource_allocation_info, 'Not valid')
404404
self.assertEqual(job.status, 'error')
405405
self.assertEqual(job.log.msg, 'Obvious incorrect allocation. Please '
406-
'contact qiita.help@gmail.com')
406+
'contact foo@bar.com')
407407

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

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

426426
# now let's test a full build_analysis_files job
427427
job = self._create_job('build_analysis_files', {

0 commit comments

Comments
 (0)