# HG changeset patch # User Paul Boddie # Date 1374439315 -7200 # Node ID f3b08f6e6dd0f8b7e27875e638768a44a89bdc2b # Parent 73962101d40715f4f499ca4f920116b15d8a5573 Moved WikiDict access functions to the support library for other actions to use. diff -r 73962101d407 -r f3b08f6e6dd0 MoinMessageSupport.py --- a/MoinMessageSupport.py Sun Jul 21 22:40:31 2013 +0200 +++ b/MoinMessageSupport.py Sun Jul 21 22:41:55 2013 +0200 @@ -197,4 +197,36 @@ return getattr(request.cfg, "moinmessage_gpg_homedir") +def get_signing_users(request): + + "Return a dictionary mapping usernames to signing keys." + + return getWikiDict( + getattr(request.cfg, "moinmessage_gpg_signing_users_page", "MoinMessageSigningUserDict"), + request) + +def get_recipients(request): + + """ + Return the recipients dictionary by first obtaining the page in which it + is stored. This page may either be a subpage of the user's home page, if + stored on this wiki, or it may be relative to the site root. + + The name of the subpage is defined by the configuration setting + 'moinmessage_gpg_recipients_page', which if absent is set to + "MoinMessageRecipientsDict". + """ + + subpage = getattr(request.cfg, "moinmessage_gpg_recipients_page", "MoinMessageRecipientsDict") + homedetails = wikiutil.getInterwikiHomePage(request) + + if homedetails: + homewiki, homepage = homedetails + if homewiki == "Self": + recipients = getWikiDict("%s/%s" % (homepage, subpage), request) + if recipients: + return recipients + + return getWikiDict(subpage, request) + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 73962101d407 -r f3b08f6e6dd0 actions/SendMessage.py --- a/actions/SendMessage.py Sun Jul 21 22:40:31 2013 +0200 +++ b/actions/SendMessage.py Sun Jul 21 22:41:55 2013 +0200 @@ -12,9 +12,10 @@ from MoinMoin.Page import Page from MoinMoin import config from MoinMessage import GPG, MoinMessageError, Message, sendMessage, timestamp +from MoinMessageSupport import get_signing_users, get_recipients from MoinSupport import * from MoinMoin.wikiutil import escape, MimeType, parseQueryString, \ - taintfilename, getInterwikiHomePage + taintfilename from email.mime.base import MIMEBase from email.mime.image import MIMEImage @@ -69,7 +70,7 @@ # Get a list of potential recipients. - recipients = self.get_recipients() + recipients = get_recipients(request) # Prepare the recipients list, selecting the specified recipients. @@ -271,12 +272,12 @@ # This is not the same as the details for authenticating users in the # PostMessage action since the fingerprints refer to public keys. - signing_users = self.get_signing_users() + signing_users = get_signing_users(request) signer = signing_users and signing_users.get(request.user.name) # Get the recipient details. - recipients = self.get_recipients() + recipients = get_recipients(request) if not recipients: return 0, _("No recipients page is defined for MoinMessage.") @@ -341,37 +342,6 @@ return getattr(self.request.cfg, "moinmessage_gpg_homedir") - def get_recipients(self): - - """ - Return the recipients dictionary by first obtaining the page in which it - is stored. This page may either be a subpage of the user's home page, if - stored on this wiki, or it may be relative to the site root. - - The name of the subpage is defined by the configuration setting - 'moinmessage_gpg_recipients_page', which if absent is set to - "MoinMessageRecipientsDict". - """ - - request = self.request - - subpage = getattr(request.cfg, "moinmessage_gpg_recipients_page", "MoinMessageRecipientsDict") - homedetails = getInterwikiHomePage(request) - - if homedetails: - homewiki, homepage = homedetails - if homewiki == "Self": - recipients = getWikiDict("%s/%s" % (homepage, subpage), request) - if recipients: - return recipients - - return getWikiDict(subpage, request) - - def get_signing_users(self): - return getWikiDict( - getattr(self.request.cfg, "moinmessage_gpg_signing_users_page", "MoinMessageSigningUserDict"), - self.request) - # Special message formatters. def unquoteWikinameURL(url, charset=config.charset):