Skip to content

Commit

Permalink
Merge pull request #3111 from manishkumr/SDM-814
Browse files Browse the repository at this point in the history
[SDM-814] send datafile recall acknowledgement email to logged in user
  • Loading branch information
manishkumr committed Jun 14, 2021
2 parents 59ba71a + 2af022a commit 1453126
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
23 changes: 19 additions & 4 deletions tardis/apps/hsm/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

HSM_EMAIL_TEMPLATES = {
'dfo_recall_complete': ('[{site_title}] File recalled from archive',
'''\
'''\
Dear {first_name} {last_name},
The following file has has been recalled from the archive:
Expand All @@ -30,7 +30,7 @@
{site_title} Team.
'''),
'dfo_recall_failed': ('[{site_title}] File recall failed',
'''\
'''\
Dear {first_name} {last_name},
An error occurred when attempting to recall the following file from the archive:
Expand All @@ -43,7 +43,7 @@
{site_title} Team.
'''),
'dataset_recall_requested': ('[{site_title}] Dataset recall requested',
'''\
'''\
Dear RDSM support team,
User {user} has requested to recall dataset {dataset} from HSM vault.
Expand All @@ -53,5 +53,20 @@
Regards,
{site_title} Team.
''')
'''),
'dfo_recall_requested': ('[{site_title}] Datafile recall requested',
'''\
Dear {first_name} {last_name},
Your request to recall datafile {file_name} has been received.
We will notify you when recall is complete and file is available for you to download.
Please contact {support_email}, if your file is not available to download in next 24 hrs.
Regards,
{site_title} Team.
'''
)
}
13 changes: 12 additions & 1 deletion tardis/apps/hsm/email_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.sites.models import Site

from . import default_settings
from ...tardis_portal.models import StorageBoxOption, StorageBoxAttribute
from ...tardis_portal.models import StorageBoxOption, StorageBoxAttribute, DataFileObject


def interpolate_template(template_name, **kwargs):
Expand Down Expand Up @@ -31,6 +31,17 @@ def email_dfo_recall_complete(dfo, user):
support_email=settings.SUPPORT_EMAIL, site_title=settings.SITE_TITLE)


def email_dfo_recall_requested(dfo_id, user):
dfo = DataFileObject.objects.get(id=dfo_id)
file_name = dfo.datafile.filename
return interpolate_template(
'dfo_recall_requested',
first_name=user.first_name, last_name=user.last_name,
file_name=file_name, site_title=settings.SITE_TITLE,
support_email=settings.SUPPORT_EMAIL
)


def email_dfo_recall_failed(dfo, user):
if dfo.datafile.directory:
file_path = '/'.join([dfo.datafile.directory, dfo.datafile.filename])
Expand Down
18 changes: 17 additions & 1 deletion tardis/apps/hsm/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from django.utils import timezone

from tardis.celery import tardis_app
from .email_text import email_dfo_recall_complete
from .email_text import email_dfo_recall_complete, email_dfo_recall_requested
from .email_text import email_dfo_recall_failed
from .exceptions import HsmException

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -38,6 +39,21 @@ def dfo_recall(dfo_id, user_id):
StorageClassNotSupportedError)
from .storage import HsmFileSystemStorage

# send an email to user acknowledging received request
"""
send an email to user
"""
if user_id:
user = User.objects.get(id=user_id)
try:
subject, content = email_dfo_recall_requested(dfo_id, user)
logger.info("sending recall requested email to user %s", user)
user.email_user(subject, content,
from_email=settings.DEFAULT_FROM_EMAIL,
fail_silently=False)
except HsmException as err:
logger.error("Error sending email %s", str(err))

dfo = DataFileObject.objects.get(id=dfo_id)

if not dfo.verified:
Expand Down

0 comments on commit 1453126

Please sign in to comment.