1.1 --- a/MoinMessageSupport.py Tue Nov 12 23:05:52 2013 +0100
1.2 +++ b/MoinMessageSupport.py Wed Nov 13 15:42:06 2013 +0100
1.3 @@ -246,4 +246,25 @@
1.4
1.5 return getWikiDict(subpage, request)
1.6
1.7 +def get_username_for_fingerprint(request, fingerprint):
1.8 +
1.9 + """
1.10 + Using the 'request', return the username corresponding to the given key
1.11 + 'fingerprint' or None if no correspondence is present in the mapping page.
1.12 + """
1.13 +
1.14 + gpg_users = getWikiDict(
1.15 + getattr(request.cfg, "moinmessage_gpg_users_page", "MoinMessageUserDict"),
1.16 + request,
1.17 + superuser=True # disable user test because we have no user yet
1.18 + )
1.19 +
1.20 + # With a user mapping and a fingerprint corresponding to a known
1.21 + # user, temporarily switch user in order to make the edit.
1.22 +
1.23 + if gpg_users and gpg_users.has_key(fingerprint):
1.24 + return gpg_users[fingerprint]
1.25 + else:
1.26 + return None
1.27 +
1.28 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/MoinMoin/auth/pgp.py Tue Nov 12 23:05:52 2013 +0100
2.2 +++ b/MoinMoin/auth/pgp.py Wed Nov 13 15:42:06 2013 +0100
2.3 @@ -14,10 +14,10 @@
2.4
2.5 from MoinMoin.user import User
2.6 from MoinMoin.auth import BaseAuth
2.7 -from MoinSupport import getHeader, getWikiDict
2.8 +from MoinSupport import getHeader
2.9 from MoinMessage import GPG, is_signed, is_encrypted, \
2.10 MoinMessageDecodingError, MoinMessageError
2.11 -from MoinMessageSupport import get_homedir
2.12 +from MoinMessageSupport import get_homedir, get_username_for_fingerprint
2.13 from email.parser import Parser
2.14
2.15 try:
2.16 @@ -117,17 +117,12 @@
2.17 # Evaluate the result of the verification process.
2.18
2.19 if fingerprint:
2.20 - gpg_users = getWikiDict(
2.21 - getattr(request.cfg, "moinmessage_gpg_users_page", "MoinMessageUserDict"),
2.22 - request,
2.23 - superuser=True # disable user test because we have no user yet
2.24 - )
2.25 + username = get_username_for_fingerprint(request, fingerprint)
2.26
2.27 - # With a user mapping and a fingerprint corresponding to a known
2.28 - # user, temporarily switch user in order to make the edit.
2.29 + # With a known username, temporarily switch user in order to make
2.30 + # the edit.
2.31
2.32 - if gpg_users and gpg_users.has_key(fingerprint):
2.33 - username = gpg_users[fingerprint]
2.34 + if username:
2.35 user = User(request, auth_method="pgp", auth_username=username)
2.36 logging.debug("username: %r" % username)
2.37
3.1 --- a/actions/PostMessage.py Tue Nov 12 23:05:52 2013 +0100
3.2 +++ b/actions/PostMessage.py Wed Nov 13 15:42:06 2013 +0100
3.3 @@ -51,10 +51,21 @@
3.4 whether it will be placed in a message store.
3.5 """
3.6
3.7 + request = self.request
3.8 +
3.9 # Handle the different update actions.
3.10 # Update a message store for the page.
3.11
3.12 if to_store(update):
3.13 +
3.14 + # Add any authenticated user.
3.15 + # Note that where messages are signed by the real author, encrypted,
3.16 + # and then signed for sending, the authenticated user here is not
3.17 + # the real author.
3.18 +
3.19 + if request.user and request.user.valid:
3.20 + update["Moin-User"] = request.user.name
3.21 +
3.22 self.store.append(update.as_string())
3.23
3.24 # Update the page.
3.25 @@ -78,12 +89,12 @@
3.26 if not replace:
3.27 body.append(self.page.get_raw_body())
3.28
3.29 - page_editor = PageEditor(self.request, self.pagename)
3.30 + page_editor = PageEditor(request, self.pagename)
3.31 page_editor.saveText("\n\n".join(body), 0)
3.32
3.33 # Refresh the page.
3.34
3.35 - self.page = Page(self.request, self.pagename)
3.36 + self.page = Page(request, self.pagename)
3.37
3.38 # Action function.
3.39