From: Michael Tremer Date: Mon, 15 May 2023 15:37:20 +0000 (+0000) Subject: builds: Add controls to add to another repository X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ff12a443047f8a1ae54ba4514553e16ae96099b;p=pbs.git builds: Add controls to add to another repository Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index ec44dc19..70ab0f30 100644 --- a/Makefile.am +++ b/Makefile.am @@ -212,6 +212,11 @@ dist_templates_builds_modules_DATA = \ templates_builds_modulesdir = $(templates_buildsdir)/modules +dist_templates_builds_repos_DATA = \ + src/templates/builds/repos/add.html + +templates_builds_reposdir = $(templates_buildsdir)/repos + dist_templates_distros_DATA = \ src/templates/distros/edit.html \ src/templates/distros/index.html \ diff --git a/src/buildservice/repository.py b/src/buildservice/repository.py index 2c57dcae..78a87b37 100644 --- a/src/buildservice/repository.py +++ b/src/buildservice/repository.py @@ -165,7 +165,7 @@ class Repository(base.DataObject): def __lt__(self, other): if isinstance(other, self.__class__): - return self.priority > other.priority or self.name < other.name + return self.name < other.name return NotImplemented diff --git a/src/templates/builds/repos/add.html b/src/templates/builds/repos/add.html new file mode 100644 index 00000000..3449bfda --- /dev/null +++ b/src/templates/builds/repos/add.html @@ -0,0 +1,55 @@ +{% extends "../../modal.html" %} + +{% block title %}{{ build }} - {{ _("Add To Repository") }}{% end block %} + +{% block breadcrumbs %} + +{% end block %} + +{% block modal_title %} +

{{ _("Add Build To A Repository") }}

+
{{ build }}
+{% end block %} + +{% block modal %} +
+ {% raw xsrf_form_html() %} + + {# Repositories #} +
+ +
+ +
+
+ + {# Submit! #} +
+ +
+
+{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 771a109d..a7e18c3f 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -137,6 +137,7 @@ class Application(tornado.web.Application): (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/bug", builds.BugHandler), (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/comment", builds.CommentHandler), (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/delete", builds.DeleteHandler), + (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/repos/add", builds.ReposAddHandler), (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/watch", builds.WatchHandler), (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/unwatch", builds.UnwatchHandler), diff --git a/src/web/builds.py b/src/web/builds.py index 4a1cc4c6..b0cdf9e4 100644 --- a/src/web/builds.py +++ b/src/web/builds.py @@ -222,6 +222,44 @@ class BugHandler(base.BaseHandler): self.render("builds/bug-created.html", build=build, bug=bug) +class ReposAddHandler(base.BaseHandler): + @tornado.web.authenticated + def get(self, uuid): + build = self.backend.builds.get_by_uuid(uuid) + if not build: + raise tornado.web.HTTPError(404, "Could not find build %s" % uuid) + + # Fetch all available repositories + try: + repos = self.current_user.repos[build.distro] + except KeyError: + repos = None + + self.render("builds/repos/add.html", build=build, repos=repos) + + @tornado.web.authenticated + async def post(self, uuid): + build = self.backend.builds.get_by_uuid(uuid) + if not build: + raise tornado.web.HTTPError(404, "Could not find build %s" % uuid) + + slug = self.get_argument("repo") + + # Fetch the repository + repo = self.current_user.get_repo(build.distro, slug) + if not repo: + raise tornado.web.HTTPError(400, "Could not find repository '%s'" % slug) + + # Add the build to the repository + with self.db.transaction(): + await repo.add_build(build, user=self.current_user, update=False) + + # Update the repository in the background + self.backend.run_task(repo.update) + + self.redirect("/builds/%s" % build.uuid) + + class GroupShowHandler(base.BaseHandler): def get(self, uuid): group = self.backend.builds.groups.get_by_uuid(uuid)