Skip to content

Commit e3cd392

Browse files
author
Erik Forsberg
committed
Tell user where to register in mail about user being unknown...
...if tracker allows anonymous web access + user creation.
1 parent 03f117e commit e3cd392

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

roundup/mailgw.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.188 2007-05-12 16:14:54 forsberg Exp $
76+
$Id: mailgw.py,v 1.189 2007-09-01 16:14:21 forsberg Exp $
7777
"""
7878
__docformat__ = 'restructuredtext'
7979

@@ -906,8 +906,18 @@ def handle_message(self, message):
906906
if author == anonid:
907907
# we're anonymous and we need to be a registered user
908908
from_address = from_list[0][1]
909+
registration_info = ""
910+
if self.db.security.hasPermission('Web Access', author) and \
911+
self.db.security.hasPermission('Create', anonid, 'user'):
912+
tracker_web = self.instance.config.TRACKER_WEB
913+
registration_info = """ Please register at:
914+
915+
%(tracker_web)suser?template=register
916+
917+
...before sending mail to the tracker.""" % locals()
918+
909919
raise Unauthorized, _("""
910-
You are not a registered user.
920+
You are not a registered user.%(registration_info)s
911921
912922
Unknown address: %(from_address)s
913923
""") % locals()

test/test_mailgw.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# but WITHOUT ANY WARRANTY; without even the implied warranty of
99
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010
#
11-
# $Id: test_mailgw.py,v 1.85 2007-02-15 03:09:53 richard Exp $
11+
# $Id: test_mailgw.py,v 1.86 2007-09-01 16:14:21 forsberg Exp $
1212

1313
# TODO: test bcc
1414

@@ -766,7 +766,48 @@ def testNewUserAuthor(self):
766766
767767
This is a test submission of a new issue.
768768
'''
769-
self.assertRaises(Unauthorized, self._handle_mail, message)
769+
try:
770+
self._handle_mail(message)
771+
except Unauthorized, value:
772+
body_diff = self.compareMessages(str(value), """
773+
You are not a registered user.
774+
775+
Unknown address: [email protected]
776+
""")
777+
778+
assert not body_diff, body_diff
779+
780+
else:
781+
raise AssertionError, "Unathorized not raised when handling mail"
782+
783+
# Add Web Access role to anonymous, and try again to make sure
784+
# we get a "please register at:" message this time.
785+
p = [
786+
self.db.security.getPermission('Create', 'user'),
787+
self.db.security.getPermission('Web Access', None),
788+
]
789+
790+
self.db.security.role['anonymous'].permissions=p
791+
792+
try:
793+
self._handle_mail(message)
794+
except Unauthorized, value:
795+
body_diff = self.compareMessages(str(value), """
796+
You are not a registered user. Please register at:
797+
798+
http://tracker.example/cgi-bin/roundup.cgi/bugs/user?template=register
799+
800+
...before sending mail to the tracker.
801+
802+
Unknown address: [email protected]
803+
""")
804+
805+
assert not body_diff, body_diff
806+
807+
else:
808+
raise AssertionError, "Unathorized not raised when handling mail"
809+
810+
# Make sure list of users is the same as before.
770811
m = self.db.user.list()
771812
m.sort()
772813
self.assertEqual(l, m)

0 commit comments

Comments
 (0)