From: Michael Tremer Date: Mon, 15 May 2023 16:05:52 +0000 (+0000) Subject: builds: Add controls to remove builds from repositories X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d27c3025931c64ec5869e61eed5d546d3aa592f;p=pbs.git builds: Add controls to remove builds from repositories Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 70ab0f30..88b13b3f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -213,7 +213,8 @@ dist_templates_builds_modules_DATA = \ templates_builds_modulesdir = $(templates_buildsdir)/modules dist_templates_builds_repos_DATA = \ - src/templates/builds/repos/add.html + src/templates/builds/repos/add.html \ + src/templates/builds/repos/remove.html templates_builds_reposdir = $(templates_buildsdir)/repos diff --git a/src/buildservice/repository.py b/src/buildservice/repository.py index 78a87b37..fbf58b18 100644 --- a/src/buildservice/repository.py +++ b/src/buildservice/repository.py @@ -466,7 +466,7 @@ class Repository(base.DataObject): repo_id = %s AND build_id = %s - """, self.id, build, + """, user, self.id, build, ) # Update the cache diff --git a/src/templates/builds/repos/remove.html b/src/templates/builds/repos/remove.html new file mode 100644 index 00000000..43361c77 --- /dev/null +++ b/src/templates/builds/repos/remove.html @@ -0,0 +1,71 @@ +{% extends "../../modal.html" %} + +{% block title %}{{ build }} - {{ _("Remove From Repository") }}{% end block %} + +{% block breadcrumbs %} + +{% end block %} + +{% block modal_title %} +

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

+
{{ build }}
+{% end block %} + +{% block modal %} +
+ {% raw xsrf_form_html() %} + + {# 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 }} +

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

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

+
+ + {# Repositories #} + {% for repo in sorted(build.repos) %} +
+ +
+ {% end %} + {% end %} + + {# Submit! #} +
+ +
+
+{% end block %} diff --git a/src/templates/builds/show.html b/src/templates/builds/show.html index cbb2a86b..56178b58 100644 --- a/src/templates/builds/show.html +++ b/src/templates/builds/show.html @@ -177,11 +177,17 @@ {% module ReposList(build.repos, build=build) %} - {% if current_user == build.owner %} + {% if build.owner and build.has_perm(current_user) %} {% end %} diff --git a/src/web/__init__.py b/src/web/__init__.py index a7e18c3f..c87fcf04 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -138,6 +138,7 @@ class Application(tornado.web.Application): (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})/repos/remove", builds.ReposRemoveHandler), (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 b0cdf9e4..022236be 100644 --- a/src/web/builds.py +++ b/src/web/builds.py @@ -260,6 +260,47 @@ class ReposAddHandler(base.BaseHandler): self.redirect("/builds/%s" % build.uuid) +class ReposRemoveHandler(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) + + # Raise error when the build is in to repositories + if not build.repos: + raise tornado.web.HTTPError(400) + + self.render("builds/repos/remove.html", build=build) + + @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) + + # 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] + + # Remove build from all repositories + with self.db.transaction(): + for repo in build.repos: + await repo.remove_build(build, user=self.current_user, update=False) + + # Update all repositories in the background + for repo in repos: + 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)