From 219138cb0bf04ba0cd3c2ec90c1000372c1e3433 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 10 Feb 2025 16:15:59 +0000 Subject: [PATCH] builds: Fix adding/removing from repositories Signed-off-by: Michael Tremer --- src/buildservice/repos.py | 13 ++++++ src/templates/builds/repos/add.html | 22 +++++----- src/templates/builds/repos/remove.html | 60 ++++++++++++-------------- src/templates/builds/show.html | 4 ++ src/web/builds.py | 44 +++++++------------ 5 files changed, 72 insertions(+), 71 deletions(-) diff --git a/src/buildservice/repos.py b/src/buildservice/repos.py index c1745bb9..67987b3c 100644 --- a/src/buildservice/repos.py +++ b/src/buildservice/repos.py @@ -82,6 +82,19 @@ class RepoBuild(database.Base): "User", foreign_keys=[removed_by_id], lazy="selectin", ) + # Remove! + + def remove(self, removed_by=None): + """ + Removes the build from the repository + """ + # Mark as removed + self.removed_at = sqlalchemy.func.current_timestamp() + if removed_by: + self.removed_by = removed_by + + log.debug("%s has been removed from %s by %s" % (self.build, self.repo, self.removed_by)) + class Repos(base.Object): def __aiter__(self): diff --git a/src/templates/builds/repos/add.html b/src/templates/builds/repos/add.html index e4ae8109..2cf51984 100644 --- a/src/templates/builds/repos/add.html +++ b/src/templates/builds/repos/add.html @@ -1,6 +1,6 @@ -{% extends "../../modal.html" %} +{% extends "modal.html" %} -{% block title %}{{ build }} - {{ _("Add To Repository") }}{% end block %} +{% block title %}{{ build }} - {{ _("Add To Repository") }}{% endblock %} {% block breadcrumbs %} -{% end block %} +{% endblock %} {% block modal_title %}

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

{{ build }}
-{% end block %} +{% endblock %} {% block modal %}
- {% raw xsrf_form_html() %} + {{ xsrf_form_html() | safe }} {# Repositories #}
@@ -36,12 +36,14 @@
@@ -54,4 +56,4 @@
-{% end block %} +{% endblock %} diff --git a/src/templates/builds/repos/remove.html b/src/templates/builds/repos/remove.html index 43361c77..61f364ec 100644 --- a/src/templates/builds/repos/remove.html +++ b/src/templates/builds/repos/remove.html @@ -1,6 +1,6 @@ -{% extends "../../modal.html" %} +{% extends "modal.html" %} -{% block title %}{{ build }} - {{ _("Remove From Repository") }}{% end block %} +{% block title %}{{ build }} - {{ _("Remove From Repository") }}{% endblock %} {% block breadcrumbs %} -{% end block %} +{% endblock %} {% block modal_title %}

{{ _("Remove Build From A Repository") }}

{{ build }}
-{% end block %} +{% endblock %} {% block modal %}
- {% raw xsrf_form_html() %} + {{ xsrf_form_html() | safe }} - {# When the build is in exactly one repository... #} - {% if len(build.repos) == 1 %} - {% set repo = build.repos[0] %} - - - -
-

- {{ _("Do you want to remove this build from %s?") % repo }} -

-
+
+

+ {{ _("Please select the repository you want to remove this build from:") }} +

+
- {# When the build is in multiple repositories... #} - {% else %} -
-

- {{ _("Please select the repository you want to remove this build from:") }} -

-
+ {# Repositories #} +
+ - {# Repositories #} - {% for repo in sorted(build.repos) %} -
- +
+
+
- {% end %} - {% end %} +
+
{# Submit! #}
@@ -68,4 +62,4 @@
-{% end block %} +{% endblock %} diff --git a/src/templates/builds/show.html b/src/templates/builds/show.html index 2c31b94c..3287ce19 100644 --- a/src/templates/builds/show.html +++ b/src/templates/builds/show.html @@ -162,6 +162,10 @@ {% if build.repos %} {{ RepoList(build.repos, build=build) }} + {% else %} +
+ {{ _("This build is in no repositories.") }} +
{% endif %}
diff --git a/src/web/builds.py b/src/web/builds.py index 759323b2..18437c05 100644 --- a/src/web/builds.py +++ b/src/web/builds.py @@ -290,34 +290,30 @@ class BugHandler(base.BaseHandler): class ReposAddHandler(base.BaseHandler): @base.authenticated - def get(self, uuid): - build = self.backend.builds.get_by_uuid(uuid) + async def get(self, uuid): + build = await 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] + repos = await self.current_user.get_repos(build.distro) except KeyError: repos = None - self.render("builds/repos/add.html", build=build, repos=repos) + await self.render("builds/repos/add.html", build=build, repos=repos) @base.authenticated async def post(self, uuid): - build = self.backend.builds.get_by_uuid(uuid) + build = await 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) + repo = await self.get_argument_repo("repo", distro=build.distro, user=self.current_user) # Add the build to the repository - with self.db.transaction(): + async with await self.db.transaction(): await repo.add_build(build, user=self.current_user) self.redirect("/builds/%s" % build.uuid) @@ -325,8 +321,8 @@ class ReposAddHandler(base.BaseHandler): class ReposRemoveHandler(base.BaseHandler): @base.authenticated - def get(self, uuid): - build = self.backend.builds.get_by_uuid(uuid) + async def get(self, uuid): + build = await self.backend.builds.get_by_uuid(uuid) if not build: raise tornado.web.HTTPError(404, "Could not find build %s" % uuid) @@ -334,28 +330,20 @@ class ReposRemoveHandler(base.BaseHandler): if not build.repos: raise tornado.web.HTTPError(400) - self.render("builds/repos/remove.html", build=build) + await self.render("builds/repos/remove.html", build=build) @base.authenticated async def post(self, uuid): - build = self.backend.builds.get_by_uuid(uuid) + build = await self.backend.builds.get_by_uuid(uuid) if not build: raise tornado.web.HTTPError(404, "Could not find build %s" % uuid) - # Fetch all selected repos - repos = self.get_arguments("repo") - - # Raise an error if nothing has been selected - if not repos: - raise tornado.web.HTTPError(400, "No repositories selected") - - # Find all selected repositories - repos = [repo for repo in build.repos if repo.slug in repos] + # Fetch the repository + repo = await self.get_argument_repo("repo", distro=build.distro, user=self.current_user) - # Remove build from all repositories - with self.db.transaction(): - for repo in repos: - await repo.remove_build(build, user=self.current_user) + # Remove build from the repository + async with await self.db.transaction(): + await repo.remove_build(build, user=self.current_user) self.redirect("/builds/%s" % build.uuid) -- 2.47.2