Commits

Scott Parkerson  committed 614c0a5

1. Merge SMTP + Notification plugin into notification plugin
2. Update cfgs to not call SMTP plugin in wizard mode
3. Disable SMTP plugin

  • Participants
  • Parent commits dba78d9

Comments (0)

Files changed (5)

 server.webpath="/rAA"
 
 # Wizard plugins to run in this order.
-wizard.plugins = ["/changepassword/ChangePassword", "/configure/SmtpConf", "/configure/Notify", "/configure/Network", "/configure/Proxy", "/configure/Entitlements", "/backup/Backup"]
+wizard.plugins = ["/changepassword/ChangePassword", "/configure/Notify", "/configure/Network", "/configure/Proxy", "/configure/Entitlements", "/backup/Backup"]
 
 [logging]
 

File raa/config/app.cfg

 plugins.extraConfigDir = "/etc/raa/plugins.d/"
 
 # Disabled plugins
-plugins.disable = []
+plugins.disable = ['/configure/RootPw', '/configure/SmtpConf']
 
 # Wizard plugins to run in this order.
-wizard.plugins = ["/changepassword/ChangePassword", "/configure/SmtpConf", "/configure/Notify", "/configure/Network", "/configure/Proxy", "/configure/Entitlements", "/backup/Backup"]
+wizard.plugins = ["/changepassword/ChangePassword", "/configure/Notify", "/configure/Network", "/configure/Proxy", "/configure/Entitlements", "/backup/Backup"]
 
 # VISIT TRACKING
 # Each visit to your application will be assigned a unique visit ID tracked via

File raaplugins/configure/notify.kid

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<?python import raa.templates.master ?>
+<?python
+import raa.templates.master
+from raa.templates.editablelistwidget import EditableListWidget 
+?>
 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
     py:extends="raa.templates.master">
 
     All Rights Reserved
 -->
 
+
 <head>
     <script type="text/javascript" src="${tg.url('/static/javascript/list.js')}"></script>
     <title>Configure Notification</title>
-
-<script type="text/javascript">
-
-// Initialize the notification email list.
-function initList(listEmails)
-{
-  dlist = new UltraDynamicList("dlist", "notEmailList");
-  dlist.msgBlank = "Add a new email address to notify.";
-  dlist.msgNormal = "Add another email address.";
-
-  dlist.validateEditing = function()
-  {
-    var val = this.listItems[this.indexEditing];
-    var err = validateEmail(val);
-    if(err) {
-      return err;
-    }
-
-    var listOthers = this.listItems.slice();
-    listOthers.splice(this.indexEditing, 1);
-    err = arrayContains(val, listOthers);
-    if(err) {
-      return "Duplicate email."
-    }
-
-    return null;
-  };
-
-  dlist.displayError = function(err)
-  {
-    displayMessageBox(err, "error");
-  };
-
-  dlist.clearError = function()
-  {
-    clearMessageBox();
-  };
-
-  dlist.drawAdd = function(indexOk)
-  {
-    hideElement("submit");
-    UltraDynamicList.prototype.drawAdd.call(this, indexOk);
-  };
-
-  dlist.drawList = function()
-  {
-    showElement("submit");
-    UltraDynamicList.prototype.drawList.call(this);
-  };
-
-  if(null != listEmails) {
-    dlist.listItems = listEmails;
-  }
-
-  dlist.drawList();
-}
-
-</script>
-
 </head>
 
-<body onload="initList(${emails}); dlist.itemAdd();">
+    <script type="text/javascript">
+        <![CDATA[
+            var emailList = new EditableList();
+            addLoadEvent(emailList.init);
+        ]]>
+    </script>
+
+<body>
 	<?python
 	instructions = "Configure email relay server and mail originator address by entering the hostname for a valid email server. Then enter any email addresses to receive notifications about " + tg.config('product.productName') + " events."
 	?>
 	<div py:replace="display_instructions(instructions, False)"></div>
-	
 	<div class="plugin-page" id="plugin-page">
 		<img class="float-left" src="${tg.url('/static/images/page_top_left.png')}" alt="" />
-	    <img class="float-right" src="${tg.url('/static/images/page_top_right.png')}" alt="" />
+                <img class="float-right" src="${tg.url('/static/images/page_top_right.png')}" alt="" />
 		<div class="page-content">
+         <form name="page_form" onsubmit="javascript:postFormWizardRedirectOnSuccess(this, 'save');">
 
-         <form name="page_form" action="javascript:void(0);" method="POST" onsubmit="javascript:postFormWizardRedirectOnSuccess(this, 'mailUpdate');">
         <a class="rnd_button float-right" href="javascript:button_submit(document.page_form)">Save</a>
         <div class="page-section">
 		1. Relay Server Configuration
            
             
 			<div class="form-line-top">
-				<div class="smtp-label">Mail Relay Server:</div> <input id="mailRelay"  type="text" name="mailRelay" value="" /><!--${mailRelay}-->
+                            <div class="smtp-label">Mail Relay Server:</div> <input id="mailRelay" type="text" name="mailRelay" value="${mailRelay}" />
 			</div>
 			<div class="form-line">
-				<div class="smtp-label">Send Mail From:</div> <input id="mailFrom" type="text" name="mailFrom" value=""/><!--${mailFrom}-->
+                            <div class="smtp-label">Send Mail From:</div> <input id="mailFrom" type="text" name="mailFrom" value="${mailFrom}" />
 			</div>
 		</div>
-        </form>
-        
-        <form name="email" action="javascript:void(0);" method="POST" onsubmit="javascript:replaceChildNodes('notHiddenInput', INPUT({'type': 'hidden', 'name': 'emails', 'value': dlist.getItems()}, null)); postFormWizardRedirectOnSuccess(this, 'notifySave');">
 
         <div class="page-section">
 		2. Notification Addresses
             </div>
             
             <div class="form-line">
-            <table class="email_addresses">
-            <tr py:if="0"><!--dlist.getItems() -->
-                <td colspan="2">No Notifications Registered</td>
-            </tr>
-            <tr ><!-- py:for="index, email in enumerate(dlist.getItems())" -->
-				<td><input name="email_" type="text" value=""/></td><!-- ${index} ${email} -->
-				<td class="button-column"><a href="">[ delete ]</a></td>
-			</tr>
-            <tr>
-                <td><a href="javascript:dlist.itemAdd();">[ add email ]</a></td>
-            </tr>
-    		</table>
+                ${EditableListWidget(emails, itemName="email address", variableName="emails")}
             </div>
         </div>
 

File raaplugins/configure/web/notify.py

 
     taskType = [
         { "shortDescription" : _("save notification"),
-          "longDescription" : _("Save the new list of email addresses notifications should be sent to.") },
+          "longDescription" : _("Save the notification configuration including the SMTP configuration as well as the email addresses to send notifications to. ") },
     ]
 
+
+    def _validateMailserver(self, mailRelay=None, mailFrom=None):
+        errors = []
+        if not raa.lib.validate.validateEmail(mailFrom):
+            errors.append("%s: %s; " % (_("Invalid email address"), mailFrom))
+        return errors
+
+    def _validateEmailAddresses(self, emails=[]):
+        errors = []
+        for em in emails:
+            if not raa.lib.validate.validateEmail(em):
+                errors.append("%s: %s; " % (_("Invalid email address"), em))
+        return errors
+
+    def _getMailserver(self):
+        # Retrieve the SMTP configuration
+        (exists, mailRelay) = cherrypy.root.configuration.getValue(
+            constants.Config.EMAIL_RELAY)
+        mailRelay = exists and mailRelay or ''
+
+        (exists, mailFrom) = exists and cherrypy.root.configuration.getValue(
+            constants.Config.EMAIL_FROM_ADDRESS) or (False, "")
+        mailFrom = exists and mailFrom or ''
+
+        return (mailRelay, mailFrom)
+
+    def _getEmailAddresses(self):
+        # Retrieve the emails.
+        (exists, emails) = cherrypy.root.configuration.getValue(
+            constants.Config.NOTIFY_EMAILS)
+        if not exists or "" == emails.strip():
+            listEmails = []
+        else:
+            listEmails = emails.split(",")
+
+        return listEmails
+
+    def _saveMailserver(self, mailRelay, mailFrom):
+        mailRelay = mailRelay.strip()
+        mailFrom = mailFrom.strip()
+        cherrypy.root.configuration.setValue(
+            constants.Config.EMAIL_RELAY, mailRelay)
+        cherrypy.root.configuration.setValue(
+            constants.Config.EMAIL_FROM_ADDRESS, mailFrom)
+
+    def _saveEmailAddresses(self, emails):
+        # emails are currently stored as a comma-separated list of values
+        emailStr = ','.join(emails)
+        cherrypy.root.configuration.setValue(
+            constants.Config.NOTIFY_EMAILS, emailStr)
+
     @raa.web.expose(allow_xmlrpc=True, template="raaplugins.configure.notify")
     def index(self):
         """
         @return: email addresses.
         """
 
-        # Retrieve the emails.
-        (exists, emails) = cherrypy.root.configuration.getValue(
-            constants.Config.NOTIFY_EMAILS)
-        if not exists or "" == emails.strip():
-            listEmails = []
-        else:
-            listEmails = emails.split(",")
+        emails = self._getEmailAddresses()
+        mailRelay, mailFrom = self._getMailserver()
+        return dict(emails=emails, mailRelay=mailRelay,
+                mailFrom=mailFrom)
 
-        return dict(emails=listEmails)
-
+    # DEPRECATED; use save below
     @raa.web.expose(allow_xmlrpc=True, allow_json=True)
     def notifySave(self, emails):
         """
         Save the new list of email addresses notifications should be sent to.
-        @type emails: string of emails delimited by commas
+        This call has been deprecated. Use "save" instead.
+        @type emails: list of emails (list obj or string separated by commas)
         @param emails: email addresses.
         @rtype: dictionary
         @return: mapping containing success message or errors.
         """
 
-        errors = None
-        message = None
-        if "" != emails.strip():
-            for em in emails.split(","):
-                if not raa.lib.validate.validateEmail(em):
-                    errors = (errors or "") \
-                        + "%s: %s; " % (_("Invalid email address"), em)
-        if None == errors:
-            cherrypy.root.configuration.setValue(
-                constants.Config.NOTIFY_EMAILS, emails)
-            message = _("Configuration saved.")
+        mailRelay, mailFrom = self._getMailServer()
+        return self.save(mailRelay=mailRelay, mailFrom=mailFrom, emails=emails)
+
+    @raa.web.expose(allow_xmlrpc=True, allow_json=True)
+    def mailUpdate(self, mailRelay = None, mailFrom = None):
+        """
+        Save the Email-related variables.
+        This call has been deprecated. Use "save" instead.
+        @type mailRelay: string
+        @param mailRelay: SMTP server.
+        @type mailFrom: string
+        @param mailFrom: originating email address.
+        """
+
+        emails = self._getEmailAddresses()
+        return self.save(mailRelay=mailRelay, mailFrom=mailFrom, emails=emails)
+
+    @raa.web.expose(allow_xmlrpc=True, allow_json=True)
+    def save(self, mailRelay=None, mailFrom=None, emails=[]):
+        """
+        Save the Email notification related variables.
+        @type mailRelay: string
+        @param mailRelay: SMTP server
+        @type mailFrom: string
+        @param mailFrom: originating email address
+        @type emails: list or comma-separated string
+        @param emails: email addresses to notify
+        """
+        errors = []
+        ret = dict()
+
+        # strip trailing whitespace from all input
+        # also, normalize email addresses to a list
+        emailList = []
+        if emails:
+            if isinstance(emails, str):
+                emails = emails.strip()
+                emailList = [x.strip() for x in emails.split(',')]
+            elif isinstance(emails, list):
+                emailList = [x.strip() for x in emails]
+            else:
+                errors.append("%s: %s" % (_('Invalid type passed when expecting string or list'), emails))
+
+        errors.extend(self._validateMailserver(mailRelay, mailFrom))
+        errors.extend(self._validateEmailAddresses(emailList))
+
+        if not errors:
+            self._saveMailserver(mailRelay, mailFrom)
+            self._saveEmailAddresses(emailList)
+            ret.update(message=_("Notification configuration saved"))
             self.wizardDone()
-            return dict(message=message)
         else:
-            return dict(errors=errors)
+            ret.update(errors=errors)
+
+        return ret

File raaplugins/configure/web/smtpconf.py

           "longDescription" : _("Save the Email-related variables.") },
     ]
 
+    # DEPRECATED; use /configure/Notify instead
     @raa.web.expose(allow_xmlrpc=True, template="raaplugins.configure.smtp")
     def index(self):
         """
         @return: mapping containing the SMTP server and the originating email
             address.
         """
-        (exists, mailRelay) = cherrypy.root.configuration.getValue(
-            constants.Config.EMAIL_RELAY)
-        (exists, mailFrom) = exists and cherrypy.root.configuration.getValue(
-            constants.Config.EMAIL_FROM_ADDRESS) or (False, "")
-        if not exists:
-            mailRelay = ""
-            mailFrom = ""
+        ret = self.plugins['/configure/Notify'].index()
+        return dict(mailRelay=ret.get('mailRelay',''),
+                    mailFrom=ret.get('mailFrom',''))
 
-        return dict(mailRelay=mailRelay, mailFrom=mailFrom)
-
+    # DEPRECATED; use /configure/Notify instead
     @raa.web.expose(allow_xmlrpc=True, allow_json=True)
     def mailUpdate(self, mailRelay = None, mailFrom = None):
         """
         @param mailFrom: originating email address.
         """
 
-        errors = None
-        message = None
-        ret = dict()
-        if None != mailRelay and None != mailFrom:
-            # Validate the email address.
-            if not raa.lib.validate.validateEmail(mailFrom):
-                errors = "%s: %s" % (_("Invalid email address"), mailFrom)
-            else:
-                mailRelay = mailRelay.strip()
-                mailFrom = mailFrom.strip()
-                cherrypy.root.configuration.setValue(
-                    constants.Config.EMAIL_RELAY, mailRelay)
-                cherrypy.root.configuration.setValue(
-                    constants.Config.EMAIL_FROM_ADDRESS, mailFrom)
-                ret.update(message=_("Email configuration saved."))
-
-        if None == errors:
-            self.wizardDone()
-        else:
-            ret.update(errors=errors)
-
-        return ret
+        return self.plugins['/configure/Notify'].mailUpdate(mailRelay,
+                mailFrom)