Coverage for portality/notifications/application_emails.py: 26%

38 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-08-04 15:38 +0100

1# ~~ Email:Notifications~~ 

2from flask import url_for 

3import json 

4 

5from portality import models, app_email, constants 

6from portality.core import app 

7from portality.dao import Facetview2 

8from portality.ui.messages import Messages 

9from portality.lib import dates 

10 

11 

12def send_editor_completed_email(application): 

13 """ inform the editor in charge of an application that it has been completed by an associate editor """ 

14 journal_name = application.bibjson().title 

15 url_root = app.config.get("BASE_URL") 

16 query_for_id = Facetview2.make_query(query_string=application.id) 

17 string_id_query = json.dumps(query_for_id).replace(' ', '') # Avoid '+' being added to URLs by removing spaces 

18 url_for_application = url_root + url_for("editor.group_suggestions", source=string_id_query) 

19 

20 # This is to the editor in charge of this application's assigned editor group 

21 editor_group_name = application.editor_group 

22 editor_group_id = models.EditorGroup.group_exists_by_name(name=editor_group_name) 

23 editor_group = models.EditorGroup.pull(editor_group_id) 

24 editor_acc = editor_group.get_editor_account() 

25 

26 editor_id = editor_acc.id 

27 to = [editor_acc.email] 

28 fro = app.config.get('SYSTEM_EMAIL_FROM', 'helpdesk@doaj.org') 

29 subject = app.config.get("SERVICE_NAME", "") + " - application marked 'completed'" 

30 

31 # The status change will have come from the associate editor assigned to the journal 

32 assoc_id = application.editor 

33 

34 app_email.send_mail(to=to, 

35 fro=fro, 

36 subject=subject, 

37 template_name="email/editor_application_completed.jinja2", 

38 editor=editor_id, 

39 associate_editor=assoc_id, 

40 application_title=journal_name, 

41 url_for_application=url_for_application) 

42 

43 

44def send_account_created_email(account): 

45 reset_url = url_for('account.reset', reset_token=account.reset_token, _external=True) 

46 forgot_pw_url = url_for('account.forgot', _external=True) 

47 

48 password_create_timeout_seconds = int( 

49 app.config.get("PASSWORD_CREATE_TIMEOUT", app.config.get('PASSWORD_RESET_TIMEOUT', 86400) * 14)) 

50 password_create_timeout_days = password_create_timeout_seconds / (60 * 60 * 24) 

51 

52 to = [account.email] 

53 fro = app.config.get('SYSTEM_EMAIL_FROM', 'helpdesk@doaj.org') 

54 subject = app.config.get("SERVICE_NAME", "") + " - account created, please verify your email address" 

55 

56 app_email.send_mail(to=to, 

57 fro=fro, 

58 subject=subject, 

59 template_name="email/account_created.jinja2", 

60 reset_url=reset_url, 

61 email=account.email, 

62 timeout_days=password_create_timeout_days, 

63 forgot_pw_url=forgot_pw_url 

64 ) 

65 

66 

67def send_account_password_reset_email(account): 

68 reset_url = url_for('account.reset', reset_token=account.reset_token, _external=True) 

69 

70 to = [account.email] 

71 fro = app.config.get('SYSTEM_EMAIL_FROM', app.config['ADMIN_EMAIL']) 

72 subject = app.config.get("SERVICE_NAME", "") + " - password reset" 

73 

74 app_email.send_mail(to=to, 

75 fro=fro, 

76 subject=subject, 

77 template_name="email/account_password_reset.jinja2", 

78 email=account.email, 

79 reset_url=reset_url, 

80 forgot_pw_url=url_for('account.forgot', _external=True) 

81 )