Package buildbot :: Package status :: Package web :: Module users
[frames] | no frames]

Source Code for Module buildbot.status.web.users

  1  # This file is part of Buildbot.  Buildbot is free software: you can 
  2  # redistribute it and/or modify it under the terms of the GNU General Public 
  3  # License as published by the Free Software Foundation, version 2. 
  4  # 
  5  # This program is distributed in the hope that it will be useful, but WITHOUT 
  6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  8  # details. 
  9  # 
 10  # You should have received a copy of the GNU General Public License along with 
 11  # this program; if not, write to the Free Software Foundation, Inc., 51 
 12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 13  # 
 14  # Copyright Buildbot Team Members 
 15   
 16  import urllib 
 17  from twisted.internet import defer 
 18  from twisted.web.util import redirectTo 
 19  from buildbot.status.web.base import HtmlResource, path_to_authzfail, \ 
 20      path_to_root, ActionResource 
21 22 -class UsersActionResource(ActionResource):
23
24 - def __init__(self):
25 self.action = "showUsersPage"
26 27 @defer.deferredGenerator
28 - def performAction(self, req):
29 d = self.getAuthz(req).actionAllowed('showUsersPage', req) 30 wfd = defer.waitForDeferred(d) 31 yield wfd 32 res = wfd.getResult() 33 if not res: 34 yield path_to_authzfail(req) 35 return 36 # show the table 37 yield path_to_root(req) + "users"
38
39 # /users/$uid 40 -class OneUserResource(HtmlResource):
41 addSlash = False
42 - def __init__(self, uid):
43 HtmlResource.__init__(self) 44 self.uid = int(uid)
45
46 - def getPageTitle (self, req):
47 return "Buildbot User: %s" % self.uid
48
49 - def content(self, request, ctx):
50 status = self.getStatus(request) 51 52 d = status.master.db.users.getUser(self.uid) 53 def cb(usdict): 54 ctx['user_identifier'] = usdict['identifier'] 55 user = ctx['user'] = {} 56 for attr in usdict: 57 if attr not in ['uid', 'identifier', 'bb_password']: 58 user[attr] = usdict[attr] 59 60 template = request.site.buildbot_service.templates.get_template("user.html") 61 data = template.render(**ctx) 62 return data
63 d.addCallback(cb) 64 return d
65
66 # /users 67 -class UsersResource(HtmlResource):
68 pageTitle = "Users" 69 addSlash = True 70
71 - def __init__(self):
73
74 - def getChild(self, path, req):
75 return OneUserResource(path)
76 77 @defer.deferredGenerator
78 - def content(self, req, ctx):
79 d = self.getAuthz(req).actionAllowed('showUsersPage', req) 80 wfd = defer.waitForDeferred(d) 81 yield wfd 82 res = wfd.getResult() 83 if not res: 84 yield redirectTo(path_to_authzfail(req), req) 85 return 86 87 s = self.getStatus(req) 88 89 d = s.master.db.users.getUsers() 90 wfd = defer.waitForDeferred(d) 91 yield wfd 92 usdicts = wfd.getResult() 93 94 users = ctx['users'] = usdicts 95 for user in users: 96 user['user_link'] = req.childLink(urllib.quote(str(user['uid']), '')) 97 template = req.site.buildbot_service.templates.get_template( 98 "users.html") 99 yield template.render(**ctx)
100