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
repo_id = %s
AND
build_id = %s
- """, self.id, build,
+ """, user, self.id, build,
)
# Update the cache
--- /dev/null
+{% 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 %}
{% 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>
(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),
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)