Skip to content

Commit

Permalink
use path_to_foo() functions instead of hand-crafted relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin J. Mitchell committed Feb 14, 2010
1 parent 63e2d5d commit 2df1cae
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion buildbot/status/web/authz.py
Expand Up @@ -30,7 +30,7 @@
# This usually looks something like
#
# if not self.getAuthz(req).actionAllowed('myNewTrick', req, someExtraArg):
# return Redirect("../../authfail") # double-check this path!
# return Redirect(path_to_authfail(req))
#
# the someExtraArg is optional (it's handled with *args, so you can have
# several if you want), and is given to the user's authorization function.
Expand Down
3 changes: 3 additions & 0 deletions buildbot/status/web/base.py
Expand Up @@ -97,6 +97,9 @@ def path_to_root(request):
root = "../" * segs
return root

def path_to_authfail(request):
return path_to_root(request) + "/authfail"

def path_to_builder(request, builderstatus):
return (path_to_root(request) +
"builders/" +
Expand Down
10 changes: 5 additions & 5 deletions buildbot/status/web/build.py
Expand Up @@ -8,7 +8,7 @@
from twisted.python import log
from buildbot.status.web.base import HtmlResource, \
css_classes, path_to_build, path_to_builder, path_to_slave, \
getAndCheckProperties
getAndCheckProperties, path_to_authfail

from buildbot.status.web.step import StepsResource
from buildbot import util, interfaces
Expand Down Expand Up @@ -135,7 +135,7 @@ def stop(self, req, auth_ok=False):
# check if this is allowed
if not auth_ok:
if not self.getAuthz(req).actionAllowed('stopBuild', req, self.build_status):
return Redirect("../../../../authfail")
return Redirect(path_to_authfail(req))

b = self.build_status
log.msg("web stopBuild of build %s:%s" % \
Expand All @@ -155,15 +155,15 @@ def stop(self, req, auth_ok=False):

# we're at http://localhost:8080/svn-hello/builds/5/stop?[args] and
# we want to go to: http://localhost:8080/svn-hello
r = Redirect("../..")
r = Redirect(path_to_builder(req, self.build_status.getBuilder()))
d = defer.Deferred()
reactor.callLater(1, d.callback, r)
return DeferredResource(d)

def rebuild(self, req):
# check auth
if not self.getAuthz(req).actionAllowed('forceBuild', req, self.build_status.getBuilder()):
return Redirect("../../../../authfail")
return Redirect(path_to_authfail(req))

# get a control object
c = interfaces.IControl(self.getBuildmaster(req))
Expand Down Expand Up @@ -194,7 +194,7 @@ def rebuild(self, req):
# evidence of their build starting (or to see the reason that it
# didn't start). This should be the Builder page.

r = Redirect('../..') # the Builder's page
r = Redirect(path_to_builder(req, self.build_status.getBuilder()))
d = defer.Deferred()
reactor.callLater(1, d.callback, r)
return DeferredResource(d)
Expand Down
28 changes: 14 additions & 14 deletions buildbot/status/web/builder.py
Expand Up @@ -9,7 +9,7 @@
from buildbot.status.web.base import HtmlResource, BuildLineMixin, \
path_to_build, path_to_slave, path_to_builder, path_to_change, \
path_to_root, getAndCheckProperties, ICurrentBox, build_get_class, \
map_branches
map_branches, path_to_authfail
from buildbot.process.base import BuildRequest
from buildbot.sourcestamp import SourceStamp

Expand Down Expand Up @@ -121,19 +121,19 @@ def force(self, req, auth_ok=False):
if not auth_ok:
if not self.getAuthz(req).actionAllowed('forceBuild', req, self.builder_status):
log.msg("..but not authorized")
return Redirect("../../authfail")
return Redirect(path_to_authfail(req))

# keep weird stuff out of the branch revision, and property strings.
# TODO: centralize this somewhere.
if not re.match(r'^[\w\.\-\/]*$', branch):
log.msg("bad branch '%s'" % branch)
return Redirect("..")
return Redirect(path_to_builder(req, self.builder_status))
if not re.match(r'^[\w\.\-\/]*$', revision):
log.msg("bad revision '%s'" % revision)
return Redirect("..")
return Redirect(path_to_builder(req, self.builder_status))
properties = getAndCheckProperties(req)
if properties is None:
return Redirect("..")
return Redirect(path_to_builder(req, self.builder_status))
if not branch:
branch = None
if not revision:
Expand All @@ -158,18 +158,18 @@ def force(self, req, auth_ok=False):
# honored
pass
# send the user back to the builder page
return Redirect(".")
return Redirect(path_to_builder(req, self.builder_status))

def ping(self, req):
log.msg("web ping of builder '%s'" % self.builder_status.getName())
if not self.getAuthz(req).actionAllowed('pingBuilder', req, self.builder_status):
log.msg("..but not authorized")
return Redirect("../../authfail")
return Redirect(path_to_authfail(req))
c = interfaces.IControl(self.getBuildmaster(req))
bc = c.getBuilder(self.builder_status.getName())
bc.ping()
# send the user back to the builder page
return Redirect(".")
return Redirect(path_to_builder(req, self.builder_status))

def cancelbuild(self, req):
try:
Expand All @@ -192,10 +192,10 @@ def cancelbuild(self, req):
if authz.actionAllowed('cancelPendingBuild', req, build_req):
build_req.cancel()
else:
return Redirect("../../authfail")
return Redirect(path_to_authfail(req))
if not cancel_all:
break
return Redirect(".")
return Redirect(path_to_builder(req, self.builder_status))

def getChild(self, path, req):
if path == "force":
Expand Down Expand Up @@ -228,19 +228,19 @@ def getChild(self, path, req):
def forceall(self, req):
authz = self.getAuthz(req)
if not authz.actionAllowed('forceAllBuilds', req):
return Redirect("../../authfail");
return Redirect(path_to_authfail(req))

for bname in self.status.getBuilderNames():
builder_status = self.status.getBuilder(bname)
build = StatusResourceBuilder(builder_status)
build.force(req, auth_ok=True) # auth_ok because we already checked
# back to the welcome page
return Redirect("../..")
return Redirect(path_to_root(req))

def stopall(self, req):
authz = self.getAuthz(req)
if not authz.actionAllowed('stopAllBuilds', req):
return Redirect("../../authfail");
return Redirect(path_to_authfail(req))

for bname in self.status.getBuilderNames():
builder_status = self.status.getBuilder(bname)
Expand All @@ -254,7 +254,7 @@ def stopall(self, req):
build = StatusResourceBuild(build_status)
build.stop(req, auth_ok=True)
# go back to the welcome page
return Redirect("../..")
return Redirect(path_to_root(req))


# /builders
Expand Down
4 changes: 2 additions & 2 deletions buildbot/status/web/slaves.py
Expand Up @@ -5,7 +5,7 @@
from twisted.web.error import NoResource

from buildbot.status.web.base import HtmlResource, abbreviate_age, \
BuildLineMixin, path_to_slave
BuildLineMixin, path_to_slave, path_to_authfail
from buildbot import util

# /buildslaves/$slavename
Expand All @@ -25,7 +25,7 @@ def getChild(self, path, req):
if self.getAuthz(req).actionAllowed("gracefulShutdown", req, slave):
slave.setGraceful(True)
else:
return Redirect("../../authfail")
return Redirect(path_to_authfail(req))
return Redirect(path_to_slave(req, slave))

def content(self, request, ctx):
Expand Down

0 comments on commit 2df1cae

Please sign in to comment.