diff --git a/swh/web/auth/mailmap.py b/swh/web/auth/mailmap.py --- a/swh/web/auth/mailmap.py +++ b/swh/web/auth/mailmap.py @@ -26,6 +26,15 @@ fields = "__all__" +@api_view(["GET"]) +def profile_list_mailmap(request: Request) -> HttpResponse: + if not request.user.has_perm(MAILMAP_PERMISSION): + return HttpResponseForbidden() + + mms = UserMailmap.objects.filter(user_id=str(request.user.id),).all() + return Response(UserMailmapSerializer(mms, many=True).data) + + @api_view(["POST"]) def profile_add_mailmap(request: Request) -> HttpResponse: if not request.user.has_perm(MAILMAP_PERMISSION): @@ -69,6 +78,7 @@ urlpatterns = [ + url(r"^profile/mailmap/list$", profile_list_mailmap, name="profile-mailmap-list",), url(r"^profile/mailmap/add$", profile_add_mailmap, name="profile-mailmap-add",), url( r"^profile/mailmap/update$", diff --git a/swh/web/tests/auth/test_mailmap.py b/swh/web/tests/auth/test_mailmap.py --- a/swh/web/tests/auth/test_mailmap.py +++ b/swh/web/tests/auth/test_mailmap.py @@ -17,7 +17,11 @@ from swh.web.auth.models import UserMailmap from swh.web.auth.utils import MAILMAP_PERMISSION from swh.web.common.utils import reverse -from swh.web.tests.utils import check_api_post_response, create_django_permission +from swh.web.tests.utils import ( + check_api_post_response, + check_http_get_response, + create_django_permission, +) @pytest.fixture @@ -45,6 +49,18 @@ status_code=200, ) + # FIXME: use check_api_get_responses; currently this crashes without + # content_type="application/json" + resp = check_http_get_response( + api_client, + reverse("profile-mailmap-list"), + status_code=200, + content_type="application/json" + ).data + assert len(resp) == 1 + assert resp[0]["from_email"] == "bar@example.org" + assert resp[0]["display_name"] == "bar" + @pytest.mark.django_db(transaction=True) def test_mailmap_endpoints_error_response(api_client, mailmap_user):