notifications.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # coding: utf-8
  2. # nm.debian.org website backend.notifications
  3. #
  4. # Copyright (C) 2013 Marco Bardelli <bardelli.marco@gmail.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. from __future__ import absolute_import
  19. from . import const
  20. from .email import send_notification
  21. def maybe_notify_applicant_on_progress(log, previous_log):
  22. """
  23. Notify applicant via e-mail about progress of this process, if it is interesting.
  24. """
  25. if previous_log is None:
  26. ## this is strange no previous log, do nothing
  27. return
  28. from_progress = previous_log.progress
  29. to_progress = log.progress
  30. ################################################################
  31. # * When they get in the queue to get an AM assigned
  32. # This happens when Process.progress goes from [anything except app_ok]
  33. # to app_ok.
  34. # Use cases:
  35. # - FD may skip any step from initial contact to having things ready
  36. # for AM assignment
  37. # - an AM may get busy and hand an applicant back to FD. That would be
  38. # a transition from any of (am_rcvd, am, am_hold) to app_ok
  39. ################################################################
  40. if from_progress in (const.PROGRESS_APP_NEW,
  41. const.PROGRESS_APP_RCVD,
  42. const.PROGRESS_APP_HOLD,
  43. const.PROGRESS_ADV_RCVD,
  44. const.PROGRESS_POLL_SENT,
  45. const.PROGRESS_AM_RCVD,
  46. const.PROGRESS_AM,
  47. const.PROGRESS_AM_HOLD):
  48. if to_progress == const.PROGRESS_APP_OK:
  49. # mail applicant in the queue to get an AM assigned
  50. send_notification(
  51. "notification_mails/applicant_waiting_for_am.txt",
  52. log, previous_log)
  53. return
  54. ################################################################
  55. # * When an AM is assigned to an applicant
  56. # This happens when Process.progress goes from app_ok to am_rcvd
  57. ################################################################
  58. if from_progress == const.PROGRESS_APP_OK:
  59. if to_progress == const.PROGRESS_AM_RCVD:
  60. # mail applicant in the queue to get an AM assigned
  61. send_notification(
  62. "notification_mails/am_assigned_to_applicant.txt",
  63. log, previous_log)
  64. return
  65. ################################################################
  66. # * When an AM approves the applicant, mail debian-newmaint
  67. # This happens only when Process.progress goes from one of (am_rcvd,
  68. # am, am_hold) to am_ok.
  69. # Use case: the AM can decide to approve an applicant whatever previous
  70. # progress they were in.
  71. # The email shouldn't however be triggered if, for example, FD just
  72. # unholds an application but hasn't finished with their review: that
  73. # would be a (fd_hold -> am_ok) change.
  74. ################################################################
  75. if from_progress in (const.PROGRESS_AM_RCVD,
  76. const.PROGRESS_AM,
  77. const.PROGRESS_AM_HOLD):
  78. if to_progress == const.PROGRESS_AM_OK:
  79. # mail debian-newmaint AM approved Applicant
  80. # with https://lists.debian.org/debian-newmaint/2009/04/msg00026.html
  81. send_notification("notification_mails/am_approved_applicant.txt",
  82. log, previous_log)
  83. return
  84. ################################################################
  85. # * When they get approved by FD
  86. # This happens only when Process.progress goes from one of (am_ok,
  87. # fd_hold) to fd_ok.
  88. ################################################################
  89. if from_progress in (const.PROGRESS_AM_OK,
  90. const.PROGRESS_FD_HOLD):
  91. if to_progress == const.PROGRESS_FD_OK:
  92. # mail applicant in the queue to get an AM assigned
  93. send_notification("notification_mails/fd_approved_applicant.txt",
  94. log, previous_log)
  95. return