From: Michael Tremer Date: Sun, 26 Jun 2022 14:44:12 +0000 (+0000) Subject: repositories: Add distribution to identify user repositories X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=940a80430a292df4ec7d7ac41ef90bc7c4056d51;p=pbs.git repositories: Add distribution to identify user repositories Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/repository.py b/src/buildservice/repository.py index 30af6263..4c2d83a2 100644 --- a/src/buildservice/repository.py +++ b/src/buildservice/repository.py @@ -194,6 +194,13 @@ class Repository(base.DataObject): @property def url(self): + if self.owner: + return "/users/%s/repos/%s/%s" % (self.owner.name, self.distro.slug, self.slug) + + return "/distros/%s/repos/%s" % (self.distro.slug, self.slug) + + @property + def download_url(self): return "/".join(( self.settings.get("baseurl", "https://pakfire.ipfire.org"), "repositories", diff --git a/src/buildservice/users.py b/src/buildservice/users.py index 7d53e03b..518dd5ab 100644 --- a/src/buildservice/users.py +++ b/src/buildservice/users.py @@ -392,7 +392,7 @@ class User(base.DataObject): return list(repos) - def get_repo(self, slug): + def get_repo(self, distro, slug): return self.backend.repos._get_repository(""" SELECT * @@ -402,9 +402,12 @@ class User(base.DataObject): deleted IS FALSE AND owner_id = %s + AND + distro_id = %s AND slug = %s""", self.id, + distro, slug, ) diff --git a/src/templates/repos/edit.html b/src/templates/repos/edit.html index c09059ab..ebacae63 100644 --- a/src/templates/repos/edit.html +++ b/src/templates/repos/edit.html @@ -15,6 +15,12 @@
  • {{ repo.owner }}
  • +
  • + {{ _("Distributions") }} +
  • +
  • + {{ repo.distro }} +
  • {% else %}
  • {{ _("Distributions") }} @@ -27,7 +33,7 @@ {{ _("Repositories") }}
  • - + {{ repo }}
  • @@ -92,7 +98,7 @@ - + {{ _("Delete") }} diff --git a/src/templates/repos/modules/list.html b/src/templates/repos/modules/list.html index de007107..51f80171 100644 --- a/src/templates/repos/modules/list.html +++ b/src/templates/repos/modules/list.html @@ -1,14 +1,7 @@ {% for repo in repos %} - {# Make URL #} - {% if repo.owner %} - {% set url = "/users/%s/repos/%s" % (repo.owner.name, repo.slug) %} - {% else %} - {% set url = "/distros/%s/repos/%s" % (repo.distro.slug, repo.slug) %} - {% end %} -
    - {{ repo }} + {{ repo }} {% if repo.summary %} {{ repo.summary }} diff --git a/src/templates/repos/show.html b/src/templates/repos/show.html index 424f2c2a..f2bf35f1 100644 --- a/src/templates/repos/show.html +++ b/src/templates/repos/show.html @@ -15,6 +15,12 @@
  • {{ repo.owner }}
  • +
  • + {{ _("Distributions") }} +
  • +
  • + {{ distro }} +
  • {% else %}
  • {{ _("Distributions") }} @@ -42,11 +48,11 @@
  • {% end %} - + {{ _("Download Configuration") }} - + {{ _("Edit") }} diff --git a/src/web/__init__.py b/src/web/__init__.py index b34874e7..20fa72db 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -113,15 +113,15 @@ class Application(tornado.web.Application): (r"/users", users.UsersHandler), (r"/users/(\w+)", users.ShowHandler), (r"/users/(\w+)/repos/create", repos.CreateCustomHandler), - (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-]+)", + (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-\.]+)/(?P[A-Za-z0-9\-]+)", repos.ShowHandler), - (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-]+)\.repo", + (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-\.]+)/(?P[A-Za-z0-9\-]+)\.repo", repos.ConfigHandler), - (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-]+)/builds", + (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-\.]+)/(?P[A-Za-z0-9\-]+)/builds", repos.BuildsHandler), - (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-]+)/edit", + (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-\.]+)/(?P[A-Za-z0-9\-]+)/edit", repos.EditHandler), - (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-]+)/mirrorlist", + (r"/users/(?P\w+)/repos/(?P[A-Za-z0-9\-\.]+)/(?P[A-Za-z0-9\-]+)/mirrorlist", repos.MirrorlistHandler), (r"/user/(\w+)/delete", users.UserDeleteHandler), (r"/user/(\w+)/edit", users.UserEditHandler), diff --git a/src/web/repos.py b/src/web/repos.py index 512369ad..08442487 100644 --- a/src/web/repos.py +++ b/src/web/repos.py @@ -25,14 +25,8 @@ from . import base from . import ui_modules class BaseHandler(base.BaseHandler): - def _get_repo(self, repo_slug, distro_slug=None, user_slug=None): - distro = user = None - - # Find the distribution - 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) + def _get_repo(self, distro_slug, repo_slug, user_slug=None): + user = None # Find the user if user_slug: @@ -40,10 +34,16 @@ class BaseHandler(base.BaseHandler): 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 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 or user).get_repo(repo_slug) + if user: + repo = user.get_repo(distro, repo_slug) + else: + repo = distro.get_repo(repo_slug) if not repo: raise tornado.web.HTTPError(404, "Could not find repo: %s" % repo_slug) @@ -151,12 +151,7 @@ class EditHandler(BaseHandler): if self.current_user.is_admin(): repo.mirrored = self.get_argument_bool("mirrored") - if repo.owner: - url = "/users/%s/repos/%s" % (repo.owner.name, repo.slug) - else: - url = "/distros/%s/repos/%s" % (repo.distro.slug, repo.slug) - - self.redirect(url) + self.redirect(repo.url) class MirrorlistHandler(BaseHandler): @@ -182,7 +177,7 @@ class MirrorlistHandler(BaseHandler): # Always use the buildservice itself as last resort mirrors.append({ - "url" : "/".join((repo.url, arch)), + "url" : "/".join((repo.download_url, arch)), }) self.finish({