templates_builders_modulesdir = $(templates_buildersdir)/modules
dist_templates_builds_DATA = \
+ src/templates/builds/approve.html \
src/templates/builds/bug.html \
src/templates/builds/bug-created.html \
src/templates/builds/clone.html \
for repo in self.repos:
await repo.changed()
+ @property
+ def next_repo(self):
+ for repo in self.repos:
+ return self.distro.get_next_repo(repo)
+
+ def can_be_approved(self, user=None):
+ if not user or not user.is_admin():
+ return False
+
+ if self.owner:
+ return False
+
+ # This can only be approved if there is another repository
+ if self.next_repo:
+ return True
+
+ return False
+
+ async def approve(self, user):
+ """
+ Moves this build to the next stage
+ """
+ # Fetch the next repository
+ next_repo = self.next_repo
+
+ # Remove the build from all repositories
+ for repo in self.repos:
+ await repo.remove_build(build=self, user=user)
+
+ # Add it to the next repository
+ await next_repo.add_build(build=self, user=user)
+
## Bugs
@lazy_property
return repo
+ def get_next_repo(self, repo):
+ """
+ Returns the next repository if there is one
+ """
+ for r in sorted(self.repos, key=lambda r: r.priority):
+ if r.priority <= repo.priority:
+ continue
+
+ return r
+
# Builds
def get_builds_by_name(self, name, limit=None):
--- /dev/null
+{% extends "../modal.html" %}
+
+{% block title %}{{ build }} - {{ _("Approve Build") }}{% 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">{{ _("Approve") }}</a>
+ </li>
+ </ul>
+ </nav>
+{% end block %}
+
+{% block modal_title %}
+ <h4 class="title is-4">{{ _("Approve %s") % build }}</h4>
+{% end block %}
+
+{% block modal %}
+ <form method="POST" action="">
+ {% raw xsrf_form_html() %}
+
+ {# Submit! #}
+ <div class="field">
+ <button type="submit" class="button is-primary is-fullwidth">
+ {{ _("Approve") }}
+ </button>
+ </div>
+ </form>
+{% end block %}
{% module ReposList(build.repos, build=build) %}
{% end %}
- {% if build.owner and build.has_perm(current_user) %}
- <div class="buttons">
+ <div class="buttons">
+ {% if build.can_be_approved(current_user) %}
+ <a class="button is-success" href="/builds/{{ build.uuid }}/approve">
+ {{ _("Approve") }}
+ </a>
+ {% end %}
+
+ {% if build.owner and build.has_perm(current_user) %}
<a class="button is-success" href="/builds/{{ build.uuid }}/repos/add">
{{ _("Add Build To Repository") }}
</a>
{{ _("Remove Build From Repository") }}
</a>
{% end %}
- </div>
- {% end %}
+ {% end %}
+ </div>
</div>
</section>
{% end %}
# Builds
(r"/builds", builds.IndexHandler),
(r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})", builds.ShowHandler),
+ (r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/approve", builds.ApproveHandler),
(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})/clone", builds.CloneHandler),
(r"/builds/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/comment", builds.CommentHandler),
distro=build.distro, bugs=bugs)
+class ApproveHandler(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)
+
+ # Check if this can be approved at all
+ if not build.can_be_approved(self.current_user):
+ raise tornado.web.HTTPError(400)
+
+ self.render("builds/approve.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)
+
+ # Check if this can be approved at all
+ if not build.can_be_approved(self.current_user):
+ raise tornado.web.HTTPError(400)
+
+ # Approve the build
+ with self.db.transaction():
+ await build.approve(self.current_user)
+
+ self.redirect("/builds/%s" % build.uuid)
+
+
class CloneHandler(base.BaseHandler):
@tornado.web.authenticated
def get(self, uuid):