]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Build UI to manually abort a job
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 19:38:17 +0000 (19:38 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 19:38:17 +0000 (19:38 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/jobs.py
src/templates/jobs-abort.html [deleted file]
src/templates/jobs/abort.html [new file with mode: 0644]
src/templates/jobs/modules/list.html
src/web/__init__.py
src/web/jobs.py

index 07a63ed16b70bd6977a37876fd56a1c2629af533..2b0823abaf5a466017b920d5e4fb3a487fb07e33 100644 (file)
@@ -158,7 +158,6 @@ webdir = $(buildservicedir)/web
 dist_templates_DATA = \
        src/templates/base.html \
        src/templates/index.html \
-       src/templates/jobs-abort.html \
        src/templates/jobs-buildroot.html \
        src/templates/log.html \
        src/templates/login.html \
@@ -229,6 +228,9 @@ dist_templates_events_modules_DATA = \
 
 templates_events_modulesdir = $(templates_eventsdir)/modules
 
+dist_templates_jobs_DATA = \
+       src/templates/jobs/abort.html
+
 templates_jobsdir = $(templatesdir)/jobs
 
 dist_templates_jobs_messages_DATA = \
index 11ed3bf6dffb9e114b62a534ca28e6ecc005f6d5..32f25a4f889a529bdd5f5e838ce91f94eae4d9f2 100644 (file)
@@ -114,6 +114,13 @@ class Job(base.DataObject):
 
                return NotImplemented
 
+       def has_perm(self, user):
+               """
+                       Check permissions
+               """
+               # This is the same as for builds
+               return self.build.has_perm(user)
+
        @property
        def uuid(self):
                return self.data.uuid
@@ -314,6 +321,14 @@ class Job(base.DataObject):
                if self.has_finished():
                        return self.data.failed
 
+       # Abort
+
+       async def abort(self, user=None):
+               """
+                       Aborts the job
+               """
+               pass # XXX TODO
+
        @property
        def message(self):
                return self.data.message
diff --git a/src/templates/jobs-abort.html b/src/templates/jobs-abort.html
deleted file mode 100644 (file)
index a915f50..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}{{ _("Abort build job %s") % job.name }}{% end block %}
-
-{% block body %}
-       <h1>{{ _("Abort build job %s") % job.name }}</h1>
-       <p>
-               {{ _("You may abort a running build.") }}
-               {{ _("The build server will eventually stop to build the package.") }}
-       </p>
-
-       <form method="post" action="">
-               {% raw xsrf_form_html() %}
-               <table class="form form3">
-                       <tr>
-                               <td class="col1">{{ _("Build job") }}</td>
-                               <td class="col2">
-                                       <a href="/job/{{ job.uuid }}">{{ job.name }}</a>
-                               </td>
-                               <td class="col3">
-                                       &nbsp;
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class="col1">{{ _("Start time") }}</td>
-                               <td class="col2">
-                                       {% if job.time_started %}
-                                               {{ locale.format_date(job.time_started, full_format=True) }}
-                                       {% else %}
-                                               {{ _("No started, yet.") }}
-                                       {% end %}
-                               </td>
-                               <td class="col3">
-                                       &nbsp;
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class="col1">{{ _("Build server") }}</td>
-                               <td class="col2">
-                                       <a href="/builders/{{ job.builder.name }}">{{ job.builder.name }}</a>
-                               </td>
-                               <td class="col3">
-                                       &nbsp;
-                               </td>
-                       </tr>
-                       <tr>
-                               <td colspan="3" class="buttons">
-                                       <input type="submit" value="{{ _("Abort build job") }}" />
-                               </td>
-                       </tr>
-               </table>
-       </form>
-{% end block %}
diff --git a/src/templates/jobs/abort.html b/src/templates/jobs/abort.html
new file mode 100644 (file)
index 0000000..f1ca06b
--- /dev/null
@@ -0,0 +1,37 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ _("Abort Job %s") % job }}{% end block %}
+
+{% block container %}
+       <nav class="breadcrumb" aria-label="breadcrumbs">
+               <ul>
+                       <li>
+                               <a href="/builds">{{ _("Builds") }}</a>
+                       </li>
+                       <li>
+                               <a href="/builds/{{ job.build.uuid }}">{{ job.build }}</a>
+                       </li>
+                       <li>
+                               <a href="#" disabled>{{ job.arch }}</a>
+                       </li>
+                       <li class="is-active">
+                               <a href="#" aria-current="page">{{ _("Abort") }}</a>
+                       </li>
+               </ul>
+       </nav>
+
+       <div class="columns is-centered">
+               <div class="column is-6">
+                       <h1 class="title is-1">{{ _("Abort Job") }}</h1>
+
+                       <form method="POST" action="">
+                               <div class="box">
+                                       {% raw xsrf_form_html() %}
+
+                                       <input class="button is-danger" type="submit"
+                                               value="{{ _("Abort Job") }}" />
+                               </div>
+                       </form>
+               </div>
+       </div>
+{% end block %}
index 4a3c9c2d490bb7be7cafa817eb940259cbbb9baf..900fecc77676e8e232d028c9b13af8b7c49b0bd2 100644 (file)
                                                        <progress class="progress is-small is-light" max="100"></progress>
                                                </div>
 
-                                               <div class="column is-2">
+                                               <div class="column is-1">
                                                        {{ format_time(job.duration, shorter=True) }}
                                                </div>
+
+                                               <div class="column is-1">
+                                                       <a class="button is-danger" href="/jobs/{{ job.uuid }}/abort">
+                                                               {{ _("Abort") }}
+                                                       </a>
+                                               </div>
                                        </div>
                                {% end %}
                        </div>
index 0a69875021c298da04af765ddcc187b2ba41f7b8..d2095ec89a9f87cd2ed3034a0a4adf0ad4c8d907 100644 (file)
@@ -131,8 +131,8 @@ class Application(tornado.web.Application):
                        (r"/queue", jobs.QueueHandler),
 
                        # Jobs
+                       (r"/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/abort", jobs.AbortHandler),
                        (r"/jobs/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/log", jobs.LogHandler),
-                       (r"/job/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/abort", jobs.JobAbortHandler),
                        (r"/job/([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})/buildroot", jobs.JobBuildrootHandler),
 
                        # Builders
index 27879308f269598c93a02049bbfb52990634228f..83e85d7e1ad0b19f47f649481c1da6df9117abf7 100644 (file)
@@ -56,41 +56,33 @@ class JobBuildrootHandler(base.BaseHandler):
                        buildroot_size=buildroot_size)
 
 
-class JobAbortHandler(base.BaseHandler):
-       def get_job(self, uuid):
+class AbortHandler(base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self, uuid):
                job = self.backend.jobs.get_by_uuid(uuid)
                if not job:
                        raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
 
-               return job
-
-       @tornado.web.authenticated
-       def get(self, uuid):
-               job = self.get_job(uuid)
-
-               # XXX Check if user has the right to manage the job.
+               # Check for permissions
+               if not job.has_perm(self.current_user):
+                       raise tornado.web.HTTPError(403)
 
-               self.render("jobs-abort.html", job=job)
+               self.render("jobs/abort.html", job=job)
 
        @tornado.web.authenticated
-       def post(self, uuid):
-               job = self.get_job(uuid)
-
-               # XXX Check if user has the right to manage the job.
-
-               # Only running builds can be set to aborted state.
-               if not job.state == "running":
-                       # XXX send the user a nicer error message.
-                       self.redirect("/job/%s" % job.uuid)
-                       return
+       async def post(self, uuid):
+               job = self.backend.jobs.get_by_uuid(uuid)
+               if not job:
+                       raise tornado.web.HTTPError(404, "Job not found: %s" % uuid)
 
-               # Set the job into aborted state.
-               job.state = "aborted"
+               # Check for permissions
+               if not job.has_perm(self.current_user):
+                       raise tornado.web.HTTPError(403)
 
-               # 0 means the job was aborted by the user.
-               job.aborted_state = 0
+               with self.db.transaction():
+                       await job.abort(self.current_user)
 
-               self.redirect("/job/%s" % job.uuid)
+               self.redirect("/builds/%s" % job.build.uuid)
 
 
 class ListModule(ui_modules.UIModule):