Making REMOTE_USER available in hgweb templates
FZiegler
zarf at klacto.net
Tue Sep 14 04:28:08 CDT 2010
Hi,
I wanted to make REMOTE_USER (when defined) available in hgweb templates
I found this possible with the patch below, which exposes it as {user}.
I'd love to know if there is a better way (through configuration rather
than patching, say) -- but so far as I could see & gather on irc, that
may not currently be the case, other than by rather massive monkey
patching of hgweb_mod.hgweb.templater & hgwebdir_mod.hgwebdir.templater.
If that is confirmed, would you consider taking this change or something
like it? Would {remoteuser} or perhaps {remote_user} be preferable? I
took 'user' since hgwebdir already has user = req.env.get('REMOTE_USER')
in the read_allowed method (currently hgwebdir_mod.py, line 116).
Thanks for any advice you may have here,
Francois Z.
diff -r 20f011311212 mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py Sat Sep 11 16:17:43 2010 -0500
+++ b/mercurial/hgweb/hgweb_mod.py Tue Sep 14 04:19:31 2010 -0400
@@ -217,6 +217,7 @@
proto = 'http'
default_port = "80"
+ user = req.env.get('REMOTE_USER', '')
port = req.env["SERVER_PORT"]
port = port != default_port and (":" + port) or ""
urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
@@ -261,6 +262,7 @@
defaults={"url": req.url,
"staticurl": staticurl,
"urlbase": urlbase,
+ "user": user,
"repo": self.reponame,
"header": header,
"footer": footer,
diff -r 20f011311212 mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py Sat Sep 11 16:17:43 2010 -0500
+++ b/mercurial/hgweb/hgwebdir_mod.py Tue Sep 14 04:19:31 2010 -0400
@@ -310,6 +310,7 @@
self.updatereqenv(req.env)
+ user = req.env.get('REMOTE_USER', '')
url = req.env.get('SCRIPT_NAME', '')
if not url.endswith('/'):
url += '/'
@@ -334,6 +335,7 @@
defaults={"header": header,
"footer": footer,
"motd": motd,
+ "user": user,
"url": url,
"staticurl": staticurl,
"sessionvars": sessionvars})
More information about the Mercurial-devel
mailing list