Skip to content

Commit 60f3cc1

Browse files
Merge pull request #3204 from antgonza/send-job-emails
send job emails to users
2 parents bdcc69e + 5cd1951 commit 60f3cc1

File tree

7 files changed

+71
-44
lines changed

7 files changed

+71
-44
lines changed

qiita_db/processing_job.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -781,13 +781,15 @@ def _set_status(self, value):
781781
new_status = qdb.util.convert_to_id(
782782
value, "processing_job_status")
783783

784-
if (new_status in ('running', 'success', 'error') and
785-
not self.command.analysis_only and
786-
self.user.level == 'admin'):
787-
subject = ('Job status change: %s (%s)' % (
788-
self.command.name, self.id))
789-
message = ('New status: %s' % (new_status))
790-
qdb.util.send_email(self.user.email, subject, message)
784+
if self.user.info['receive_processing_job_emails']:
785+
# skip if software is internal
786+
ignore_software = ('Qiita')
787+
if self.command.software.name not in ignore_software:
788+
subject = ('Job status change: %s (%s)' % (
789+
self.command.name, self.id))
790+
message = ('New status: %s' % (new_status))
791+
qdb.util.send_email(self.user.email, subject, message)
792+
791793
sql = """UPDATE qiita.processing_job
792794
SET processing_job_status_id = %s
793795
WHERE processing_job_id = %s"""

qiita_db/support_files/patches/86.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ $$ LANGUAGE plpgsql;
2727
-- Jun 13, 2022
2828
-- adding an archive_data column to the artifact
2929
ALTER TABLE qiita.artifact ADD archive_data JSONB DEFAULT NULL;
30+
31+
-- Jun 15, 2022
32+
-- adding
33+
ALTER TABLE qiita.qiita_user ADD receive_processing_job_emails BOOL DEFAULT FALSE;

qiita_db/support_files/qiita-db.dbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,9 @@
12471247
<column name="pass_reset_timestamp" type="timestamp" length="0" decimal="6" jt="93" >
12481248
<comment><![CDATA[Time the reset code was generated]]></comment>
12491249
</column>
1250+
<column name="receive_processing_job_emails" type="boolean" jt="-7" mandatory="y" >
1251+
<defo><![CDATA[false]]></defo>
1252+
</column>
12501253
<index name="pk_user" unique="PRIMARY_KEY" >
12511254
<column name="email" />
12521255
</index>

qiita_db/support_files/qiita-db.html

Lines changed: 39 additions & 31 deletions
Large diffs are not rendered by default.

qiita_db/test/test_user.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def setUp(self):
7171
'phone': '111-222-3344',
7272
'pass_reset_code': None,
7373
'pass_reset_timestamp': None,
74-
'user_verify_code': None
74+
'user_verify_code': None,
75+
'receive_processing_job_emails': True
7576
}
7677

7778
def tearDown(self):
@@ -123,6 +124,7 @@ def test_create_user(self):
123124
'user_verify_code': '',
124125
'address': None,
125126
'user_level_id': 5,
127+
'receive_processing_job_emails': False,
126128
'email': 'testcreateuser@test.bar'}
127129
self._check_correct_info(obs, exp)
128130

@@ -159,6 +161,7 @@ def test_create_user_info(self):
159161
'pass_reset_code': None,
160162
'user_verify_code': '',
161163
'user_level_id': 5,
164+
'receive_processing_job_emails': True,
162165
'email': 'testcreateuserinfo@test.bar'}
163166
self._check_correct_info(obs, exp)
164167

@@ -225,6 +228,7 @@ def test_get_info(self):
225228
'pass_reset_code': None,
226229
'pass_reset_timestamp': None,
227230
'user_verify_code': None,
231+
'receive_processing_job_emails': False,
228232
'phone': '222-444-6789'
229233
}
230234
self.assertEqual(self.user.info, expinfo)

qiita_db/test/test_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_get_table_cols(self):
8383
obs = qdb.util.get_table_cols("qiita_user")
8484
exp = {"email", "user_level_id", "password", "name", "affiliation",
8585
"address", "phone", "user_verify_code", "pass_reset_code",
86-
"pass_reset_timestamp"}
86+
"pass_reset_timestamp", "receive_processing_job_emails"}
8787
self.assertEqual(set(obs), exp)
8888

8989
def test_exists_table(self):

qiita_pet/handlers/user_handlers.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# -----------------------------------------------------------------------------
88

99
from tornado.web import authenticated, HTTPError
10-
from wtforms import Form, StringField, validators
10+
from wtforms import Form, StringField, BooleanField, validators
1111

1212
from qiita_pet.handlers.base_handlers import BaseHandler
1313
from qiita_pet.handlers.api_proxy import user_jobs_get_req
@@ -25,6 +25,8 @@ class UserProfile(Form):
2525
affiliation = StringField("Affiliation")
2626
address = StringField("Address")
2727
phone = StringField("Phone")
28+
receive_processing_job_emails = BooleanField(
29+
"Receive Processing Job Emails?")
2830

2931

3032
class UserProfileHandler(BaseHandler):
@@ -45,14 +47,18 @@ def post(self):
4547
if action == "profile":
4648
# tuple of colmns available for profile
4749
# FORM INPUT NAMES MUST MATCH DB COLUMN NAMES
50+
not_str_fields = ('receive_processing_job_emails')
4851
form_data = UserProfile()
4952
form_data.process(data=self.request.arguments)
50-
profile = {name: data[0].decode('ascii') for name, data in
51-
form_data.data.items()}
53+
profile = {name: data[0].decode('ascii')
54+
if name not in not_str_fields else
55+
data
56+
for name, data in form_data.data.items()}
5257

5358
# Turn default value as list into default strings
5459
for field in form_data:
55-
field.data = field.data[0].decode('ascii')
60+
if field.name not in not_str_fields:
61+
field.data = field.data[0].decode('ascii')
5662
try:
5763
user.info = profile
5864
msg = "Profile updated successfully"

0 commit comments

Comments
 (0)