Initial implementation of mailer events
Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
+31
-15
@@ -15,10 +15,16 @@ from mayan.apps.common import (
|
|||||||
menu_secondary, menu_setup, menu_tools
|
menu_secondary, menu_setup, menu_tools
|
||||||
)
|
)
|
||||||
from mayan.apps.common.widgets import TwoStateWidget
|
from mayan.apps.common.widgets import TwoStateWidget
|
||||||
|
from mayan.apps.events import ModelEventType
|
||||||
|
from mayan.apps.events.links import (
|
||||||
|
link_events_for_object, link_object_event_types_user_subcriptions_list
|
||||||
|
)
|
||||||
|
from mayan.apps.events.permissions import permission_events_view
|
||||||
from mayan.apps.navigation import SourceColumn
|
from mayan.apps.navigation import SourceColumn
|
||||||
from mayan.celery import app
|
from mayan.celery import app
|
||||||
|
|
||||||
from .classes import MailerBackend
|
from .classes import MailerBackend
|
||||||
|
from .events import event_email_sent
|
||||||
from .links import (
|
from .links import (
|
||||||
link_send_document, link_send_document_link, link_send_multiple_document,
|
link_send_document, link_send_document_link, link_send_multiple_document,
|
||||||
link_send_multiple_document_link, link_system_mailer_error_log,
|
link_send_multiple_document_link, link_system_mailer_error_log,
|
||||||
@@ -43,6 +49,7 @@ class MailerApp(MayanAppConfig):
|
|||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
super(MailerApp, self).ready()
|
super(MailerApp, self).ready()
|
||||||
|
from actstream import registry
|
||||||
|
|
||||||
Document = apps.get_model(
|
Document = apps.get_model(
|
||||||
app_label='documents', model_name='Document'
|
app_label='documents', model_name='Document'
|
||||||
@@ -53,6 +60,25 @@ class MailerApp(MayanAppConfig):
|
|||||||
|
|
||||||
MailerBackend.initialize()
|
MailerBackend.initialize()
|
||||||
|
|
||||||
|
ModelEventType.register(
|
||||||
|
model=UserMailer, event_types=(event_email_sent,)
|
||||||
|
)
|
||||||
|
|
||||||
|
ModelPermission.register(
|
||||||
|
model=Document, permissions=(
|
||||||
|
permission_mailing_link, permission_mailing_send_document
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
ModelPermission.register(
|
||||||
|
model=UserMailer, permissions=(
|
||||||
|
permission_acl_edit, permission_acl_view,
|
||||||
|
permission_events_view, permission_user_mailer_delete,
|
||||||
|
permission_user_mailer_edit, permission_user_mailer_view,
|
||||||
|
permission_user_mailer_use
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
SourceColumn(
|
SourceColumn(
|
||||||
source=LogEntry, label=_('Date and time'), attribute='datetime'
|
source=LogEntry, label=_('Date and time'), attribute='datetime'
|
||||||
)
|
)
|
||||||
@@ -78,20 +104,6 @@ class MailerApp(MayanAppConfig):
|
|||||||
source=UserMailer, label=_('Label'), attribute='backend_label'
|
source=UserMailer, label=_('Label'), attribute='backend_label'
|
||||||
)
|
)
|
||||||
|
|
||||||
ModelPermission.register(
|
|
||||||
model=Document, permissions=(
|
|
||||||
permission_mailing_link, permission_mailing_send_document
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
ModelPermission.register(
|
|
||||||
model=UserMailer, permissions=(
|
|
||||||
permission_acl_edit, permission_acl_view,
|
|
||||||
permission_user_mailer_delete, permission_user_mailer_edit,
|
|
||||||
permission_user_mailer_view, permission_user_mailer_use
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
app.conf.task_queues.append(
|
app.conf.task_queues.append(
|
||||||
Queue('mailing', Exchange('mailing'), routing_key='mailing'),
|
Queue('mailing', Exchange('mailing'), routing_key='mailing'),
|
||||||
)
|
)
|
||||||
@@ -106,7 +118,9 @@ class MailerApp(MayanAppConfig):
|
|||||||
|
|
||||||
menu_list_facet.bind_links(
|
menu_list_facet.bind_links(
|
||||||
links=(
|
links=(
|
||||||
link_acl_list, link_user_mailer_log_list,
|
link_acl_list, link_events_for_object,
|
||||||
|
link_object_event_types_user_subcriptions_list,
|
||||||
|
link_user_mailer_log_list,
|
||||||
), sources=(UserMailer,)
|
), sources=(UserMailer,)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -142,3 +156,5 @@ class MailerApp(MayanAppConfig):
|
|||||||
menu_tools.bind_links(links=(link_system_mailer_error_log,))
|
menu_tools.bind_links(links=(link_system_mailer_error_log,))
|
||||||
|
|
||||||
menu_setup.bind_links(links=(link_user_mailer_setup,))
|
menu_setup.bind_links(links=(link_user_mailer_setup,))
|
||||||
|
|
||||||
|
registry.register(UserMailer)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.events import EventTypeNamespace
|
||||||
|
|
||||||
|
namespace = EventTypeNamespace(name='mailing', label=_('Mailing'))
|
||||||
|
|
||||||
|
event_email_sent = namespace.add_event_type(
|
||||||
|
name='email_send', label=_('Email sent')
|
||||||
|
)
|
||||||
@@ -12,6 +12,7 @@ from django.utils.html import strip_tags
|
|||||||
from django.utils.module_loading import import_string
|
from django.utils.module_loading import import_string
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from .events import event_email_sent
|
||||||
from .managers import UserMailerManager
|
from .managers import UserMailerManager
|
||||||
from .utils import split_recipient_list
|
from .utils import split_recipient_list
|
||||||
|
|
||||||
@@ -126,7 +127,7 @@ class UserMailer(models.Model):
|
|||||||
|
|
||||||
return super(UserMailer, self).save(*args, **kwargs)
|
return super(UserMailer, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def send(self, to, subject='', body='', attachments=None):
|
def send(self, to, subject='', body='', attachments=None, _user=None):
|
||||||
"""
|
"""
|
||||||
Send a simple email. There is no document or template knowledge.
|
Send a simple email. There is no document or template knowledge.
|
||||||
attachments is a list of dictionaries with the keys:
|
attachments is a list of dictionaries with the keys:
|
||||||
@@ -157,8 +158,11 @@ class UserMailer(models.Model):
|
|||||||
self.error_log.create(message=exception)
|
self.error_log.create(message=exception)
|
||||||
else:
|
else:
|
||||||
self.error_log.all().delete()
|
self.error_log.all().delete()
|
||||||
|
event_email_sent.commit(
|
||||||
|
actor=_user, target=self, #action_object=self.document_type
|
||||||
|
)
|
||||||
|
|
||||||
def send_document(self, document, to, subject='', body='', as_attachment=False):
|
def send_document(self, document, to, subject='', body='', as_attachment=False, _user=None):
|
||||||
"""
|
"""
|
||||||
Send a document using this user mailing profile.
|
Send a document using this user mailing profile.
|
||||||
"""
|
"""
|
||||||
@@ -189,7 +193,7 @@ class UserMailer(models.Model):
|
|||||||
|
|
||||||
return self.send(
|
return self.send(
|
||||||
attachments=attachments, body=body_html_content,
|
attachments=attachments, body=body_html_content,
|
||||||
subject=subject_text, to=to,
|
subject=subject_text, to=to, user=user
|
||||||
)
|
)
|
||||||
|
|
||||||
def test(self, to):
|
def test(self, to):
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
from mayan.celery import app
|
from mayan.celery import app
|
||||||
|
|
||||||
|
|
||||||
@app.task(ignore_result=True)
|
@app.task(ignore_result=True)
|
||||||
def task_send_document(body, sender, subject, recipient, user_mailer_id, as_attachment=False, document_id=None):
|
def task_send_document(body, sender, subject, recipient, user_mailer_id, as_attachment=False, document_id=None, user_id=None):
|
||||||
Document = apps.get_model(
|
Document = apps.get_model(
|
||||||
app_label='documents', model_name='Document'
|
app_label='documents', model_name='Document'
|
||||||
)
|
)
|
||||||
UserMailer = apps.get_model(
|
UserMailer = apps.get_model(
|
||||||
app_label='mailer', model_name='UserMailer'
|
app_label='mailer', model_name='UserMailer'
|
||||||
)
|
)
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
if document_id:
|
if document_id:
|
||||||
document = Document.objects.get(pk=document_id)
|
document = Document.objects.get(pk=document_id)
|
||||||
@@ -20,8 +22,12 @@ def task_send_document(body, sender, subject, recipient, user_mailer_id, as_atta
|
|||||||
document = None
|
document = None
|
||||||
|
|
||||||
user_mailer = UserMailer.objects.get(pk=user_mailer_id)
|
user_mailer = UserMailer.objects.get(pk=user_mailer_id)
|
||||||
|
if user_id:
|
||||||
|
user = User.objects.get(pk=user_id)
|
||||||
|
else:
|
||||||
|
user = None
|
||||||
|
|
||||||
user_mailer.send_document(
|
user_mailer.send_document(
|
||||||
as_attachment=as_attachment, body=body, document=document,
|
as_attachment=as_attachment, body=body, document=document,
|
||||||
subject=subject, to=recipient
|
subject=subject, to=recipient, _user=user
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ class MailDocumentView(MultipleObjectFormActionView):
|
|||||||
'sender': self.request.user.email,
|
'sender': self.request.user.email,
|
||||||
'subject': form.cleaned_data['subject'],
|
'subject': form.cleaned_data['subject'],
|
||||||
'user_mailer_id': form.cleaned_data['user_mailer'].pk,
|
'user_mailer_id': form.cleaned_data['user_mailer'].pk,
|
||||||
|
'user_id': self.request.user.pk,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from .links import (
|
|||||||
class TaskManagerApp(MayanAppConfig):
|
class TaskManagerApp(MayanAppConfig):
|
||||||
app_namespace = 'task_manager'
|
app_namespace = 'task_manager'
|
||||||
app_url = 'task_manager'
|
app_url = 'task_manager'
|
||||||
has_tests = True
|
has_tests = False
|
||||||
name = 'mayan.apps.task_manager'
|
name = 'mayan.apps.task_manager'
|
||||||
verbose_name = _('Task manager')
|
verbose_name = _('Task manager')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user