]> git.ipfire.org Git - pbs.git/commitdiff
users: Give users their own connect to Bugzilla
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 May 2023 10:26:04 +0000 (10:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 May 2023 10:26:04 +0000 (10:26 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/users.py
src/database.sql
src/web/users.py

index 40ca23901d311557efcdebb801f09f8fc12a5705..025a0cc17508d473f6a4b7f75b8037bdca538910 100644 (file)
@@ -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):
index 52657065192d459ce1add33e50585c7abe6b1875..cd266de249089adf532cf1fd20a5d968ecbd67dd 100644 (file)
@@ -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
 );
 
 
index 59b31bd43ed47bcc79ff60e1bd4abcac5c001ff2..80842991c060d97fa75356751ad02c330df57dee 100644 (file)
@@ -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)