Skip to content

Commit

Permalink
Fixes for email notifications not sending share link in the body (#1143)
Browse files Browse the repository at this point in the history
### Feature or Bugfix
- Bugfix

### Detail
- Correcting place where the environment variable containing frontend
URL is defined. Earlier it was in the AWSWorker lambda env but it is
needed in the graphQL lambda
- Removing " which was causing issues when clicking on email address.
Also lowercased words.

### Relates
- #1142

### Security
Please answer the questions below briefly where applicable, or write
`N/A`. Based on
[OWASP 10](https://owasp.org/Top10/en/).

- Does this PR introduce or modify any input fields or queries - this
includes
fetching data from storage outside the application (e.g. a database, an
S3 bucket)? N/A
  - Is the input sanitized?
- What precautions are you taking before deserializing the data you
consume?
  - Is injection prevented by parametrizing queries?
  - Have you ensured no `eval` or similar functions are used?
- Does this PR introduce any functionality or component that requires
authorization? N/A
- How have you ensured it respects the existing AuthN/AuthZ mechanisms?
  - Are you logging failed auth attempts?
- Are you using or adding any cryptographic features? N/A
  - Do you use a standard proven implementations?
  - Are the used keys controlled by the customer? Where are they stored?
- Are you introducing any new policies/roles/users? N/A
  - Have you used the least-privilege principle? How?


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

---------

Co-authored-by: trajopadhye <tejas.rajopadhye@yahooinc.com>
  • Loading branch information
TejasRGitHub and trajopadhye authored Apr 8, 2024
1 parent f4966e8 commit 626e174
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,36 @@ def __init__(self, session, dataset: Dataset, share: ShareObject):

def notify_share_object_submission(self, email_id: str):
share_link_text = ''
if os.environ.get('frontend_domain_url'):
share_link_text = f'<br><br> Please visit Data.all <a href="{os.environ.get("frontend_domain_url")}"/console/shares/{self.share.shareUri}">Share link </a> to take action or view more details'
if os.environ.get("frontend_domain_url"):
share_link_text = f'<br><br> Please visit data.all <a href="{os.environ.get("frontend_domain_url")}/console/shares/{self.share.shareUri}">share link </a> to take action or view more details'
msg = f'User {email_id} SUBMITTED share request for dataset {self.dataset.label} for principal {self.share.principalId}'
subject = f'Data.all | Share Request Submitted for {self.dataset.label}'
email_notification_msg = msg + share_link_text

notifications = self._register_notifications(
notification_type=DataSharingNotificationType.SHARE_OBJECT_SUBMITTED.value, msg=msg
)
notification_type=DataSharingNotificationType.SHARE_OBJECT_SUBMITTED.value, msg=msg)

self._create_notification_task(subject=subject, msg=email_notification_msg)
return notifications

def notify_share_object_approval(self, email_id: str):
share_link_text = ''
if os.environ.get('frontend_domain_url'):
share_link_text = f'<br><br> Please visit Data.all <a href="{os.environ.get("frontend_domain_url")}"/console/shares/{self.share.shareUri}">Share link </a> to take action or view more details'
if os.environ.get("frontend_domain_url"):
share_link_text = f'<br><br> Please visit data.all <a href="{os.environ.get("frontend_domain_url")}/console/shares/{self.share.shareUri}">share link </a> to take action or view more details'
msg = f'User {email_id} APPROVED share request for dataset {self.dataset.label} for principal {self.share.principalId}'
subject = f'Data.all | Share Request Approved for {self.dataset.label}'
email_notification_msg = msg + share_link_text

notifications = self._register_notifications(
notification_type=DataSharingNotificationType.SHARE_OBJECT_APPROVED.value, msg=msg
)
notification_type=DataSharingNotificationType.SHARE_OBJECT_APPROVED.value, msg=msg)

self._create_notification_task(subject=subject, msg=email_notification_msg)
return notifications

def notify_share_object_rejection(self, email_id: str):
share_link_text = ''
if os.environ.get('frontend_domain_url'):
share_link_text = f'<br><br> Please visit Data.all <a href="{os.environ.get("frontend_domain_url")}"/console/shares/{self.share.shareUri}">Share link </a> to take action or view more details'
if os.environ.get("frontend_domain_url"):
share_link_text = f'<br><br> Please visit data.all <a href="{os.environ.get("frontend_domain_url")}/console/shares/{self.share.shareUri}">share link </a> to take action or view more details'
if self.share.status == ShareObjectStatus.Rejected.value:
msg = f'User {email_id} REJECTED share request for dataset {self.dataset.label} for principal {self.share.principalId}'
subject = f'Data.all | Share Request Rejected for {self.dataset.label}'
Expand All @@ -87,8 +85,7 @@ def notify_share_object_rejection(self, email_id: str):
email_notification_msg = msg + share_link_text

notifications = self._register_notifications(
notification_type=DataSharingNotificationType.SHARE_OBJECT_REJECTED.value, msg=msg
)
notification_type=DataSharingNotificationType.SHARE_OBJECT_REJECTED.value, msg=msg)

self._create_notification_task(subject=subject, msg=email_notification_msg)
return notifications
Expand All @@ -97,8 +94,7 @@ def notify_new_data_available_from_owners(self, s3_prefix):
msg = f'New data (at {s3_prefix}) is available from dataset {self.dataset.datasetUri} shared by owner {self.dataset.owner}'

notifications = self._register_notifications(
notification_type=DataSharingNotificationType.DATASET_VERSION.value, msg=msg
)
notification_type=DataSharingNotificationType.DATASET_VERSION.value, msg=msg)
return notifications

def _get_share_object_targeted_users(self):
Expand All @@ -118,7 +114,7 @@ def _register_notifications(self, notification_type, msg):
"""
notifications = []
for recipient in self.notification_target_users:
log.info(f'Creating notification for {recipient}, msg {msg}')
log.info(f"Creating notification for {recipient}, msg {msg}")
notifications.append(
NotificationRepository.create_notification(
session=self.session,
Expand Down Expand Up @@ -148,8 +144,8 @@ def _create_notification_task(self, subject, msg):
notification_recipient_groups_list = [self.dataset.SamlAdminGroupName, self.dataset.stewards]
notification_recipient_email_ids = []

if share_notification_config_type == 'email':
if params.get('group_notifications', False) == True:
if share_notification_config_type == "email":
if params.get("group_notifications", False) == True:
notification_recipient_groups_list.append(self.share.groupUri)
else:
notification_recipient_email_ids = [self.share.owner]
Expand All @@ -162,7 +158,7 @@ def _create_notification_task(self, subject, msg):
'subject': subject,
'message': msg,
'recipientGroupsList': notification_recipient_groups_list,
'recipientEmailList': notification_recipient_email_ids,
'recipientEmailList': notification_recipient_email_ids
},
)
self.session.add(notification_task)
Expand Down
6 changes: 3 additions & 3 deletions deploy/stacks/lambda_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def __init__(
self.api_handler_dlq = self.set_dlq(f'{resource_prefix}-{envname}-graphql-dlq')
api_handler_sg = self.create_lambda_sgs(envname, 'apihandler', resource_prefix, vpc)
api_handler_env = {'envname': envname, 'LOG_LEVEL': 'INFO', 'REAUTH_TTL': str(reauth_ttl)}
# Check if custom domain exists and if it exists email notifications could be enabled. Create a env variable which stores the domain url. This is used for sending data.all share weblinks in the email notifications.
if custom_domain and custom_domain.get('hosted_zone_name', None):
api_handler_env['frontend_domain_url'] = f'https://{custom_domain.get("hosted_zone_name", None)}'
if custom_auth:
api_handler_env['custom_auth'] = custom_auth.get('provider', None)
self.api_handler = _lambda.DockerImageFunction(
Expand Down Expand Up @@ -120,9 +123,6 @@ def __init__(
'LOG_LEVEL': 'INFO',
'email_sender_id': email_notification_sender_email_id,
}
# Check if custom domain exists and if it exists email notifications could be enabled. Create a env variable which stores the domain url. This is used for sending data.all share weblinks in the email notifications.
if custom_domain and custom_domain.get('hosted_zone_name', None):
awshandler_env['frontend_domain_url'] = f'https://{custom_domain.get("hosted_zone_name", None)}'
self.aws_handler = _lambda.DockerImageFunction(
self,
'AWSWorker',
Expand Down

0 comments on commit 626e174

Please sign in to comment.