From d8b11c42932351232e86ba7b67d740d60eda1667 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Fri, 17 Jul 2020 19:33:15 +0000 Subject: [PATCH] Removed an unused and unnecessary API endpoint, now that gather.town has gotten OpenID Connect authentication working. - Legacy-Id: 18190 --- ietf/api/tests.py | 18 ---------- ietf/api/urls.py | 2 -- ietf/api/views.py | 33 +++++++++++-------- .../commands/send_apikey_usage_emails.py | 0 ietf/ietfauth/tests.py | 7 ++-- ietf/person/models.py | 1 - 6 files changed, 24 insertions(+), 37 deletions(-) rename ietf/{utils => ietfauth}/management/commands/send_apikey_usage_emails.py (100%) diff --git a/ietf/api/tests.py b/ietf/api/tests.py index 983226962..4d7fb91cb 100644 --- a/ietf/api/tests.py +++ b/ietf/api/tests.py @@ -277,24 +277,6 @@ class CustomApiTests(TestCase): self.assertEqual(data['user']['email'], secretariat.user.email) - def test_api_v2_person_access_meetecho(self): - url = urlreverse('ietf.api.views.person_access_meetecho') - person = PersonFactory() - apikey = PersonalApiKey.objects.create(endpoint=url, person=person) - - # error cases - r = self.client.get(url, {'apikey': apikey.hash()}) - self.assertContains(r, "Too long since last regular login", status_code=400) - person.user.last_login = timezone.now() - person.user.save() - - # working case - r = self.client.get(url, {'apikey': apikey.hash()}) - self.assertEqual(r.status_code, 200) - data = r.json() - self.assertEqual(data['name'], person.plain_name()) - self.assertEqual(data['email'], person.email().address) - def test_api_new_meeting_registration(self): meeting = MeetingFactory(type_id='ietf') reg = { diff --git a/ietf/api/urls.py b/ietf/api/urls.py index 9507b096e..686f1e7c2 100644 --- a/ietf/api/urls.py +++ b/ietf/api/urls.py @@ -34,8 +34,6 @@ urlpatterns = [ url(r'^notify/meeting/registration/?', api_views.api_new_meeting_registration), # OpenID authentication provider url(r'^openid/', include('oidc_provider.urls', namespace='oidc_provider')), - # For meetecho access - url(r'^person/access/meetecho', api_views.person_access_meetecho), # Draft submission API url(r'^submit/?$', submit_views.api_submit), ] diff --git a/ietf/api/views.py b/ietf/api/views.py index 9a6a7a78f..22756e24f 100644 --- a/ietf/api/views.py +++ b/ietf/api/views.py @@ -102,19 +102,26 @@ class ApiV2PersonExportView(DetailView, JsonExportMixin): return self.json_view(request, filter=querydict.dict(), expand=expand) -@require_api_key -@csrf_exempt -def person_access_meetecho(request): - person = get_object_or_404(Person, user=request.user) - - return HttpResponse(json.dumps({ - 'name' : person.plain_name(), - 'email': person.email().address, - 'roles': { - 'chair': list(person.role_set.filter(name='chair', group__state__in=['active', 'bof', 'proposed']).values_list('group__acronym', flat=True)), - 'secr': list(person.role_set.filter(name='secr', group__state__in=['active', 'bof', 'proposed']).values_list('group__acronym', flat=True)), - } - }), content_type='application/json') +# @require_api_key +# @csrf_exempt +# def person_access_token(request): +# person = get_object_or_404(Person, user=request.user) +# +# if request.method == 'POST': +# client_id = request.POST.get('client_id', None) +# client_secret = request.POST.get('client_secret', None) +# client = get_object_or_404(ClientRecord, client_id=client_id, client_secret=client_secret) +# +# return HttpResponse(json.dumps({ +# 'name' : person.plain_name(), +# 'email': person.email().address, +# 'roles': { +# 'chair': list(person.role_set.filter(name='chair', group__state__in=['active', 'bof', 'proposed']).values_list('group__acronym', flat=True)), +# 'secr': list(person.role_set.filter(name='secr', group__state__in=['active', 'bof', 'proposed']).values_list('group__acronym', flat=True)), +# } +# }), content_type='application/json') +# else: +# return HttpResponse(status=405) @require_api_key @role_required('Robot') diff --git a/ietf/utils/management/commands/send_apikey_usage_emails.py b/ietf/ietfauth/management/commands/send_apikey_usage_emails.py similarity index 100% rename from ietf/utils/management/commands/send_apikey_usage_emails.py rename to ietf/ietfauth/management/commands/send_apikey_usage_emails.py diff --git a/ietf/ietfauth/tests.py b/ietf/ietfauth/tests.py index fc8629f2a..72ef6729d 100644 --- a/ietf/ietfauth/tests.py +++ b/ietf/ietfauth/tests.py @@ -530,8 +530,9 @@ class IetfAuthTests(TestCase): self.assertTrue(user.check_password('password')) def test_apikey_management(self): - person = PersonFactory() - + # Create a person with a role that will give at least one valid apikey + person = RoleFactory(name_id='secr', group__acronym='secretariat').person + url = urlreverse('ietf.ietfauth.views.apikey_index') # Check that the url is protected, then log in @@ -632,7 +633,7 @@ class IetfAuthTests(TestCase): from ietf.ietfauth.management.commands.send_apikey_usage_emails import Command from ietf.utils.mail import outbox, empty_outbox - person = PersonFactory() + person = RoleFactory(name_id='secr', group__acronym='secretariat').person url = urlreverse('ietf.ietfauth.views.apikey_create') # Check that the url is protected, then log in diff --git a/ietf/person/models.py b/ietf/person/models.py index a22d49978..71d4bb34c 100644 --- a/ietf/person/models.py +++ b/ietf/person/models.py @@ -340,7 +340,6 @@ PERSON_API_KEY_VALUES = [ ("/api/iesg/position", "/api/iesg/position", "Area Director"), ("/api/v2/person/person", "/api/v2/person/person", "Secretariat"), ("/api/meeting/session/video/url", "/api/meeting/session/video/url", "Recording Manager"), - ("/api/person/access/meetecho", "/api/person/access/meetecho", None), ("/api/notify/meeting/registration", "/api/notify/meeting/registration", "Robot"), ] PERSON_API_KEY_ENDPOINTS = [ (v, n) for (v, n, r) in PERSON_API_KEY_VALUES ]