Attachment 'patch-homeprefix-setting-5819_51e0575a1ee9.diff'
Download 1 # HG changeset patch
2 # User Paul Boddie <paul@boddie.org.uk>
3 # Date 1318183386 -7200
4 # Node ID 51e0575a1ee9907dd24da95c2951fce145a36518
5 # Parent 89882824b375c0afe55433de0e5ccc081a740c82
6 Added support for home page namespaces other than at the root of a site by
7 employing a homeprefix setting.
8 Changed the serveopenid action, autoadmin security policy, MyPages action and
9 the OpenID identity advertising in the Page class to work with home pages that
10 have a non-empty homeprefix.
11 Added various utility functions to work with page names.
12 Handle a result of None, possible when running a maintenance script or when no
13 user is logged in.
14 (Consolidated patch from 5782, 5816 and 5818.)
15
16 diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/Page.py
17 --- a/MoinMoin/Page.py Wed Aug 03 00:07:16 2011 +0200
18 +++ b/MoinMoin/Page.py Sun Oct 09 20:03:06 2011 +0200
19 @@ -1137,8 +1137,14 @@
20
21 html_head = ''
22 if request.cfg.openid_server_enabled:
23 - openid_username = self.page_name
24 - userid = user.getUserId(request, openid_username)
25 + pagenames = wikiutil.splitPageName(self.page_name)
26 + prefix = wikiutil.joinPageNames(*pagenames[:-1])
27 + if prefix == request.cfg.user_homeprefix:
28 + openid_username = pagenames[-1]
29 + userid = user.getUserId(request, openid_username)
30 + else:
31 + openid_username = None
32 + userid = None
33
34 if userid is None and 'openid.user' in self.pi:
35 openid_username = self.pi['openid.user']
36 @@ -1373,7 +1379,11 @@
37 _ = request.getText
38
39 if special_type == 'missing':
40 - if request.user.valid and request.user.name == self.page_name and \
41 + pagenames = wikiutil.splitPageName(self.page_name)
42 + prefix = wikiutil.joinPageNames(*pagenames[:-1])
43 +
44 + if request.user.valid and request.user.name == pagenames[-1] and \
45 + request.cfg.user_homeprefix == prefix and \
46 request.cfg.user_homewiki in ('Self', request.cfg.interwikiname):
47 page = wikiutil.getLocalizedPage(request, 'MissingHomePage')
48 else:
49 diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/action/MyPages.py
50 --- a/MoinMoin/action/MyPages.py Wed Aug 03 00:07:16 2011 +0200
51 +++ b/MoinMoin/action/MyPages.py Sun Oct 09 20:03:06 2011 +0200
52 @@ -30,7 +30,7 @@
53 homepageurl = wikiutil.join_wiki(wikiurl, wikitail)
54 request.http_redirect('%s?action=MyPages' % homepageurl)
55
56 - homepage = Page(request, username)
57 + homepage = Page(request, wikiutil.joinPageNames(request.cfg.user_homeprefix, username))
58 if not homepage.exists():
59 request.theme.add_msg(_('Please first create a homepage before creating additional pages.'), "error")
60 return homepage.send_page()
61 diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/action/serveopenid.py
62 --- a/MoinMoin/action/serveopenid.py Wed Aug 03 00:07:16 2011 +0200
63 +++ b/MoinMoin/action/serveopenid.py Sun Oct 09 20:03:06 2011 +0200
64 @@ -172,7 +172,13 @@
65 request = self.request
66 form = request.values
67
68 - username = request.page.page_name
69 + pagenames = wikiutil.splitPageName(request.page.page_name)
70 + prefix = wikiutil.joinPageNames(*pagenames[:-1])
71 + if prefix == request.cfg.user_homeprefix:
72 + username = pagenames[-1]
73 + else:
74 + username = None
75 +
76 if 'openid.user' in request.page.pi:
77 username = request.page.pi['openid.user']
78
79 diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/config/multiconfig.py
80 --- a/MoinMoin/config/multiconfig.py Wed Aug 03 00:07:16 2011 +0200
81 +++ b/MoinMoin/config/multiconfig.py Sun Oct 09 20:03:06 2011 +0200
82 @@ -1171,6 +1171,8 @@
83
84 ('homewiki', u'Self',
85 "interwiki name of the wiki where the user home pages are located [Unicode] - useful if you have ''many'' users. You could even link to nonwiki \"user pages\" if the wiki username is in the target URL."),
86 + ('homeprefix', u'',
87 + "name of the page under which user home pages are stored [Unicode] - this page can itself be a subpage of another page; set to the empty string for the normal top-level home page behaviour."),
88
89 ('checkbox_fields',
90 [
91 diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/security/autoadmin.py
92 --- a/MoinMoin/security/autoadmin.py Wed Aug 03 00:07:16 2011 +0200
93 +++ b/MoinMoin/security/autoadmin.py Sun Oct 09 20:03:06 2011 +0200
94 @@ -62,6 +62,7 @@
95 from MoinMoin.security import Permissions
96 from MoinMoin.Page import Page
97 from MoinMoin.PageEditor import PageEditor
98 +from MoinMoin import wikiutil
99
100 class SecurityPolicy(Permissions):
101 """ Extend the default security policy with autoadmin feature """
102 @@ -72,9 +73,20 @@
103 groups = request.groups
104 username = request.user.name
105 pagename = request.page.page_name
106 +
107 + # test admin rights on the user's own home page
108 + homedetails = wikiutil.getInterwikiHomePage(request, username)
109 +
110 + if homedetails is not None:
111 + homewiki, homepage = homedetails
112 +
113 + if homewiki == "Self" and \
114 + (pagename == homepage or wikiutil.isSubPage(pagename, homepage)) and \
115 + username in groups.get(u'AutoAdminGroup', []):
116 + return True
117 +
118 + # test admin rights for the user on group pages
119 mainpage = pagename.split('/')[0]
120 - if username == mainpage and username in groups.get(u'AutoAdminGroup', []):
121 - return True
122 group_name = "%s/AdminGroup" % mainpage
123 if (username in groups.get(group_name, []) and
124 group_name in groups.get(u'AutoAdminGroup', [])):
125 @@ -87,19 +99,23 @@
126 request = self.request
127 username = request.user.name
128 pagename = editor.page_name
129 + homedetails = wikiutil.getInterwikiHomePage(request, username)
130
131 - if grouppage_autocreate and username == pagename:
132 - # create group pages when a user saves his own homepage
133 - for page in grouppages:
134 - grouppagename = "%s/%s" % (username, page)
135 - grouppage = Page(request, grouppagename)
136 - if not grouppage.exists():
137 - text = """\
138 + if homedetails is not None:
139 + homewiki, homepage = homedetails
140 +
141 + if grouppage_autocreate and homewiki == "Self" and pagename == homepage:
142 + # create group pages when a user saves his own homepage
143 + for page in grouppages:
144 + grouppagename = "%s/%s" % (homepage, page)
145 + grouppage = Page(request, grouppagename)
146 + if not grouppage.exists():
147 + text = """\
148 #acl %(username)s:read,write,delete,revert
149 * %(username)s
150 """ % locals()
151 - editor = PageEditor(request, grouppagename)
152 - editor._write_file(text)
153 + editor = PageEditor(request, grouppagename)
154 + editor._write_file(text)
155
156 parts = pagename.split('/')
157 if len(parts) == 2:
158 diff -r 89882824b375 -r 51e0575a1ee9 MoinMoin/wikiutil.py
159 --- a/MoinMoin/wikiutil.py Wed Aug 03 00:07:16 2011 +0200
160 +++ b/MoinMoin/wikiutil.py Sun Oct 09 20:03:06 2011 +0200
161 @@ -737,7 +737,7 @@
162 # known user?
163 if username:
164 # Return home page
165 - page = Page(request, username)
166 + page = Page(request, joinPageNames(request.cfg.user_homeprefix, username))
167 if page.exists():
168 return page
169
170 @@ -769,8 +769,40 @@
171 if homewiki == request.cfg.interwikiname:
172 homewiki = u'Self'
173
174 - return homewiki, username
175 + return homewiki, joinPageNames(request.cfg.user_homeprefix, username)
176
177 +def joinPageNames(*pagenames):
178 + """
179 + Join the given page names to construct a complete absolute page name.
180 +
181 + @param pagenames: the page names which construct the complete name
182 + @return: the absolute page name
183 + """
184 +
185 + pagenames = [name for name in pagenames if name]
186 + return u'/'.join(pagenames)
187 +
188 +def splitPageName(pagename):
189 + """
190 + Split the given page name into a hierarchy of pages.
191 +
192 + @param pagename: an absolute page name with potentially many parts
193 + @return: a list of page names
194 + """
195 +
196 + return pagename.split(u'/')
197 +
198 +def isSubPage(pagename, parent):
199 + """
200 + Return whether the given page name is a subpage of the potential parent
201 + page.
202 +
203 + @param pagename: a page name to be tested as a potential subpage
204 + @param parent: a potential parent page
205 + @return: a boolean value indicating whether pagename is a subpage of parent
206 + """
207 +
208 + return pagename.startswith("%s/" % parent)
209
210 def AbsPageName(context, pagename):
211 """
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.