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

Email Implementation on local units #2357

Open
wants to merge 15 commits into
base: project/localunit
Choose a base branch
from

Conversation

susilnem
Copy link
Member

Addresses

Changes

  • Commenting out tls server for now
  • Email Implementation on Local units
  • Create a Cronjob for sending email to Regional and global validators

Checklist

Things that should succeed before merging.

  • Updated/ran unit tests
  • Updated CHANGELOG.md

Release

If there is a version update, make sure to tag the repository with the latest version.

@susilnem susilnem requested review from Rup-Narayan-Rajbanshi and thenav56 and removed request for Rup-Narayan-Rajbanshi December 27, 2024 08:32
@@ -0,0 +1,43 @@
<p>Dear {{full_name}} {% include "includes/logo.html" %}</p>
Copy link
Member

Choose a reason for hiding this comment

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

This is weird. What does logo.html introduce? Can this be splitted on multiple lines?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this file needs to be refactored with correct styling and structure. Someone from frontend will need to help here.

@susilnem will add a preview view in backend for local develop run which can be used for developer to make required changes.

We will also need to add a proper base template for emails as well

</p>
{% endif %}

{% if regional_admin %}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if the variable name is correct here. Better name could be pending_regional_admin_validation

Copy link
Member

Choose a reason for hiding this comment

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

They are passed through context variable from this file local_units/management/commands/notify_validators.py


{% endif %}

{% if global_admin %}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if the variable name is correct here.

Copy link
Member

Choose a reason for hiding this comment

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

They are passed through context variable from this file local_units/management/commands/notify_validators.py

Comment on lines 29 to 30
server.starttls()
# NOTE: TLS is disabled for now, for alpha instance
# server.starttls()
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this also be configured through the environment variable?

Copy link
Member

Choose a reason for hiding this comment

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

Let's add and use EMAIL_USE_TLS here (set True as default value to avoid changing production logic)

Comment on lines 26 to 33
queryset_for_regional_validtors = LocalUnit.objects.filter(
validated=False, is_deprecated=False, created_at__date=timezone.now() - timedelta(days=14)
)

# Global Validators: 28 days
queryset_for_global_validators = LocalUnit.objects.filter(
validated=False, is_deprecated=False, created_at__date=timezone.now() - timedelta(days=28)
)
Copy link
Member

Choose a reason for hiding this comment

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

We should use greater than or equal to comparison instead of is equal to for the dates

self.stdout.write(self.style.NOTICE("Notifying the validators..."))

# Regional Validators: 14 days
queryset_for_regional_validtors = LocalUnit.objects.filter(
Copy link
Member

Choose a reason for hiding this comment

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

Let's use date threshold filter and track it using database (one field last_sent_validator_type)

Also

Suggested change
queryset_for_regional_validtors = LocalUnit.objects.filter(
queryset_for_regional_validators = LocalUnit.objects.filter(



@shared_task
def send_local_unit_email(local_unit_id: int, users_details: list, new: bool = True):
Copy link
Member

Choose a reason for hiding this comment

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

Let's use users_ids

for email, first_name, last_name in users_details:
# NOTE: Adding the validator email to the context
email_context["validator_email"] = email
email_context["full_name"] = f"{first_name} {last_name}"
Copy link
Member

Choose a reason for hiding this comment

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

Let's use get_full_name



@shared_task
def send_revert_email(local_unit_id: int, user_id: int, reason: str = ""):
Copy link
Member

Choose a reason for hiding this comment

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

Let's use local_unit.created_by instead of user_id

For other tasks as well

def get_email_context(instance):
from local_units.serializers import PrivateLocalUnitSerializer

local_unit_data = PrivateLocalUnitSerializer(instance).data
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a NOTE on why we are using PrivateLocalUnitSerializer here

serializer.save()
self.perform_update(serializer)
deprecated_reason = serializer.validated_data["deprecated_reason_overview"]
transaction.on_commit(lambda: send_deprecate_email(instance.id, instance.created_by_id, deprecated_reason))
Copy link
Member

Choose a reason for hiding this comment

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

Let's use instance.deprecated_reason from within the task and remove it from here

email_subject = "Action Required: Local Unit Pending Validation"
email_type = "Local Unit"

for region_admin_validator in get_region_admins(local_unit):
Copy link
Member

Choose a reason for hiding this comment

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

Let's add try catch... Only update success sends


{% endif %}

{% if global_admin %}
Copy link
Member

Choose a reason for hiding this comment

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

They are passed through context variable from this file local_units/management/commands/notify_validators.py

</p>
{% endif %}

{% if regional_admin %}
Copy link
Member

Choose a reason for hiding this comment

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

They are passed through context variable from this file local_units/management/commands/notify_validators.py

@@ -0,0 +1,43 @@
<p>Dear {{full_name}} {% include "includes/logo.html" %}</p>
Copy link
Member

Choose a reason for hiding this comment

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

Yes, this file needs to be refactored with correct styling and structure. Someone from frontend will need to help here.

@susilnem will add a preview view in backend for local develop run which can be used for developer to make required changes.

We will also need to add a proper base template for emails as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants