]> git.ipfire.org Git - pbs.git/commitdiff
distros: Refactor editing distributions
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 15:11:44 +0000 (15:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 15:11:44 +0000 (15:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/buildservice/distribution.py
src/templates/distro-edit.html [deleted file]
src/templates/distros/edit.html [new file with mode: 0644]
src/templates/distros/show.html
src/web/__init__.py
src/web/distributions.py

index c014540ba07be8205afe2ae9ba08c4f3ab0cf8b8..42cd14ae203315aa49b8418ed252e7299d031cbd 100644 (file)
@@ -157,7 +157,6 @@ webdir = $(buildservicedir)/web
 
 dist_templates_DATA = \
        src/templates/base.html \
-       src/templates/distro-edit.html \
        src/templates/distro-source-commit-detail.html \
        src/templates/distro-source-commit-reset.html \
        src/templates/distro-source-commits.html \
@@ -208,6 +207,7 @@ dist_templates_builds_modules_DATA = \
 templates_builds_modulesdir = $(templates_buildsdir)/modules
 
 dist_templates_distros_DATA = \
+       src/templates/distros/edit.html \
        src/templates/distros/index.html \
        src/templates/distros/show.html
 
index 16ecf04f121cf11fccb6af43aea3ce7ddaf36745..2996771daab46fae7d56167cbd5aba777c2ec733 100644 (file)
@@ -105,22 +105,42 @@ class Distribution(base.DataObject):
 
                return lines
 
-       @property
-       def name(self):
+       # Name
+
+       def get_name(self):
                return self.data.name
 
+       def set_name(self, name):
+               self._set_attribute("name", name)
+
+       name = property(get_name, set_name)
+
+       # Slug
+
        @property
        def slug(self):
                return self.data.slug
 
-       @property
-       def slogan(self):
+       # Slogan
+
+       def get_slogan(self):
                return self.data.slogan
 
-       @property
-       def description(self):
+       def set_slogan(self, slogan):
+               self._set_attribute("slogan", slogan or "")
+
+       slogan = property(get_slogan, set_slogan)
+
+       # Description
+
+       def get_description(self):
                return self.data.description
 
+       def set_description(self, description):
+               self._set_attribute("description", description or "")
+
+       description = property(get_description, set_description)
+
        # Arches
 
        def get_arches(self):
@@ -131,10 +151,18 @@ class Distribution(base.DataObject):
 
        arches = property(get_arches, set_arches)
 
-       @property
-       def vendor(self):
+       # Vendor
+
+       def get_vendor(self):
                return self.data.vendor
 
+       def set_vendor(self, vendor):
+               self._set_attribute("vendor", vendor)
+
+       vendor = property(get_vendor, set_vendor)
+
+       # Contact
+
        def get_contact(self):
                return self.data.contact
 
@@ -143,13 +171,11 @@ class Distribution(base.DataObject):
 
        contact = property(get_contact, set_contact)
 
-       def get_tag(self):
-               return self.data.tag
-
-       def set_tag(self, tag):
-               self._set_attribute("tag", tag)
+       # Tag
 
-       tag = property(get_tag, set_tag)
+       @property
+       def tag(self):
+               return self.data.tag
 
        # Custom Configuration
 
@@ -161,6 +187,16 @@ class Distribution(base.DataObject):
 
        custom_config = property(get_custom_config, set_custom_config)
 
+       # Permissions
+
+       def has_perm(self, user):
+               # Anonymous users have no permissions
+               if not user:
+                       return False
+
+               # Must be admin
+               return user.is_admin()
+
        @lazy_property
        def repos(self):
                repos = self.backend.repos._get_repositories("""
diff --git a/src/templates/distro-edit.html b/src/templates/distro-edit.html
deleted file mode 100644 (file)
index 2f33133..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-{% extends "base.html" %}
-
-{% block title %}{{ _("Edit distribution %s") % distro.name }}{% end block %}
-
-{% block body %}
-       <h1>{{ _("Edit distribution %s") % distro.name }}</h1>
-
-       <form method="post" action="">
-               {% raw xsrf_form_html() %}
-               <table class="form form3">
-                       <tr>
-                               <td class="col1">{{ _("Name") }}</td>
-                               <td class="col2">
-                                       <input type="text" name="name" value="{{ distro.name }}" />
-                               </td>
-                               <td class="col3">
-                                       {{ _("The fancy name of the distribution.") }}
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class="col1">{{ _("Identifier") }}</td>
-                               <td class="col2">
-                                       {{ distro.sname }}
-                               </td>
-                               <td class="col3">
-                                       {{ _("Cannot be changed.") }}
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class="col1">{{ _("Tag") }}</td>
-                               <td class="col2">
-                                       <input type="text" name="tag" value="{{ distro.tag }}" />
-                               </td>
-                               <td class="col3">
-                                       {{ _("The tag is added to the package release.") }}
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class="col1">{{ _("Vendor") }}</td>
-                               <td class="col2">
-                                       <input type="text" name="vendor" value="{{ distro.vendor }}" />
-                               </td>
-                               <td class="col3">
-                                       {{ _("From whom is the distribution from?") }}
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class="col1">{{ _("Contact") }}</td>
-                               <td class="col2">
-                                       <input type="text" name="contact" value="{{ distro.contact or "" }}" />
-                               </td>
-                               <td>
-                                       {{ _("The email address from the vendor.") }}
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class="col1">{{ _("Slogan") }}</td>
-                               <td class="col2">
-                                       <input type="text" name="slogan" value="{{ distro.slogan }}" />
-                               </td>
-                               <td class="col3">
-                                       {{ _("A short sentence that characterizes the distribution.") }}
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class="col1">{{ _("Architectures") }}</td>
-                               <td class="col2">
-                                       <select name="arches" size="4" multiple>
-                                               {% for arch in arches %}
-                                                       <option value="{{ arch }}" {% if arch in distro.arches %}selected{% end %}>{{ arch }}</option>
-                                               {% end %}
-                                       </select>
-                               </td>
-                               <td class="col3">
-                                       {{ _("For which architectures should the distribution be built?") }}
-                               </td>
-                       </tr>
-                       <tr>
-                               <td class="col1">{{ _("Sources") }}</td>
-                               <td class="col2">
-                                       <select name="sources" size="4" multiple>
-                                               {% for source in sources %}
-                                                       <option value="{{ source.id }}" {% if source in distro.sources %}selected="selected"{% end %}>{{ source.name }}</option>
-                                               {% end %}
-                                       </select>
-                               </td>
-                               <td class="col3">
-                                       {{ _("Which sources should be imported to the distribution?") }}
-                               </td>
-                       </tr>
-                       <tr>
-                               <td colspan="3" class="buttons">
-                                       <input type="submit" value="{{ _("Save") }}" />
-                               </td>
-                       </tr>
-               </table>
-               <div style="clear: both;">&nbsp;</div>
-       </form>
-{% end block %}
diff --git a/src/templates/distros/edit.html b/src/templates/distros/edit.html
new file mode 100644 (file)
index 0000000..6a1c72c
--- /dev/null
@@ -0,0 +1,110 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ _("Distributions") }} - {{ distro }} - {{ _("Edit") }}{% end block %}
+
+{% block container %}
+       {% import pakfire %}
+
+       <nav class="breadcrumb" aria-label="breadcrumbs">
+               <ul>
+                       <li>
+                               <a href="/distros">{{ _("Distributions") }}</a>
+                       </li>
+                       <li>
+                               <a href="/distros/{{ distro.slug }}">{{ distro }}</a>
+                       </li>
+                       <li class="is-active">
+                               <a href="#" aria-current="page">{{ _("Edit") }}</a>
+                       </li>
+               </ul>
+       </nav>
+
+       <div class="columns is-centered">
+               <div class="column is-6">
+                       <form method="POST" action="">
+                               <div class="box">
+                                       {% raw xsrf_form_html() %}
+
+                                       {# Name #}
+                                       <div class="field">
+                                               <label class="label">{{ _("Name") }}</label>
+                                               <div class="control">
+                                                       <input class="input" type="text"
+                                                               name="name" value="{{ distro.name }}" required>
+                                               </div>
+                                               <p class="help">
+                                                       {{ _("The name of this distributions") }}
+                                               </p>
+                                       </div>
+
+                                       <fieldset>
+                                               {# Vendor #}
+                                               <div class="field">
+                                                       <label class="label">{{ _("Vendor") }}</label>
+                                                       <div class="control">
+                                                               <input class="input" type="text"
+                                                                       name="vendor" value="{{ distro.vendor }}">
+                                                       </div>
+                                                       <p class="help">
+                                                               {{ _("The vendor of this distributions") }}
+                                                       </p>
+                                               </div>
+
+                                               {# Contact #}
+                                               <div class="field">
+                                                       <label class="label">{{ _("Contact") }}</label>
+                                                       <div class="control">
+                                                               <input class="input" type="text"
+                                                                       name="contact" value="{{ distro.contact }}">
+                                                       </div>
+                                                       <p class="help">
+                                                               {{ _("The contact of this distributions") }}
+                                                       </p>
+                                               </div>
+
+                                               {# Slogan #}
+                                               <div class="field">
+                                                       <label class="label">{{ _("Slogan") }}</label>
+                                                       <div class="control">
+                                                               <input class="input" type="text"
+                                                                       name="slogan" value="{{ distro.slogan }}">
+                                                       </div>
+                                                       <p class="help">
+                                                               {{ _("The slogan of this distributions") }}
+                                                       </p>
+                                               </div>
+                                       </fieldset>
+
+                                       <div class="field">
+                                               <label class="label">{{ _("Architectures") }}</label>
+
+                                               <div class="control">
+                                                       <div class="select is-multiple">
+                                                               <select multiple name="arches">
+                                                                       {% for arch in pakfire.supported_arches() %}
+                                                                               <option value="{{ arch }}"
+                                                                                       {% if arch in distro.arches %}selected{% end %}>{{ arch }}</option>
+                                                                       {% end %}
+                                                               </select>
+                                                       </div>
+                                               </div>
+                                       </div>
+
+                                       <div class="field is-grouped">
+                                               <div class="control">
+                                                       <button class="button is-success is-link" type="submit">
+                                                               {{ _("Save") }}
+                                                       </button>
+                                               </div>
+
+                                               <div class="control">
+                                                       <a class="button is-danger is-outlined is-link" href="/distros/{{ distro.slug }}/delete">
+                                                               {{ _("Delete") }}
+                                                       </a>
+                                               </div>
+                                       </div>
+                               </div>
+                       </form>
+               </div>
+       </div>
+{% end block %}
index a3415935106c52050c2459377e8542d7cf82ef85..05d43b802522a94ea414246cc345a069b461f8ba 100644 (file)
                                                </div>
                                        </div>
                                </nav>
+
+                               <div class="buttons are-small">
+                                       {% if distro.has_perm(current_user) %}
+                                               <a class="button is-warning" href="/distros/{{ distro.slug }}/edit">
+                                                       {{ _("Edit") }}
+                                               </a>
+                                       {% end %}
+                               </div>
                        </div>
                </div>
        {% end %}
index 8d4a41fbcc5b3d1fb10a68085179ceb5eac6a26a..33bad7be1a732d07badc2087dc14699401d2d560 100644 (file)
@@ -145,6 +145,7 @@ class Application(tornado.web.Application):
                        # Distributions
                        (r"/distros", distributions.IndexHandler),
                        (r"/distros/([A-Za-z0-9\-\.]+)", distributions.ShowHandler),
+                       (r"/distros/([A-Za-z0-9\-\.]+)/edit", distributions.EditHandler),
                        (r"/distros/(?P<distro_slug>[A-Za-z0-9\-\.]+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)",
                                repos.ShowHandler),
                        (r"/distros/(?P<distro_slug>[A-Za-z0-9\-\.]+)/repos/(?P<repo_slug>[A-Za-z0-9\-]+)\.repo",
index 6b22f51a62cb90c53aa80d5027cc7924e43ef3a5..3bd68f87fac975cf86ff7267655c61c0d68b4e25 100644 (file)
@@ -19,44 +19,33 @@ class ShowHandler(base.BaseHandler):
                self.render("distros/show.html", distro=distro)
 
 
-class DistributionEditHandler(base.BaseHandler):
-       def prepare(self):
-               self.sources = self.backend.sources.get_all()
-
+class EditHandler(base.BaseHandler):
        @tornado.web.authenticated
-       def get(self, name):
-               distro = self.backend.distros.get_by_slug(name)
+       def get(self, slug):
+               distro = self.backend.distros.get_by_slug(slug)
                if not distro:
-                       raise tornado.web.HTTPError(404, "Distro not found")
+                       raise tornado.web.HTTPError(404, "Could not find distribution: %s" % slug)
+
+               # Check for permissions
+               if not distro.has_perm(self.current_user):
+                       raise tornado.web.HTTPError(403)
 
-               self.render("distro-edit.html", distro=distro, sources=self.sources)
+               self.render("distros/edit.html", distro=distro)
 
        @tornado.web.authenticated
-       def post(self, name):
-               distro = self.backend.distros.get_by_slug(name)
+       def post(self, slug):
+               distro = self.backend.distros.get_by_slug(slug)
                if not distro:
-                       raise tornado.web.HTTPError(404, "Distro not found")
-
-               name = self.get_argument("name", distro.name)
-               vendor = self.get_argument("vendor", distro.vendor)
-               contact = self.get_argument("contact", "")
-               slogan = self.get_argument("slogan", distro.slogan)
-               tag = self.get_argument("tag", "")
-
-               distro.set("name", name)
-               distro.set("vendor", vendor)
-               distro.set("slogan", slogan)
-
-               # Update the contact email address.
-               distro.contact = contact
-
-               # Update the tag.
-               distro.tag = tag
+                       raise tornado.web.HTTPError(404, "Could not find distribution: %s" % slug)
 
-               # Update architectures
-               distro.arches = self.get_arguments("arches", [])
+               with self.db.transaction():
+                       distro.name    = self.get_argument("name")
+                       distro.vendor  = self.get_argument("vendor", None)
+                       distro.contact = self.get_argument("contact", None)
+                       distro.slogan  = self.get_argument("slogan", None)
+                       distro.arches  = self.get_arguments("arches")
 
-               self.redirect("/distribution/%s" % distro.slug)
+               self.redirect("/distros/%s" % distro.slug)
 
 
 class DistroSourceDetailHandler(base.BaseHandler):