From: Michael Tremer Date: Mon, 15 May 2023 10:26:04 +0000 (+0000) Subject: users: Give users their own connect to Bugzilla X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8550381874ed016ba133dd4258811b6c137b687;p=pbs.git users: Give users their own connect to Bugzilla Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/users.py b/src/buildservice/users.py index 40ca2390..025a0cc1 100644 --- a/src/buildservice/users.py +++ b/src/buildservice/users.py @@ -10,6 +10,7 @@ import time import tornado.locale from . import base +from . import bugtracker from .decorators import * @@ -469,6 +470,25 @@ class User(base.DataObject): 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): diff --git a/src/database.sql b/src/database.sql index 52657065..cd266de2 100644 --- a/src/database.sql +++ b/src/database.sql @@ -1123,7 +1123,8 @@ CREATE TABLE public.users ( admin boolean DEFAULT false NOT NULL, quota bigint, perms text[] DEFAULT ARRAY[]::text[] NOT NULL, - _attrs bytea + _attrs bytea, + bugzilla_api_key text ); diff --git a/src/web/users.py b/src/web/users.py index 59b31bd4..80842991 100644 --- a/src/web/users.py +++ b/src/web/users.py @@ -63,7 +63,7 @@ class EditHandler(base.BaseHandler): 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) @@ -73,7 +73,10 @@ class EditHandler(base.BaseHandler): 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)