Repository: privacyidea/privacyidea

Issue:
Allow tags in subject of email notifications
The Notification Event Handler should also allow to use tags in the email subject.

We should simply allow the same tags as in the body (well - obviously an image tag will not work ;-)


Discussion:

Resolving patch:
diff --git a/privacyidea/lib/eventhandler/usernotification.py b/privacyidea/lib/eventhandler/usernotification.py
--- a/privacyidea/lib/eventhandler/usernotification.py
+++ b/privacyidea/lib/eventhandler/usernotification.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 #
+#  2018-05-07 Cornelius Kölbel <cornelius.koelbel@netknights.it>
+#             Use tags in email subject.
 #  2017-10-27 Cornelius Kölbel <cornelius.koelbel@netknights.it>
 #             Add additional tags for notification: date, time, client_ip,
 #             ua_string, ua_browser
@@ -269,6 +271,8 @@ def do(self, action, options=None):
         if recipient:
             # Collect all data
             body = handler_options.get("body") or DEFAULT_BODY
+            subject = handler_options.get("subject") or \
+                      "An action was performed on your token."
             serial = request.all_data.get("serial") or \
                      content.get("detail", {}).get("serial") or \
                      g.audit_object.audit_data.get("serial")
@@ -288,38 +292,36 @@ def do(self, action, options=None):
 
             time = datetime.datetime.now().strftime("%H:%M:%S")
             date = datetime.datetime.now().strftime("%Y-%m-%d")
-            body = body.format(
-                admin=logged_in_user.get("username"),
-                realm=logged_in_user.get("realm"),
-                action=request.path,
-                serial=serial,
-                url=request.url_root,
-                user=tokenowner.info.get("givenname"),
-                surname=tokenowner.info.get("surname"),
-                givenname=recipient.get("givenname"),
-                username=tokenowner.login,
-                userrealm=tokenowner.realm,
-                tokentype=tokentype,
-                registrationcode=registrationcode,
-                recipient_givenname=recipient.get("givenname"),
-                recipient_surname=recipient.get("surname"),
-                googleurl_img=googleurl_img,
-                googleurl_value=googleurl_value,
-                time=time,
-                date=date,
-                client_ip=g.client_ip,
-                ua_browser=request.user_agent.browser,
-                ua_string=request.user_agent.string
-            )
-
+            tags = dict(admin=logged_in_user.get("username"),
+                        realm=logged_in_user.get("realm"),
+                        action=request.path,
+                        serial=serial,
+                        url=request.url_root,
+                        user=tokenowner.info.get("givenname"),
+                        surname=tokenowner.info.get("surname"),
+                        givenname=recipient.get("givenname"),
+                        username=tokenowner.login,
+                        userrealm=tokenowner.realm,
+                        tokentype=tokentype,
+                        registrationcode=registrationcode,
+                        recipient_givenname=recipient.get("givenname"),
+                        recipient_surname=recipient.get("surname"),
+                        googleurl_value=googleurl_value,
+                        time=time,
+                        date=date,
+                        client_ip=g.client_ip,
+                        ua_browser=request.user_agent.browser,
+                        ua_string=request.user_agent.string)
+            body = body.format(googleurl_img=googleurl_img,
+                               **tags)
+            subject = subject.format(**tags)
             # Send notification
             if action.lower() == "sendmail":
                 emailconfig = handler_options.get("emailconfig")
                 mimetype = handler_options.get("mimetype", "plain")
                 useremail = recipient.get("email")
                 reply_to = handler_options.get("reply_to")
-                subject = handler_options.get("subject") or \
-                          "An action was performed on your token."
+
                 try:
                     ret = send_email_identifier(emailconfig,
                                                 recipient=useremail,


Test patch: