* dev: create email notification preference model * dev: intiate models * dev: user notification preferences * dev: create notification logs for the user. * dev: email notification stacking and sending logic * feat: email notification preference settings page. * dev: delete subscribers * dev: issue update ui implementation in email notification * chore: integrate email notification endpoint. * chore: remove toggle switch. * chore: added labels part * fix: refactored base design with tables * dev: email notification templates * dev: template updates * dev: update models * dev: update template for labels and new migrations * fix: profile settings preference sidebar. * dev: update preference endpoints * dev: update the schedule to 5 minutes * dev: update template with priority data * dev: update templates * chore: enable `issue subscribe` button for all users. * chore: notification handling for external api * dev: update origin request --------- Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com> Co-authored-by: LAKHAN BAHETI <lakhanbaheti9@gmail.com> Co-authored-by: Ramesh Kumar Chandra <rameshkumar2299@gmail.com> Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
128 lines
4 KiB
Python
128 lines
4 KiB
Python
# Django imports
|
|
from django.db import models
|
|
from django.conf import settings
|
|
|
|
# Module imports
|
|
from . import BaseModel
|
|
|
|
class Notification(BaseModel):
|
|
workspace = models.ForeignKey(
|
|
"db.Workspace", related_name="notifications", on_delete=models.CASCADE
|
|
)
|
|
project = models.ForeignKey(
|
|
"db.Project",
|
|
related_name="notifications",
|
|
on_delete=models.CASCADE,
|
|
null=True,
|
|
)
|
|
data = models.JSONField(null=True)
|
|
entity_identifier = models.UUIDField(null=True)
|
|
entity_name = models.CharField(max_length=255)
|
|
title = models.TextField()
|
|
message = models.JSONField(null=True)
|
|
message_html = models.TextField(blank=True, default="<p></p>")
|
|
message_stripped = models.TextField(blank=True, null=True)
|
|
sender = models.CharField(max_length=255)
|
|
triggered_by = models.ForeignKey(
|
|
"db.User",
|
|
related_name="triggered_notifications",
|
|
on_delete=models.SET_NULL,
|
|
null=True,
|
|
)
|
|
receiver = models.ForeignKey(
|
|
"db.User",
|
|
related_name="received_notifications",
|
|
on_delete=models.CASCADE,
|
|
)
|
|
read_at = models.DateTimeField(null=True)
|
|
snoozed_till = models.DateTimeField(null=True)
|
|
archived_at = models.DateTimeField(null=True)
|
|
|
|
class Meta:
|
|
verbose_name = "Notification"
|
|
verbose_name_plural = "Notifications"
|
|
db_table = "notifications"
|
|
ordering = ("-created_at",)
|
|
|
|
def __str__(self):
|
|
"""Return name of the notifications"""
|
|
return f"{self.receiver.email} <{self.workspace.name}>"
|
|
|
|
|
|
def get_default_preference():
|
|
return {
|
|
"property_change": {
|
|
"email": True,
|
|
},
|
|
"state": {
|
|
"email": True,
|
|
},
|
|
"comment": {
|
|
"email": True,
|
|
},
|
|
"mentions": {
|
|
"email": True,
|
|
},
|
|
}
|
|
|
|
|
|
class UserNotificationPreference(BaseModel):
|
|
# user it is related to
|
|
user = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL,
|
|
on_delete=models.CASCADE,
|
|
related_name="notification_preferences",
|
|
)
|
|
# workspace if it is applicable
|
|
workspace = models.ForeignKey(
|
|
"db.Workspace",
|
|
on_delete=models.CASCADE,
|
|
related_name="workspace_notification_preferences",
|
|
null=True,
|
|
)
|
|
# project
|
|
project = models.ForeignKey(
|
|
"db.Project",
|
|
on_delete=models.CASCADE,
|
|
related_name="project_notification_preferences",
|
|
null=True,
|
|
)
|
|
|
|
# preference fields
|
|
property_change = models.BooleanField(default=True)
|
|
state_change = models.BooleanField(default=True)
|
|
comment = models.BooleanField(default=True)
|
|
mention = models.BooleanField(default=True)
|
|
issue_completed = models.BooleanField(default=True)
|
|
|
|
class Meta:
|
|
verbose_name = "UserNotificationPreference"
|
|
verbose_name_plural = "UserNotificationPreferences"
|
|
db_table = "user_notification_preferences"
|
|
ordering = ("-created_at",)
|
|
|
|
def __str__(self):
|
|
"""Return the user"""
|
|
return f"<{self.user}>"
|
|
|
|
class EmailNotificationLog(BaseModel):
|
|
# receiver
|
|
receiver = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="email_notifications")
|
|
triggered_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="triggered_emails")
|
|
# entity - can be issues, pages, etc.
|
|
entity_identifier = models.UUIDField(null=True)
|
|
entity_name = models.CharField(max_length=255)
|
|
# data
|
|
data = models.JSONField(null=True)
|
|
# sent at
|
|
processed_at = models.DateTimeField(null=True)
|
|
sent_at = models.DateTimeField(null=True)
|
|
entity = models.CharField(max_length=200)
|
|
old_value = models.CharField(max_length=300, blank=True, null=True)
|
|
new_value = models.CharField(max_length=300, blank=True, null=True)
|
|
|
|
class Meta:
|
|
verbose_name = "Email Notification Log"
|
|
verbose_name_plural = "Email Notification Logs"
|
|
db_table = "email_notification_logs"
|
|
ordering = ("-created_at",)
|