2023-11-07 05:00:09 +00:00
|
|
|
from django.template.loader import render_to_string
|
2023-07-24 03:52:25 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2022-01-10 11:02:18 +00:00
|
|
|
|
2023-11-07 07:10:46 +00:00
|
|
|
from common.tasks import send_mail_attachment_async, upload_backup_to_obj_storage
|
2023-11-07 05:00:09 +00:00
|
|
|
from notifications.notifications import UserMessage
|
2023-11-07 07:10:46 +00:00
|
|
|
from terminal.models.component.storage import ReplayStorage
|
2023-12-13 08:15:34 +00:00
|
|
|
from users.models import User
|
2022-01-10 11:02:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AccountBackupExecutionTaskMsg(object):
|
|
|
|
subject = _('Notification of account backup route task results')
|
|
|
|
|
|
|
|
def __init__(self, name: str, user: User):
|
|
|
|
self.name = name
|
|
|
|
self.user = user
|
|
|
|
|
|
|
|
@property
|
|
|
|
def message(self):
|
|
|
|
name = self.name
|
|
|
|
if self.user.secret_key:
|
2023-01-16 11:02:09 +00:00
|
|
|
return _('{} - The account backup passage task has been completed.'
|
|
|
|
' See the attachment for details').format(name)
|
|
|
|
else:
|
|
|
|
return _("{} - The account backup passage task has been completed: "
|
|
|
|
"the encryption password has not been set - "
|
2023-12-13 08:15:34 +00:00
|
|
|
"please go to personal information -> Basic file encryption password for preference settings"
|
|
|
|
).format(name)
|
2022-01-10 11:02:18 +00:00
|
|
|
|
|
|
|
def publish(self, attachment_list=None):
|
2022-11-04 03:15:34 +00:00
|
|
|
send_mail_attachment_async(
|
2022-01-10 11:02:18 +00:00
|
|
|
self.subject, self.message, [self.user.email], attachment_list
|
|
|
|
)
|
2022-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
|
2023-11-07 07:10:46 +00:00
|
|
|
class AccountBackupByObjStorageExecutionTaskMsg(object):
|
|
|
|
subject = _('Notification of account backup route task results')
|
|
|
|
|
|
|
|
def __init__(self, name: str, obj_storage: ReplayStorage):
|
|
|
|
self.name = name
|
|
|
|
self.obj_storage = obj_storage
|
|
|
|
|
|
|
|
@property
|
|
|
|
def message(self):
|
|
|
|
name = self.name
|
|
|
|
return _('{} - The account backup passage task has been completed.'
|
|
|
|
' See the attachment for details').format(name)
|
|
|
|
|
|
|
|
def publish(self, attachment_list=None):
|
|
|
|
upload_backup_to_obj_storage(
|
|
|
|
self.obj_storage, attachment_list
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-11-03 14:39:48 +00:00
|
|
|
class ChangeSecretExecutionTaskMsg(object):
|
|
|
|
subject = _('Notification of implementation result of encryption change plan')
|
|
|
|
|
|
|
|
def __init__(self, name: str, user: User):
|
|
|
|
self.name = name
|
|
|
|
self.user = user
|
|
|
|
|
|
|
|
@property
|
|
|
|
def message(self):
|
|
|
|
name = self.name
|
|
|
|
if self.user.secret_key:
|
2023-01-16 11:02:09 +00:00
|
|
|
return _('{} - The encryption change task has been completed. '
|
|
|
|
'See the attachment for details').format(name)
|
|
|
|
else:
|
|
|
|
return _("{} - The encryption change task has been completed: the encryption "
|
|
|
|
"password has not been set - please go to personal information -> "
|
|
|
|
"file encryption password to set the encryption password").format(name)
|
2022-11-03 14:39:48 +00:00
|
|
|
|
|
|
|
def publish(self, attachments=None):
|
2022-11-04 03:15:34 +00:00
|
|
|
send_mail_attachment_async(
|
2022-11-03 14:39:48 +00:00
|
|
|
self.subject, self.message, [self.user.email], attachments
|
|
|
|
)
|
2023-11-07 05:00:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class GatherAccountChangeMsg(UserMessage):
|
|
|
|
subject = _('Gather account change information')
|
|
|
|
|
|
|
|
def __init__(self, user, change_info: dict):
|
|
|
|
self.change_info = change_info
|
|
|
|
super().__init__(user)
|
|
|
|
|
|
|
|
def get_html_msg(self) -> dict:
|
|
|
|
context = {'change_info': self.change_info}
|
|
|
|
message = render_to_string('accounts/asset_account_change_info.html', context)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'subject': str(self.subject),
|
|
|
|
'message': message
|
|
|
|
}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def gen_test_msg(cls):
|
|
|
|
user = User.objects.first()
|
|
|
|
return cls(user, {})
|