Back to index

moin  1.9.0~rc2
UpdateGroup.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - Wiki XMLRPC group creation
00004 
00005     @copyright: 2005-2006 Bastian Blank, Florian Festi, Thomas Waldmann
00006     @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 import sys, xmlrpclib
00010 
00011 from MoinMoin import log
00012 logging = log.getLogger(__name__)
00013 
00014 from MoinMoin.PageEditor import PageEditor
00015 
00016 def execute(self, groupname, groupcomment, memberlist, pageacls=u"All:read"):
00017     """
00018     create or overwrite a group definition page
00019     @param groupname: the page name of the group definition page (unicode or utf-8)
00020                       must match the page_group_regex or it won't have effect
00021     @param memberlist: the group members (unicode or utf-8)
00022     @param pageacls: the ACLs to use for the group page (defaults to u"All:read")
00023     @rtype: bool
00024     @return: true on success
00025     """
00026 
00027     pagename = self._instr(groupname)
00028 
00029     # also check ACLs
00030     if not self.request.user.may.write(pagename):
00031         return xmlrpclib.Fault(1, "You are not allowed to edit this page")
00032 
00033     # check if groupname matches page_group_regex
00034     if not self.request.cfg.cache.page_group_regexact.search(groupname):
00035         return xmlrpclib.Fault(2, "The groupname %s does not match your page_group_regex (%s)" % (
00036                                groupname, self.request.cfg.page_group_regex))
00037 
00038     newtext = """\
00039 #acl %(acl)s
00040 %(comment)s
00041 %(memberlist)s
00042 """ % {
00043     'acl': pageacls,
00044     'comment': groupcomment,
00045     'memberlist': "\n * ".join([''] + memberlist)
00046     }
00047 
00048     page = PageEditor(self.request, pagename)
00049     try:
00050         msg = page.saveText(newtext, 0)
00051     except page.SaveError, msg:
00052         logging.error("SaveError msg: %s" % str(msg))
00053         return xmlrpclib.Fault(3, msg)
00054     if msg:
00055         logging.debug("saveText msg: %s" % msg)
00056 
00057     #we need this to update pagelinks cache:
00058     #self.request.args = self.request.form = self.request.setup_args()
00059     self.request.redirectedOutput(page.send_page, content_only=1)
00060 
00061     return xmlrpclib.Boolean(1)
00062