diff --git a/assets/src/bundles/add_forge/moderation-dashboard.js b/assets/src/bundles/add_forge/moderation-dashboard.js --- a/assets/src/bundles/add_forge/moderation-dashboard.js +++ b/assets/src/bundles/add_forge/moderation-dashboard.js @@ -50,6 +50,16 @@ name: 'forge_url', render: $.fn.dataTable.render.text() }, + { + data: 'last_moderator', + name: 'last_moderator', + render: $.fn.dataTable.render.text() + }, + { + data: 'last_modified_date', + name: 'last_modified_date', + render: getHumanReadableDate + }, { data: 'status', name: 'status', diff --git a/swh/web/add_forge_now/views.py b/swh/web/add_forge_now/views.py --- a/swh/web/add_forge_now/views.py +++ b/swh/web/add_forge_now/views.py @@ -71,8 +71,7 @@ else: requests = AddForgeNowRequestPublicSerializer(page.object_list, many=True).data - results = [dict(request) for request in requests] - + results = [dict(req) for req in requests] table_data["recordsFiltered"] = add_forge_requests.count() table_data["data"] = results return JsonResponse(table_data) diff --git a/swh/web/api/views/add_forge_now.py b/swh/web/api/views/add_forge_now.py --- a/swh/web/api/views/add_forge_now.py +++ b/swh/web/api/views/add_forge_now.py @@ -9,6 +9,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.core.paginator import Paginator from django.db import transaction +from django.db.models.query import QuerySet from django.forms import CharField, ModelForm from django.http import HttpResponseBadRequest from django.http.request import HttpRequest @@ -62,10 +63,38 @@ class AddForgeNowRequestSerializer(serializers.ModelSerializer): + + last_moderator = serializers.SerializerMethodField() + last_modified_date = serializers.SerializerMethodField() + history: Dict[int, QuerySet] = {} + class Meta: model = AddForgeRequest fields = "__all__" + def _gethistory(self, request): + if request.id not in self.history: + self.history[request.id] = AddForgeNowRequestHistory.objects.filter( + request=request + ).order_by("id") + return self.history[request.id] + + def get_last_moderator(self, request): + last_history_with_moderator = ( + self._gethistory(request).filter(actor_role="MODERATOR").last() + ) + return ( + last_history_with_moderator.actor if last_history_with_moderator else "None" + ) + + def get_last_modified_date(self, request): + last_history = self._gethistory(request).last() + return ( + last_history.date.isoformat().replace("+00:00", "Z") + if last_history + else None + ) + class AddForgeNowRequestPublicSerializer(serializers.ModelSerializer): """Serializes AddForgeRequest without private fields.""" diff --git a/swh/web/templates/add_forge_now/requests-moderation.html b/swh/web/templates/add_forge_now/requests-moderation.html --- a/swh/web/templates/add_forge_now/requests-moderation.html +++ b/swh/web/templates/add_forge_now/requests-moderation.html @@ -30,6 +30,8 @@ Submission date Forge type Forge URL + Moderator Name + Last Modified Date Status diff --git a/swh/web/tests/api/views/test_add_forge_now.py b/swh/web/tests/api/views/test_add_forge_now.py --- a/swh/web/tests/api/views/test_add_forge_now.py +++ b/swh/web/tests/api/views/test_add_forge_now.py @@ -114,6 +114,8 @@ "submitter_name": regular_user.username, "submitter_email": regular_user.email, "submitter_forward_username": expected_consent_bool, + "last_moderator": resp.data["last_moderator"], + "last_modified_date": resp.data["last_modified_date"], } assert date_before < iso8601.parse_date(resp.data["submission_date"]) < date_after @@ -143,11 +145,13 @@ assert resp.data == { **ADD_FORGE_DATA_FORGE1, - "id": 1, + "id": resp.data["id"], "status": "PENDING", "submission_date": resp.data["submission_date"], "submitter_name": regular_user.username, "submitter_email": regular_user.email, + "last_moderator": resp.data["last_moderator"], + "last_modified_date": resp.data["last_modified_date"], } assert date_before < iso8601.parse_date(resp.data["submission_date"]) < date_after @@ -330,7 +334,7 @@ "forge_type": ADD_FORGE_DATA_FORGE1["forge_type"], "status": "PENDING", "submission_date": resp.data[0]["submission_date"], - "id": 1, + "id": resp.data[0]["id"], } assert resp.data == [add_forge_request] @@ -344,7 +348,7 @@ "forge_type": ADD_FORGE_DATA_FORGE2["forge_type"], "status": "PENDING", "submission_date": resp.data[0]["submission_date"], - "id": 2, + "id": resp.data[0]["id"], } assert resp.data == [other_forge_request, add_forge_request] @@ -368,7 +372,9 @@ "submission_date": resp.data[1]["submission_date"], "submitter_name": regular_user.username, "submitter_email": regular_user.email, - "id": 1, + "last_moderator": resp.data[1]["last_moderator"], + "last_modified_date": resp.data[1]["last_modified_date"], + "id": resp.data[1]["id"], } other_forge_request = { @@ -377,7 +383,9 @@ "submission_date": resp.data[0]["submission_date"], "submitter_name": regular_user.username, "submitter_email": regular_user.email, - "id": 2, + "last_moderator": resp.data[0]["last_moderator"], + "last_modified_date": resp.data[0]["last_modified_date"], + "id": resp.data[0]["id"], } assert resp.data == [other_forge_request, add_forge_request] @@ -500,6 +508,7 @@ url = reverse("api-1-add-forge-request-get", url_args={"id": 1}) resp = check_api_get_responses(api_client, url, status_code=200) + resp.data["history"] = [dict(history_item) for history_item in resp.data["history"]] assert resp.data == { "request": { @@ -509,6 +518,8 @@ "submission_date": submission_date, "submitter_name": regular_user.username, "submitter_email": regular_user.email, + "last_moderator": add_forge_moderator.username, + "last_modified_date": resp.data["history"][1]["date"], }, "history": [ {