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.inlineCallbacks
28 - def performAction(self, req):
29 res = yield self.getAuthz(req).actionAllowed('showUsersPage', req) 30 if not res: 31 defer.returnValue(path_to_authzfail(req)) 32 return 33 # show the table 34 defer.returnValue(path_to_root(req) + "users")
35
36 # /users/$uid 37 -class OneUserResource(HtmlResource):
38 addSlash = False
39 - def __init__(self, uid):
40 HtmlResource.__init__(self) 41 self.uid = int(uid)
42
43 - def getPageTitle (self, req):
44 return "Buildbot User: %s" % self.uid
45
46 - def content(self, request, ctx):
47 status = self.getStatus(request) 48 49 d = status.master.db.users.getUser(self.uid) 50 def cb(usdict): 51 ctx['user_identifier'] = usdict['identifier'] 52 user = ctx['user'] = {} 53 for attr in usdict: 54 if attr not in ['uid', 'identifier', 'bb_password']: 55 user[attr] = usdict[attr] 56 57 template = request.site.buildbot_service.templates.get_template("user.html") 58 data = template.render(**ctx) 59 return data
60 d.addCallback(cb) 61 return d
62
63 # /users 64 -class UsersResource(HtmlResource):
65 pageTitle = "Users" 66 addSlash = True 67
68 - def __init__(self):
70
71 - def getChild(self, path, req):
72 return OneUserResource(path)
73 74 @defer.inlineCallbacks
75 - def content(self, req, ctx):
76 res = yield self.getAuthz(req).actionAllowed('showUsersPage', req) 77 if not res: 78 defer.returnValue(redirectTo(path_to_authzfail(req), req)) 79 return 80 81 s = self.getStatus(req) 82 83 usdicts = yield s.master.db.users.getUsers() 84 users = ctx['users'] = usdicts 85 86 for user in users: 87 user['user_link'] = req.childLink(urllib.quote(str(user['uid']), '')) 88 template = req.site.buildbot_service.templates.get_template( 89 "users.html") 90 defer.returnValue(template.render(**ctx))
91