import tornado.locale
from . import base
+from . import bugtracker
from .decorators import *
return list(sessions)
+ # Bugzilla
+
+ async def connect_to_bugzilla(self, api_key):
+ bz = bugtracker.Bugzilla(self.backend, api_key)
+
+ # Does the API key match with this user?
+ if not self.email == await bz.whoami():
+ raise ValueError("The API key does not belong to %s" % self)
+
+ self._set_attribute("bugzilla_api_key", api_key)
+
+ @lazy_property
+ def bugzilla(self):
+ """
+ Connection to Bugzilla as this user
+ """
+ if self.data.bugzilla_api_key:
+ return bugtracker.Bugzilla(self.backend, self.data.bugzilla_api_key)
+
# Quota
def get_quota(self):
admin boolean DEFAULT false NOT NULL,
quota bigint,
perms text[] DEFAULT ARRAY[]::text[] NOT NULL,
- _attrs bytea
+ _attrs bytea,
+ bugzilla_api_key text
);
self.render("users/edit.html", user=user)
@tornado.web.authenticated
- def post(self, name):
+ async def post(self, name):
user = self.backend.users.get_by_name(name)
if not user:
raise tornado.web.HTTPError(404, "Could not find user %s" % name)
raise tornado.web.HTTPError(403)
with self.db.transaction():
- pass
+ # Connect to Bugzilla
+ bugzilla_api_key = self.get_argument("bugzilla_api_key", None)
+ if bugzilla_api_key:
+ await user.connect_to_bugzilla(bugzilla_api_key)
self.redirect("/users/%s" % user.name)