~rjarry/dlrepo

ae06a5fa8e07f89e6632fbd3b65c473a5271c99d — Julien Floret 1 year, 2 months ago 18c4878
templates: add branch links to product page

To ease navigation between the product page and the original job(s) in
/branches/, add a "Branch Link(s)" section to the bottom of the
product page (similar to the "Product Link" section at the bottom of
the job page).

The branch links are not displayed if the user does not have the
rights to access the job (typically, customers should have access to
/products/ but not to /branches/).

Signed-off-by: Julien Floret <julien.floret@6wind.com>
Acked-by: Thomas Faivre <thomas.faivre@6wind.com>
2 files changed, 24 insertions(+), 0 deletions(-)

M dlrepo/templates/product_version.html
M dlrepo/views/product.py
M dlrepo/templates/product_version.html => dlrepo/templates/product_version.html +14 -0
@@ 37,4 37,18 @@

  {{macros.install_procedure(version.name, version.artifact_formats)}}
</section>

{% if version.branch_links %}
<section class="product-link">
  <h2>Branch Link{{'s' if version.branch_links|length > 1}}</h2>
  <hr/>
  {% for link in version.branch_links|sort %}
  <a href="/{{'~' + user + '/' if user}}branches/{{link}}/"
     title="Branch link" class="product">
    <span>{{link.split('/')[-1]}}</span>
  </a>
  {% endfor %}
</section>
{% endif %}

{% endblock %}

M dlrepo/views/product.py => dlrepo/views/product.py +10 -0
@@ 183,6 183,7 @@ class VersionView(BaseView):
        html = "html" in self.request.headers.get("Accept", "json")

        formats = []
        branch_links = []
        for fmt in version.get_formats():
            fmt_url = fmt.url()
            if self.access_granted(fmt_url):


@@ 202,12 203,21 @@ class VersionView(BaseView):
                            "url": fmt_url,
                        }
                    )
                    job = fmt.path().resolve().parent
                    link = f"{job.parent.parent.name}/{job.parent.name}/{job.name}"
                    if link not in branch_links and self.access_granted(
                        fmt.root().url() + link
                    ):
                        branch_links.append(link)
                else:
                    formats.append(fmt.name)

        data = {"version": {"name": version.name, "artifact_formats": formats}}

        if html:
            if branch_links:
                data["version"]["branch_links"] = branch_links

            return aiohttp_jinja2.render_template(
                "product_version.html", self.request, data
            )