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 @@