Changeset View
Changeset View
Standalone View
Standalone View
swh/web/admin/deposit.py
# Copyright (C) 2018-2022 The Software Heritage developers | # Copyright (C) 2018-2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import sentry_sdk | import sentry_sdk | ||||
from django.conf import settings | from django.conf import settings | ||||
from django.contrib.auth.decorators import user_passes_test | from django.contrib.auth.decorators import user_passes_test | ||||
from django.core.paginator import Paginator | from django.core.paginator import Paginator | ||||
from django.http import JsonResponse | from django.http import JsonResponse | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from swh.web.admin.adminurls import admin_route | from swh.web.admin.adminurls import admin_route | ||||
from swh.web.auth.utils import ADMIN_LIST_DEPOSIT_PERMISSION | from swh.web.auth.utils import ADMIN_LIST_DEPOSIT_PERMISSION | ||||
from swh.web.common.utils import ( | from swh.web.common.utils import ( | ||||
get_deposit_raw_metadata, | |||||
get_deposits_list, | get_deposits_list, | ||||
parse_swh_deposit_origin, | parse_swh_deposit_origin, | ||||
parse_swh_metadata_provenance, | parse_swh_metadata_provenance, | ||||
) | ) | ||||
def _can_list_deposits(user): | def _can_list_deposits(user): | ||||
return user.is_staff or user.has_perm(ADMIN_LIST_DEPOSIT_PERMISSION) | return user.is_staff or user.has_perm(ADMIN_LIST_DEPOSIT_PERMISSION) | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | try: | ||||
# This could be large. As this is not displayed yet, drop it to avoid | # This could be large. As this is not displayed yet, drop it to avoid | ||||
# cluttering the data dict | # cluttering the data dict | ||||
data_dict.pop("raw_metadata", None) | data_dict.pop("raw_metadata", None) | ||||
data_list.append(data_dict) | data_list.append(data_dict) | ||||
table_data["data"] = data_list | table_data["data"] = data_list | ||||
for row in table_data["data"]: | |||||
metadata = get_deposit_raw_metadata(row["id"]) | |||||
if metadata: | |||||
row["raw_metadata"] = metadata[-1] | |||||
else: | |||||
row["raw_metadata"] = None | |||||
except Exception as exc: | except Exception as exc: | ||||
sentry_sdk.capture_exception(exc) | sentry_sdk.capture_exception(exc) | ||||
table_data[ | table_data["error"] = f"Could not retrieve deposits: {exc!r}" | ||||
"error" | |||||
] = "An error occurred while retrieving the list of deposits !" | |||||
return JsonResponse(table_data) | return JsonResponse(table_data) |