]> git.ipfire.org Git - pbs.git/commitdiff
builds: Add controls to remove builds from repositories
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 May 2023 16:05:52 +0000 (16:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 15 May 2023 16:05:52 +0000 (16:05 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/repository.py
src/templates/builds/repos/remove.html [new file with mode: 0644]
src/templates/builds/show.html
src/web/__init__.py
src/web/builds.py

index 70ab0f3075be53e7d34445c28c764fb4c93772d1..88b13b3f585e0bae44ccf3407b0577cefa6ae7d7 100644 (file)
@@ -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
 
index 78a87b37d88e6ac2edd132270abe891630f0eb50..fbf58b1837842cb0be64ab736e2630b627be6947 100644 (file)
@@ -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 (file)
index 0000000..43361c7
--- /dev/null
@@ -0,0 +1,71 @@
+{% extends "../../modal.html" %}
+
+{% block title %}{{ build }} - {{ _("Remove From Repository") }}{% end block %}
+
+{% block breadcrumbs %}
+       <nav class="breadcrumb" aria-label="breadcrumbs">
+               <ul>
+                       <li>
+                               <a href="/packages">{{ _("Packages") }}</a>
+                       </li>
+                       <li>
+                               <a href="/packages/{{ build.pkg.name }}">{{ build.pkg.name }}</a>
+                       </li>
+                       <li>
+                               <a href="/builds/{{ build.uuid }}">{{ build.pkg.evr }}</a>
+                       </li>
+                       <li class="is-active">
+                               <a href="#" aria-current="page">{{ _("Remove From Repository") }}</a>
+                       </li>
+               </ul>
+       </nav>
+{% end block %}
+
+{% block modal_title %}
+       <h4 class="title is-4">{{ _("Remove Build From A Repository") }}</h4>
+       <h6 class="subtitle is-6">{{ build }}</h6>
+{% end block %}
+
+{% block modal %}
+       <form method="POST" action="">
+               {% raw xsrf_form_html() %}
+
+               {# When the build is in exactly one repository... #}
+               {% if len(build.repos) == 1 %}
+                       {% set repo = build.repos[0] %}
+
+                       <input type="hidden" name="repo" value="{{ repo.slug }}">
+
+                       <div class="block">
+                               <p>
+                                       {{ _("Do you want to remove this build from %s?") % repo }}
+                               </p>
+                       </div>
+
+               {# When the build is in multiple repositories... #}
+               {% else %}
+                       <div class="block">
+                               <p>
+                                               {{ _("Please select the repository you want to remove this build from:") }}
+                               </p>
+                       </div>
+
+                       {# Repositories #}
+                       {% for repo in sorted(build.repos) %}
+                               <div class="field">
+                                       <label class="checkbox">
+                                               <input type="checkbox" name="repo" value="{{ repo.slug }}">
+                                               {{ repo }}
+                                       </label>
+                               </div>
+                       {% end %}
+               {% end %}
+
+               {# Submit! #}
+               <div class="field">
+                       <button type="submit" class="button is-danger is-fullwidth">
+                               {{ _("Remove From Repository") }}
+                       </button>
+               </div>
+       </form>
+{% end block %}
index cbb2a86b740498b00ecf370a25490083e888ddff..56178b588951e89c0e8f7384ba9125732fa18021 100644 (file)
 
                                {% module ReposList(build.repos, build=build) %}
 
-                               {% if current_user == build.owner %}
+                               {% if build.owner and build.has_perm(current_user) %}
                                        <div class="buttons">
                                                <a class="button is-success" href="/builds/{{ build.uuid }}/repos/add">
                                                        {{ _("Add Build To Repository") }}
                                                </a>
+
+                                               {% if build.repos %}
+                                                       <a class="button is-danger" href="/builds/{{ build.uuid }}/repos/remove">
+                                                               {{ _("Remove Build From Repository") }}
+                                                       </a>
+                                               {% end %}
                                        </div>
                                {% end %}
                        </div>
index a7e18c3f7c70c125277b06e673cd14bd6cefcc27..c87fcf04620a0082ca47b3800da6ee351fe3ba82 100644 (file)
@@ -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),
 
index b0cdf9e40850df9c39450dc285eacf10ddd483b1..022236be3b66c946ec7345fce2c57814e6897d2e 100644 (file)
@@ -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)