Unverified Commit 640c5ad3 authored by Enrico Zini's avatar Enrico Zini
Browse files

Added api/salsa_status to map salsa IDs to people

parent 3bc702a7
Pipeline #263565 failed with stage
in 5 minutes and 15 seconds
......@@ -84,3 +84,46 @@ class TestStatusAllPermissions(BaseFixtureMixin, TestCase):
'dd_nu@debian.org': {'status': 'dd_nu'}
},
})
class TestSalsaStatus(BaseFixtureMixin, TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.add_named_objects(keys=NamedObjects(Key))
cls.create_person("dc", status=const.STATUS_DC, alioth=True)
cls.create_person("dd_nu", status=const.STATUS_DD_NU)
cls.identities.create(
"dc", person=cls.persons.dc, issuer="salsa", subject="1", username="dc", audit_skip=True)
cls.identities.create(
"dd_nu", person=cls.persons.dd_nu, issuer="salsa", subject="2", username="dd_nu", audit_skip=True)
cls.identities.create(
"unmapped", issuer="salsa", subject="3", username="unmapped", audit_skip=True)
def test_missing(self):
client = self.make_test_client(None)
response = client.get(reverse("api:salsa_status", kwargs={"subject": 4}))
self.assertEqual(response.status_code, 404)
def test_unmapped(self):
client = self.make_test_client(None)
response = client.get(reverse("api:salsa_status", kwargs={"subject": 3}))
self.assertJSONEqual(response.content, {
"profile": None,
"status": None,
})
def test_existing(self):
client = self.make_test_client(None)
response = client.get(reverse("api:salsa_status", kwargs={"subject": 1}))
self.assertJSONEqual(response.content, {
"profile": "/person/dc/",
"status": "dc",
})
response = client.get(reverse("api:salsa_status", kwargs={"subject": 2}))
self.assertJSONEqual(response.content, {
"profile": "/person/dd_nu/",
"status": "dd_nu",
})
......@@ -11,4 +11,5 @@ urlpatterns = [
path('status/', views.Status.as_view(), name="status"),
path('whoami/', views.Whoami.as_view(), name="whoami"),
path('export_identities', views.ExportIdentities.as_view(), name="export_identities"),
path('salsa_status/<int:subject>', views.SalsaStatus.as_view(), name="salsa_status"),
]
......@@ -4,6 +4,7 @@ from django.core.exceptions import PermissionDenied
from django.forms.models import model_to_dict
from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
from django.shortcuts import get_object_or_404
from rest_framework.views import APIView
import backend.models as bmodels
from apikeys.mixins import APIVisitorMixin
......@@ -228,3 +229,26 @@ class ExportIdentities(APIVisitorMixin, APIView):
res = http.HttpResponse(content_type="application/json")
json.dump(list(by_person.values()), res, indent=1, cls=Serializer)
return res
class SalsaStatus(APIVisitorMixin, APIView):
def get(self, request, *args, **kw):
from signon.models import Identity
identity = get_object_or_404(Identity, issuer="salsa", subject=self.kwargs["subject"])
if identity.person is None:
data = {
"profile": None,
"status": None,
}
else:
data = {
"profile": identity.person.get_absolute_url(),
"status": identity.person.status,
}
res = http.HttpResponse(content_type="application/json")
json.dump(data, res, indent=1, cls=Serializer)
return res
@csrf_exempt
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment