~rjarry/dlrepo

3837eab5c95540ab3dfa6405ab719c438b095cf7 — Julien Floret 10 months ago 978cf6f
fmt: refuse deletion in product view

Deleting product formats is not supported.

Fixes: 6de1f15cfcf8 ("format: add delete method")
Signed-off-by: Julien Floret <julien.floret@6wind.com>
Acked-by: Thomas Faivre <thomas.faivre@6wind.com>
Acked-by: Robin Jarry <robin@jarry.cc>
1 files changed, 8 insertions(+), 2 deletions(-)

M dlrepo/views/fmt.py
M dlrepo/views/fmt.py => dlrepo/views/fmt.py +8 -2
@@ 78,7 78,7 @@ class FormatDirView(BaseView):
        """
        loop = asyncio.get_running_loop()
        try:
            fmt = _get_format(self.repo(), self.request.match_info)
            fmt = _get_format(self.repo(), self.request.match_info, delete=True)
            await loop.run_in_executor(None, fmt.delete)
            self.repo().schedule_cleanup_orphans()
        except FileNotFoundError as e:


@@ 175,9 175,15 @@ class FormatFileView(BaseView):


# --------------------------------------------------------------------------------------
def _get_format(repo, match_info, access_cb: Callable[[str], bool] = None):
def _get_format(
    repo, match_info, access_cb: Callable[[str], bool] = None, delete=False
):
    try:
        if "product" in match_info:
            if delete:
                raise web.HTTPBadRequest(
                    reason="Deleting product formats is not supported"
                )
            fmt = (
                repo.get_product(match_info["product"])
                .get_variant(match_info["variant"])