Browse Source

allow to activate/desactivate email sending in .ini file (with parameter email.notification.activated = true/false)

Damien ACCORSI 10 years ago
parent
commit
259490ac37

+ 2 - 1
README.md View File

272
 
272
 
273
 The main parameters for notifications are the following ones:
273
 The main parameters for notifications are the following ones:
274
 
274
 
275
+    email.notification.activated = true
275
     email.notification.from = Tracim Notification <tracim@tmycompany.com>
276
     email.notification.from = Tracim Notification <tracim@tmycompany.com>
276
     email.notification.smtp.server = smtp.mycompany.com
277
     email.notification.smtp.server = smtp.mycompany.com
277
     email.notification.smtp.port = 25
278
     email.notification.smtp.port = 25
359
 
360
 
360
 Building the community is a work in progress.
361
 Building the community is a work in progress.
361
 
362
 
362
-Need help ? Do not hesitate to contact me : damien.accorsi@free.fr
363
+Need help ? Do not hesitate to contact me : damien.accorsi@free.fr

+ 1 - 0
tracim/development.ini.base View File

127
 # integrated in the email notifcations
127
 # integrated in the email notifcations
128
 website.base_url = http://127.0.0.1:8080
128
 website.base_url = http://127.0.0.1:8080
129
     
129
     
130
+email.notification.activated = False
130
 email.notification.from = Tracim Notification <noreply@trac.im>
131
 email.notification.from = Tracim Notification <noreply@trac.im>
131
 email.notification.content_update.template.html = ./tracim/templates/mail/content_update_body_html.mak
132
 email.notification.content_update.template.html = ./tracim/templates/mail/content_update_body_html.mak
132
 email.notification.content_update.template.text = ./tracim/templates/mail/content_update_body_text.mak
133
 email.notification.content_update.template.text = ./tracim/templates/mail/content_update_body_text.mak

+ 3 - 0
tracim/tracim/config/app_cfg.py View File

14
 """
14
 """
15
 
15
 
16
 import tg
16
 import tg
17
+from paste.deploy.converters import asbool
18
+
17
 from tg.configuration import AppConfig
19
 from tg.configuration import AppConfig
18
 from tgext.pluggable import plug
20
 from tgext.pluggable import plug
19
 from tgext.pluggable import replace_template
21
 from tgext.pluggable import replace_template
211
         self.EMAIL_NOTIFICATION_PROCESSING_MODE = tg.config.get('email.notification.processing_mode')
213
         self.EMAIL_NOTIFICATION_PROCESSING_MODE = tg.config.get('email.notification.processing_mode')
212
 
214
 
213
 
215
 
216
+        self.EMAIL_NOTIFICATION_ACTIVATED = asbool(tg.config.get('email.notification.activated'))
214
         self.EMAIL_NOTIFICATION_SMTP_SERVER = tg.config.get('email.notification.smtp.server')
217
         self.EMAIL_NOTIFICATION_SMTP_SERVER = tg.config.get('email.notification.smtp.server')
215
         self.EMAIL_NOTIFICATION_SMTP_PORT = tg.config.get('email.notification.smtp.port')
218
         self.EMAIL_NOTIFICATION_SMTP_PORT = tg.config.get('email.notification.smtp.port')
216
         self.EMAIL_NOTIFICATION_SMTP_USER = tg.config.get('email.notification.smtp.user')
219
         self.EMAIL_NOTIFICATION_SMTP_USER = tg.config.get('email.notification.smtp.user')

+ 8 - 4
tracim/tracim/lib/email.py View File

24
     this class allow to send emails and has no relations with SQLAlchemy and other tg HTTP request environment
24
     this class allow to send emails and has no relations with SQLAlchemy and other tg HTTP request environment
25
     This means that it can be used in any thread (even through a asyncjob_perform() call
25
     This means that it can be used in any thread (even through a asyncjob_perform() call
26
     """
26
     """
27
-    def __init__(self, config: SmtpConfiguration):
27
+    def __init__(self, config: SmtpConfiguration, really_send_messages):
28
         self._smtp_config = config
28
         self._smtp_config = config
29
         self._smtp_connection = None
29
         self._smtp_connection = None
30
+        self._is_active = really_send_messages
30
 
31
 
31
     def connect(self):
32
     def connect(self):
32
         if not self._smtp_connection:
33
         if not self._smtp_connection:
52
 
53
 
53
 
54
 
54
     def send_mail(self, message: MIMEMultipart):
55
     def send_mail(self, message: MIMEMultipart):
55
-        self.connect() # Acutally, this connects to SMTP only if required
56
-        logger.info(self, 'Sending email to {}'.format(message['To']))
57
-        self._smtp_connection.send_message(message)
56
+        if not self._is_active:
57
+            logger.info(self, 'Not sending email to {} (service desactivated)'.format(message['To']))
58
+        else:
59
+            self.connect() # Acutally, this connects to SMTP only if required
60
+            logger.info(self, 'Sending email to {}'.format(message['To']))
61
+            self._smtp_connection.send_message(message)

+ 6 - 0
tracim/tracim/lib/helpers.py View File

64
   Shared = '<i class="fa fa-group"></i>'
64
   Shared = '<i class="fa fa-group"></i>'
65
   Private = '<i class="fa fa-key"></i>'
65
   Private = '<i class="fa fa-key"></i>'
66
 
66
 
67
+def show_email_stuff():
68
+    """
69
+    this function is used in order to show/hide link for sending password reset through email
70
+    """
71
+    return CFG.get_instance().EMAIL_NOTIFICATION_ACTIVATED
72
+
67
 def tracker_js():
73
 def tracker_js():
68
     return CFG.get_instance().TRACKER_JS_CONTENT
74
     return CFG.get_instance().TRACKER_JS_CONTENT
69
 
75
 

+ 1 - 1
tracim/tracim/lib/notifications.py View File

126
         # In the other thread.
126
         # In the other thread.
127
         #
127
         #
128
         # This way, the webserver will return sooner (actually before notification emails are sent
128
         # This way, the webserver will return sooner (actually before notification emails are sent
129
-        async_email_sender = EmailSender(self._smtp_config)
129
+        async_email_sender = EmailSender(self._smtp_config, self._global_config.EMAIL_NOTIFICATION_ACTIVATED)
130
 
130
 
131
         for role in notifiable_roles:
131
         for role in notifiable_roles:
132
             logger.info(self, 'Sending email to {}'.format(role.user.email))
132
             logger.info(self, 'Sending email to {}'.format(role.user.email))

+ 5 - 4
tracim/tracim/templates/index.mak View File

49
                                 <button type="submit" class="btn btn-small btn-success text-right">
49
                                 <button type="submit" class="btn btn-small btn-success text-right">
50
                                     <i class="fa fa-check"></i> ${_('Login')}
50
                                     <i class="fa fa-check"></i> ${_('Login')}
51
                                 </button>
51
                                 </button>
52
-                                <div class="pull-left">
53
-                                    <a class="btn btn-link" href="${tg.url('/reset_password')}"><i class="fa fa-magic"></i> ${_('Forgot password?')}</a>
54
-                                </div>
55
-
52
+                                % if h.show_email_stuff():
53
+                                    <div class="pull-left">
54
+                                        <a class="btn btn-link" href="${tg.url('/reset_password')}"><i class="fa fa-magic"></i> ${_('Forgot password?')}</a>
55
+                                    </div>
56
+                                % endif
56
                             </div>
57
                             </div>
57
                         </form>
58
                         </form>
58
                     </div>
59
                     </div>