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,6 +272,7 @@ The reset password related parameters are the follwoing ones :
272 272
 
273 273
 The main parameters for notifications are the following ones:
274 274
 
275
+    email.notification.activated = true
275 276
     email.notification.from = Tracim Notification <tracim@tmycompany.com>
276 277
     email.notification.smtp.server = smtp.mycompany.com
277 278
     email.notification.smtp.port = 25
@@ -359,4 +360,4 @@ Example of Apache WSGI configuration. This configuration refers to productionapp
359 360
 
360 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,6 +127,7 @@ website.home.below_login_form = in case of problem, please contact the administr
127 127
 # integrated in the email notifcations
128 128
 website.base_url = http://127.0.0.1:8080
129 129
     
130
+email.notification.activated = False
130 131
 email.notification.from = Tracim Notification <noreply@trac.im>
131 132
 email.notification.content_update.template.html = ./tracim/templates/mail/content_update_body_html.mak
132 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,6 +14,8 @@ convert them into boolean, for example, you should use the
14 14
 """
15 15
 
16 16
 import tg
17
+from paste.deploy.converters import asbool
18
+
17 19
 from tg.configuration import AppConfig
18 20
 from tgext.pluggable import plug
19 21
 from tgext.pluggable import replace_template
@@ -211,6 +213,7 @@ class CFG(object):
211 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 217
         self.EMAIL_NOTIFICATION_SMTP_SERVER = tg.config.get('email.notification.smtp.server')
215 218
         self.EMAIL_NOTIFICATION_SMTP_PORT = tg.config.get('email.notification.smtp.port')
216 219
         self.EMAIL_NOTIFICATION_SMTP_USER = tg.config.get('email.notification.smtp.user')

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

@@ -24,9 +24,10 @@ class EmailSender(object):
24 24
     this class allow to send emails and has no relations with SQLAlchemy and other tg HTTP request environment
25 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 28
         self._smtp_config = config
29 29
         self._smtp_connection = None
30
+        self._is_active = really_send_messages
30 31
 
31 32
     def connect(self):
32 33
         if not self._smtp_connection:
@@ -52,6 +53,9 @@ class EmailSender(object):
52 53
 
53 54
 
54 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,6 +64,12 @@ class ICON(object):
64 64
   Shared = '<i class="fa fa-group"></i>'
65 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 73
 def tracker_js():
68 74
     return CFG.get_instance().TRACKER_JS_CONTENT
69 75
 

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

@@ -126,7 +126,7 @@ class EmailNotifier(object):
126 126
         # In the other thread.
127 127
         #
128 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 131
         for role in notifiable_roles:
132 132
             logger.info(self, 'Sending email to {}'.format(role.user.email))

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

@@ -49,10 +49,11 @@
49 49
                                 <button type="submit" class="btn btn-small btn-success text-right">
50 50
                                     <i class="fa fa-check"></i> ${_('Login')}
51 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 57
                             </div>
57 58
                         </form>
58 59
                     </div>