|
@@ -17,9 +17,12 @@ from tracim_backend.lib.mail_notifier.utils import SmtpConfiguration, EST
|
17
|
17
|
from tracim_backend.lib.mail_notifier.sender import send_email_through
|
18
|
18
|
from tracim_backend.lib.core.workspace import WorkspaceApi
|
19
|
19
|
from tracim_backend.lib.utils.logger import logger
|
20
|
|
-from tracim_backend.models import User
|
|
20
|
+from tracim_backend.lib.utils.utils import get_login_frontend_url
|
|
21
|
+from tracim_backend.lib.utils.utils import get_email_logo_frontend_url
|
21
|
22
|
from tracim_backend.models.auth import User
|
22
|
23
|
from tracim_backend.models.contents import CONTENT_TYPES
|
|
24
|
+from tracim_backend.models.context_models import ContentInContext
|
|
25
|
+from tracim_backend.models.context_models import WorkspaceInContext
|
23
|
26
|
from tracim_backend.models.data import ActionDescription
|
24
|
27
|
from tracim_backend.models.data import Content
|
25
|
28
|
from tracim_backend.models.data import UserRoleInWorkspace
|
|
@@ -234,7 +237,13 @@ class EmailManager(object):
|
234
|
237
|
show_archived=True,
|
235
|
238
|
show_deleted=True,
|
236
|
239
|
).get_one(event_content_id, CONTENT_TYPES.Any_SLUG)
|
237
|
|
- main_content = content.parent if content.type == CONTENT_TYPES.Comment.slug else content
|
|
240
|
+ workspace_api = WorkspaceApi(
|
|
241
|
+ session=self.session,
|
|
242
|
+ current_user=user,
|
|
243
|
+ config=self.config,
|
|
244
|
+ )
|
|
245
|
+ workpace_in_context = workspace_api.get_workspace_with_context(workspace_api.get_one(content.workspace_id)) # nopep8
|
|
246
|
+ main_content = content.parent if content.type == CONTENT_TYPES.Comment.slug else content # nopep8
|
238
|
247
|
notifiable_roles = WorkspaceApi(
|
239
|
248
|
current_user=user,
|
240
|
249
|
session=self.session,
|
|
@@ -265,7 +274,7 @@ class EmailManager(object):
|
265
|
274
|
# INFO - G.M - 2017-11-15 - set content_id in header to permit reply
|
266
|
275
|
# references can have multiple values, but only one in this case.
|
267
|
276
|
replyto_addr = self.config.EMAIL_NOTIFICATION_REPLY_TO_EMAIL.replace( # nopep8
|
268
|
|
- '{content_id}',str(content.content_id)
|
|
277
|
+ '{content_id}', str(content.content_id)
|
269
|
278
|
)
|
270
|
279
|
|
271
|
280
|
reference_addr = self.config.EMAIL_NOTIFICATION_REFERENCES_EMAIL.replace( #nopep8
|
|
@@ -297,8 +306,21 @@ class EmailManager(object):
|
297
|
306
|
# To link this email to a content we create a virtual parent
|
298
|
307
|
# in reference who contain the content_id.
|
299
|
308
|
message['References'] = formataddr(('',reference_addr))
|
300
|
|
- body_text = self._build_email_body_for_content(self.config.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_TEXT, role, content, user)
|
301
|
|
- body_html = self._build_email_body_for_content(self.config.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_HTML, role, content, user)
|
|
309
|
+ content_in_context = content_api.get_content_in_context(content)
|
|
310
|
+ body_text = self._build_email_body_for_content(
|
|
311
|
+ self.config.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_TEXT,
|
|
312
|
+ role,
|
|
313
|
+ content_in_context,
|
|
314
|
+ workpace_in_context,
|
|
315
|
+ user
|
|
316
|
+ )
|
|
317
|
+ body_html = self._build_email_body_for_content(
|
|
318
|
+ self.config.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_HTML,
|
|
319
|
+ role,
|
|
320
|
+ content_in_context,
|
|
321
|
+ workpace_in_context,
|
|
322
|
+ user
|
|
323
|
+ )
|
302
|
324
|
|
303
|
325
|
part1 = MIMEText(body_text, 'plain', 'utf-8')
|
304
|
326
|
part2 = MIMEText(body_html, 'html', 'utf-8')
|
|
@@ -362,9 +384,9 @@ class EmailManager(object):
|
362
|
384
|
'user': user,
|
363
|
385
|
'password': password,
|
364
|
386
|
# TODO - G.M - 11-06-2018 - [emailTemplateURL] correct value for logo_url # nopep8
|
365
|
|
- 'logo_url': '',
|
|
387
|
+ 'logo_url': get_email_logo_frontend_url(self.config),
|
366
|
388
|
# TODO - G.M - 11-06-2018 - [emailTemplateURL] correct value for login_url # nopep8
|
367
|
|
- 'login_url': self.config.WEBSITE_BASE_URL,
|
|
389
|
+ 'login_url': get_login_frontend_url(self.config),
|
368
|
390
|
}
|
369
|
391
|
body_text = self._render_template(
|
370
|
392
|
mako_template_filepath=text_template_file_path,
|
|
@@ -415,8 +437,9 @@ class EmailManager(object):
|
415
|
437
|
self,
|
416
|
438
|
mako_template_filepath: str,
|
417
|
439
|
role: UserRoleInWorkspace,
|
418
|
|
- content: Content,
|
419
|
|
- actor: User
|
|
440
|
+ content_in_context: ContentInContext,
|
|
441
|
+ workspace_in_context: WorkspaceInContext,
|
|
442
|
+ actor: User,
|
420
|
443
|
) -> str:
|
421
|
444
|
"""
|
422
|
445
|
Build an email body and return it as a string
|
|
@@ -424,24 +447,21 @@ class EmailManager(object):
|
424
|
447
|
:param role: the role related to user to whom the email must be sent. The role is required (and not the user only) in order to show in the mail why the user receive the notification
|
425
|
448
|
:param content: the content item related to the notification
|
426
|
449
|
:param actor: the user at the origin of the action / notification (for example the one who wrote a comment
|
427
|
|
- :param config: the global configuration
|
428
|
450
|
:return: the built email body as string. In case of multipart email, this method must be called one time for text and one time for html
|
429
|
451
|
"""
|
430
|
452
|
logger.debug(self, 'Building email content from MAKO template {}'.format(mako_template_filepath))
|
431
|
|
-
|
|
453
|
+ content = content_in_context.content
|
432
|
454
|
main_title = content.label
|
433
|
455
|
content_intro = ''
|
434
|
456
|
content_text = ''
|
435
|
457
|
call_to_action_text = ''
|
436
|
458
|
|
437
|
|
- # TODO - G.M - 11-06-2018 - [emailTemplateURL] correct value for call_to_action_url # nopep8
|
438
|
|
- call_to_action_url =''
|
|
459
|
+ call_to_action_url = content_in_context.frontend_url
|
439
|
460
|
# TODO - G.M - 11-06-2018 - [emailTemplateURL] correct value for status_icon_url # nopep8
|
440
|
461
|
status_icon_url = ''
|
441
|
|
- # TODO - G.M - 11-06-2018 - [emailTemplateURL] correct value for workspace_url # nopep8
|
442
|
|
- workspace_url = ''
|
|
462
|
+ workspace_url = workspace_in_context.frontend_url
|
443
|
463
|
# TODO - G.M - 11-06-2018 - [emailTemplateURL] correct value for logo_url # nopep8
|
444
|
|
- logo_url = ''
|
|
464
|
+ logo_url = get_email_logo_frontend_url(self.config)
|
445
|
465
|
|
446
|
466
|
action = content.get_last_action().id
|
447
|
467
|
if ActionDescription.COMMENT == action:
|