]> git.ipfire.org Git - pbs.git/commitdiff
users: Make custom repositories available
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 25 Jun 2022 14:05:12 +0000 (14:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 25 Jun 2022 14:05:12 +0000 (14:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/distribution.py
src/buildservice/users.py
src/web/__init__.py
src/web/repos.py

index 1a0340ab3c3e27657b55ab912348337eee4257fa..7c2a8f6189ada6cfd65a90790d264445f1dffa67 100644 (file)
@@ -155,12 +155,13 @@ class Distribution(base.DataObject):
 
                return sorted(repos)
 
-       def get_repo(self, name):
+       def get_repo(self, slug):
                repo = self.backend.repos._get_repository("SELECT * FROM repositories \
-                       WHERE distro_id = %s AND name = %s", self.id, name)
+                       WHERE distro_id = %s AND slug = %s", self.id, slug)
 
                # Cache
-               repo.distro = self
+               if repo:
+                       repo.distro = self
 
                return repo
 
index e6b209aa338c0dc766461493b1aa766dc37a9b0d..7d53e03b8857865b38f58805766d8348d83e13d7 100644 (file)
@@ -392,6 +392,22 @@ class User(base.DataObject):
 
                return list(repos)
 
+       def get_repo(self, slug):
+               return self.backend.repos._get_repository("""
+                       SELECT
+                               *
+                       FROM
+                               repositories
+                       WHERE
+                               deleted IS FALSE
+                       AND
+                               owner_id = %s
+                       AND
+                               slug = %s""",
+                       self.id,
+                       slug,
+               )
+
 
 class UserEmail(base.DataObject):
        table = "users_emails"
index 5cee78b648ae6cd2f195789d9e8ef4669142e48c..891729446e04d6ba6b7b4b293ccdc88842500024 100644 (file)
@@ -111,6 +111,14 @@ class Application(tornado.web.Application):
                        # User profiles
                        (r"/users", users.UsersHandler),
                        (r"/users/(\w+)", users.ShowHandler),
+                       (r"/users/(?P<user_slug>\w+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)",
+                               repos.ShowHandler),
+                       (r"/users/(?P<user_slug>\w+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)\.repo",
+                               repos.ConfigHandler),
+                       (r"/users/(?P<user_slug>\w+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)/builds",
+                               repos.BuildsHandler),
+                       (r"/users/(?P<user_slug>\w+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)/mirrorlist",
+                               repos.MirrorlistHandler),
                        (r"/user/(\w+)/impersonate", users.UserImpersonateHandler),
                        (r"/user/(\w+)/delete", users.UserDeleteHandler),
                        (r"/user/(\w+)/edit", users.UserEditHandler),
@@ -155,10 +163,14 @@ class Application(tornado.web.Application):
                        # Distributions
                        (r"/distros", distributions.IndexHandler),
                        (r"/distros/([A-Za-z0-9\-\.]+)", distributions.ShowHandler),
-                       (r"/distros/([A-Za-z0-9\-\.]+)/repos/([A-Za-z0-9\-]+)", repos.ShowHandler),
-                       (r"/distros/([A-Za-z0-9\-\.]+)/repos/([A-Za-z0-9\-]+)\.repo", repos.ConfigHandler),
-                       (r"/distros/([A-Za-z0-9\-\.]+)/repos/([A-Za-z0-9\-]+)/builds", repos.BuildsHandler),
-                       (r"/distros/([A-Za-z0-9\-\.]+)/repos/([A-Za-z0-9\-]+)/mirrorlist", repos.MirrorlistHandler),
+                       (r"/distros/(?P<distro_slug>[A-Za-z0-9\-\.]+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)",
+                               repos.ShowHandler),
+                       (r"/distros/(?P<distro_slug>[A-Za-z0-9\-\.]+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)\.repo",
+                               repos.ConfigHandler),
+                       (r"/distros/(?P<distro_slug>[A-Za-z0-9\-\.]+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)/builds",
+                               repos.BuildsHandler),
+                       (r"/distros/(?P<distro_slug>[A-Za-z0-9\-\.]+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)/mirrorlist",
+                               repos.MirrorlistHandler),
 
                        (r"/distro/([A-Za-z0-9\-\.]+)/repo/([A-Za-z0-9\-]+)/edit",
                                RepositoryEditHandler),
index 9df0f2f96b1391135a183698d11c91d0d9f9bfdc..e77d3f6e91605838dec34d746037334f414c69d1 100644 (file)
@@ -24,47 +24,51 @@ import tornado.web
 from . import base
 from . import ui_modules
 
-class ShowHandler(base.BaseHandler):
-       def get(self, distro_slug, repo_slug):
+class BaseHandler(base.BaseHandler):
+       def _get_repo(self, repo_slug, distro_slug=None, user_slug=None):
+               distro = user = None
+
                # Find the distribution
-               distro = self.backend.distros.get_by_slug(distro_slug)
-               if not distro:
-                       raise tornado.web.HTTPError(404, "Could not find distro: %s" % distro_slug)
+               if distro_slug:
+                       distro = self.backend.distros.get_by_slug(distro_slug)
+                       if not distro:
+                               raise tornado.web.HTTPError(404, "Could not find distro: %s" % distro_slug)
+
+               # Find the user
+               if user_slug:
+                       user = self.backend.users.get_by_name(user_slug)
+                       if not user:
+                               raise tornado.web.HTTPError(404, "Could not find user: %s" % user_slug)
+
+               assert distro or user, "Neither distro nor user set"
 
                # Find the repository
-               repo = distro.get_repo(repo_slug)
+               repo = (distro or user).get_repo(repo_slug)
                if not repo:
                        raise tornado.web.HTTPError(404, "Could not find repo: %s" % repo_slug)
 
-               self.render("repos/show.html", repo=repo, distro=repo.distro)
+               return repo
 
+class ShowHandler(BaseHandler):
+       def get(self, **kwargs):
+               # Fetch the repository
+               repo = self._get_repo(**kwargs)
 
-class BuildsHandler(base.BaseHandler):
-       def get(self, distro_slug, repo_slug):
-               # Find the distribution
-               distro = self.backend.distros.get_by_slug(distro_slug)
-               if not distro:
-                       raise tornado.web.HTTPError(404, "Could not find distro: %s" % distro_slug)
+               self.render("repos/show.html", repo=repo, distro=repo.distro)
 
-               # Find the repository
-               repo = distro.get_repo(repo_slug)
-               if not repo:
-                       raise tornado.web.HTTPError(404, "Could not find repo: %s" % repo_slug)
 
-               self.render("repos/builds.html", repo=repo, distro=repo.distro)
+class BuildsHandler(BaseHandler):
+       def get(self, **kwargs):
+               # Fetch the repository
+               repo = self._get_repo(**kwargs)
 
+               self.render("repos/builds.html", repo=repo, distro=repo.distro)
 
-class ConfigHandler(base.BaseHandler):
-       def get(self, distro_slug, repo_slug):
-               # Find the distribution
-               distro = self.backend.distros.get_by_slug(distro_slug)
-               if not distro:
-                       raise tornado.web.HTTPError(404, "Could not find distro: %s" % distro_slug)
 
-               # Find the repository
-               repo = distro.get_repo(repo_slug)
-               if not repo:
-                       raise tornado.web.HTTPError(404, "Could not find repo: %s" % repo_slug)
+class ConfigHandler(BaseHandler):
+       def get(self, **kwargs):
+               # Fetch the repository
+               repo = self._get_repo(**kwargs)
 
                # This is plain text
                self.set_header("Content-Type", "text/plain")
@@ -76,17 +80,10 @@ class ConfigHandler(base.BaseHandler):
                self.finish(config)
 
 
-class MirrorlistHandler(base.BaseHandler):
-       def get(self, distro_slug, repo_slug):
-               # Find the distribution
-               distro = self.backend.distros.get_by_slug(distro_slug)
-               if not distro:
-                       raise tornado.web.HTTPError(404, "Could not find distro: %s" % distro_slug)
-
-               # Find the repository
-               repo = distro.get_repo(repo_slug)
-               if not repo:
-                       raise tornado.web.HTTPError(404, "Could not find repo: %s" % repo_slug)
+class MirrorlistHandler(BaseHandler):
+       def get(self, **kwargs):
+               # Fetch the repository
+               repo = self._get_repo(**kwargs)
 
                # Send nothing if repository isn't supposed to be mirrored
                if not repo.mirrored: