]> git.ipfire.org Git - pbs.git/commitdiff
repositories: Add distribution to identify user repositories
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jun 2022 14:44:12 +0000 (14:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jun 2022 14:44:12 +0000 (14:44 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/repository.py
src/buildservice/users.py
src/templates/repos/edit.html
src/templates/repos/modules/list.html
src/templates/repos/show.html
src/web/__init__.py
src/web/repos.py

index 30af62637ef72e238edd183752111060aff7fd56..4c2d83a287fc65dc050126d86100d9654867849f 100644 (file)
@@ -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",
index 7d53e03b8857865b38f58805766d8348d83e13d7..518dd5ab17e3a61cc43c970ac049a52534044868 100644 (file)
@@ -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,
                )
 
index c09059ab7a9d0583c41a2892aed9a03e3f40ea41..ebacae6323240af065f664787673331302c400cb 100644 (file)
                                <li>
                                        <a href="/users/{{ repo.owner.name }}">{{ repo.owner }}</a>
                                </li>
+                               <li>
+                                       {{ _("Distributions") }}
+                               </li>
+                               <li>
+                                       {{ repo.distro }}
+                               </li>
                        {% else %}
                                <li>
                                        <a href="/distros">{{ _("Distributions") }}</a>
@@ -27,7 +33,7 @@
                                {{ _("Repositories") }}
                        </li>
                        <li>
-                               <a href="{% if repo.owner %}/users/{{ repo.owner.name }}{% else %}/distros/{{ repo.distro.slug }}{% end %}/repos/{{ repo.slug }}">
+                               <a href="{{ repo.url }}">
                                        {{ repo }}
                                </a>
                        </li>
@@ -92,7 +98,7 @@
 
                                <button class="success button expanded" type="submit">{{ _("Save") }}</button>
 
-                               <a class="small danger button expanded" href="{% if repo.owner %}/users/{{ repo.owner.name }}{% else %}/distros/{{ repo.distro.slug }}{% end %}/repos/{{ repo.slug }}/delete">
+                               <a class="small danger button expanded" href="{{ repo.url }}/delete">
                                        {{ _("Delete") }}
                                </a>
                        </form>
index de0071072e445572558d0b6a28f532ff23dd67c2..51f801710266ceb211891598f1571add47fb384f 100644 (file)
@@ -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 %}
-
        <div class="callout">
                <h5>
-                       <a href="{{ url }}">{{ repo }}</a>
+                       <a href="{{ repo.url }}">{{ repo }}</a>
 
                        {% if repo.summary %}
                                <small>{{ repo.summary }}</small>
index 424f2c2a9e2c3469283bf0d1dafd486ae215c55b..f2bf35f14afdaf4d9f4c23ff16c7b5cdec6822ac 100644 (file)
                                <li>
                                        <a href="/users/{{ repo.owner.name }}">{{ repo.owner }}</a>
                                </li>
+                               <li>
+                                       {{ _("Distributions") }}
+                               </li>
+                               <li>
+                                       {{ distro }}
+                               </li>
                        {% else %}
                                <li>
                                        <a href="/distros">{{ _("Distributions") }}</a>
                </div>
        {% end %}
 
-       <a class="secondary expanded button" href="{% if repo.owner %}/users/{{ repo.owner.name }}{% else %}/distros/{{ distro.slug }}{% end %}/repos/{{ repo.slug }}.repo">
+       <a class="secondary expanded button" href="{{ repo.url }}.repo">
                {{ _("Download Configuration") }}
        </a>
 
-       <a class="warning expanded button" href="{% if repo.owner %}/users/{{ repo.owner.name }}{% else %}/distros/{{ distro.slug }}{% end %}/repos/{{ repo.slug }}/edit">
+       <a class="warning expanded button" href="{{ repo.url }}/edit">
                {{ _("Edit") }}
        </a>
 
index b34874e797d2fb8f91f4cd91e910dbe057d93ae2..20fa72dbad622a8eeb069137a95ec04c157774e5 100644 (file)
@@ -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<user_slug>\w+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)",
+                       (r"/users/(?P<user_slug>\w+)/repos/(?P<distro_slug>[A-Za-z0-9\-\.]+)/(?P<repo_slug>[A-Za-z0-9\-]+)",
                                repos.ShowHandler),
-                       (r"/users/(?P<user_slug>\w+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)\.repo",
+                       (r"/users/(?P<user_slug>\w+)/repos/(?P<distro_slug>[A-Za-z0-9\-\.]+)/(?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",
+                       (r"/users/(?P<user_slug>\w+)/repos/(?P<distro_slug>[A-Za-z0-9\-\.]+)/(?P<repo_slug>[A-Za-z0-9\-]+)/builds",
                                repos.BuildsHandler),
-                       (r"/users/(?P<user_slug>\w+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)/edit",
+                       (r"/users/(?P<user_slug>\w+)/repos/(?P<distro_slug>[A-Za-z0-9\-\.]+)/(?P<repo_slug>[A-Za-z0-9\-]+)/edit",
                                repos.EditHandler),
-                       (r"/users/(?P<user_slug>\w+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)/mirrorlist",
+                       (r"/users/(?P<user_slug>\w+)/repos/(?P<distro_slug>[A-Za-z0-9\-\.]+)/(?P<repo_slug>[A-Za-z0-9\-]+)/mirrorlist",
                                repos.MirrorlistHandler),
                        (r"/user/(\w+)/delete", users.UserDeleteHandler),
                        (r"/user/(\w+)/edit", users.UserEditHandler),
index 512369ad36266a5979279d17f547acc4b24a471b..08442487a286fbdbaab978b3dbea56f40a91d1fd 100644 (file)
@@ -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({