Merge pull request #532 from mozilla/issue-530-remove-signup-route
Remove /signup route and its related code
This commit is contained in:
Коммит
d8c52a2d91
|
@ -31,10 +31,6 @@ env = environ.Env(
|
|||
CORS_ORIGIN_REGEX_WHITELIST=(list, []),
|
||||
CORS_ORIGIN_WHITELIST=(list, []),
|
||||
CSRF_TRUSTED_ORIGINS=(list, []),
|
||||
AWS_SQS_REGION=(str, None),
|
||||
AWS_SQS_ACCESS_KEY_ID=(str, None),
|
||||
AWS_SQS_SECRET_ACCESS_KEY=(str, None),
|
||||
SQS_QUEUE_URL=(str, None),
|
||||
DEBUG=(bool, False),
|
||||
DJANGO_LOG_LEVEL=(str, 'INFO'),
|
||||
HEROKU_APP_NAME=(str, ''),
|
||||
|
@ -350,11 +346,6 @@ else:
|
|||
MEDIA_ROOT = root('media/')
|
||||
MEDIA_URL = '/media/'
|
||||
|
||||
AWS_SQS_REGION = env('AWS_SQS_REGION')
|
||||
AWS_SQS_ACCESS_KEY_ID = env('AWS_SQS_ACCESS_KEY_ID')
|
||||
AWS_SQS_SECRET_ACCESS_KEY = env('AWS_SQS_SECRET_ACCESS_KEY')
|
||||
SQS_QUEUE_URL = env('SQS_QUEUE_URL')
|
||||
|
||||
# Remove the default Django loggers and configure new ones
|
||||
LOGGING_CONFIG = None
|
||||
LOGGING = {
|
||||
|
|
|
@ -20,9 +20,6 @@ from django.conf.urls.static import static
|
|||
from ajax_select import urls as ajax_select_urls
|
||||
|
||||
from pulseapi.profiles.views import UserProfileAPIView
|
||||
from pulseapi.utility.newsletters.signup import (
|
||||
signup_submission_view
|
||||
)
|
||||
from pulseapi.utility.syndication import (
|
||||
RSSFeedLatestFromPulse,
|
||||
AtomFeedLatestFromPulse,
|
||||
|
@ -68,9 +65,6 @@ urlpatterns = [
|
|||
|
||||
# Autocomplete
|
||||
url(r'^ajax_select/', include(ajax_select_urls)),
|
||||
|
||||
# Newsletter signup
|
||||
url(r'signup/', signup_submission_view, name='newsletter-signup'),
|
||||
]
|
||||
|
||||
if settings.USE_S3 is not True:
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
from rest_framework.decorators import api_view, parser_classes, permission_classes
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.parsers import JSONParser
|
||||
from rest_framework import status, permissions
|
||||
from django.conf import settings
|
||||
from datetime import datetime
|
||||
|
||||
import boto3
|
||||
import logging
|
||||
import json
|
||||
|
||||
|
||||
class SQSProxy:
|
||||
"""
|
||||
We use a proxy class to make sure that code that
|
||||
relies on SQS posting still works, even when there
|
||||
is no "real" sqs client available to work with.
|
||||
"""
|
||||
|
||||
def send_message(self, QueueUrl, MessageBody):
|
||||
"""
|
||||
As a proxy function, the only thing we report
|
||||
is that "things succeeded!" even though nothing
|
||||
actually happened.
|
||||
"""
|
||||
|
||||
return {
|
||||
'MessageId': True
|
||||
}
|
||||
|
||||
|
||||
# Basket/Salesforce SQS client - Proxy first...
|
||||
crm_sqs = {
|
||||
'client': SQSProxy()
|
||||
}
|
||||
|
||||
# But if there's an SQS access key, bind a "real client".
|
||||
if settings.AWS_SQS_ACCESS_KEY_ID:
|
||||
crm_sqs['client'] = boto3.client(
|
||||
'sqs',
|
||||
region_name=settings.AWS_SQS_REGION,
|
||||
aws_access_key_id=settings.AWS_SQS_ACCESS_KEY_ID,
|
||||
aws_secret_access_key=settings.AWS_SQS_SECRET_ACCESS_KEY,
|
||||
)
|
||||
|
||||
|
||||
# sqs destination for salesforce
|
||||
crm_queue_url = settings.SQS_QUEUE_URL
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@parser_classes((JSONParser,))
|
||||
@permission_classes((permissions.AllowAny,))
|
||||
def signup_submission_view(request):
|
||||
|
||||
for parameter in ('email', 'source'):
|
||||
if parameter not in request.data:
|
||||
return Response(
|
||||
{'error': f'Missing {parameter} parameter'},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
data = {
|
||||
"email": request.data['email'],
|
||||
"lang": "en",
|
||||
"format": "html",
|
||||
"source_url": request.data['source'],
|
||||
"newsletters": 'mozilla-foundation',
|
||||
}
|
||||
|
||||
message = json.dumps({
|
||||
'app': settings.HEROKU_APP_NAME,
|
||||
'timestamp': datetime.now().isoformat(),
|
||||
'data': {
|
||||
'json': True,
|
||||
'form': data,
|
||||
'event_type': 'newsletter_signup_data'
|
||||
}
|
||||
})
|
||||
|
||||
return send_to_sqs(crm_sqs['client'], crm_queue_url, message)
|
||||
|
||||
|
||||
def send_to_sqs(sqs, queue_url, message, type='signup'):
|
||||
if settings.DEBUG is True:
|
||||
logger.info(f'Sending {type} message: {message}')
|
||||
|
||||
if queue_url is None:
|
||||
logger.warning(f'{type} was not submitted: No {type} SQS url was specified')
|
||||
return Response({'message': 'success'}, 201)
|
||||
|
||||
try:
|
||||
response = sqs.send_message(
|
||||
QueueUrl=queue_url,
|
||||
MessageBody=message
|
||||
)
|
||||
except Exception as error:
|
||||
logger.error(f'Failed to send {type} with: {error}')
|
||||
return Response(
|
||||
{'error': f'Failed to queue up {type}'},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
)
|
||||
|
||||
if 'MessageId' in response and response['MessageId']:
|
||||
return Response({'message': 'success'}, 201)
|
||||
else:
|
||||
return Response(
|
||||
{'error': f'Something went wrong with {type}'},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
)
|
|
@ -1,44 +0,0 @@
|
|||
import json
|
||||
|
||||
from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
||||
class TestNewsletterSignup(TestCase):
|
||||
|
||||
def test_newsletter_signup(self):
|
||||
"""
|
||||
Check that the signup url exists, and does not support GET
|
||||
"""
|
||||
response = self.client.get(reverse('newsletter-signup'))
|
||||
self.assertEqual(response.status_code, 405)
|
||||
|
||||
def test_bad_news_letter_post_missing_content_type(self):
|
||||
# wrong media type (missing content_type)
|
||||
payload = {
|
||||
'email': 'test@example.com',
|
||||
'source': 'http://test.example.com/',
|
||||
}
|
||||
response = self.client.post(reverse('newsletter-signup'), payload)
|
||||
self.assertEqual(response.status_code, 415)
|
||||
|
||||
def test_bad_news_letter_post_missing_data(self):
|
||||
# missing email
|
||||
payload = json.dumps({'source': 'http://test.example.com'})
|
||||
response = self.client.post(reverse('newsletter-signup'), payload, content_type='application/json')
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
# missing source
|
||||
payload = json.dumps({'email': 'test@example.com'})
|
||||
response = self.client.post(reverse('newsletter-signup'), payload, content_type='application/json')
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
def test_proper_news_letter_post(self):
|
||||
payload = json.dumps({
|
||||
'email': 'test@example.com',
|
||||
'source': 'http://test.example.com/',
|
||||
})
|
||||
|
||||
response = self.client.post(reverse('newsletter-signup'), payload, content_type='application/json')
|
||||
|
||||
self.assertEqual(response.status_code, 201)
|
|
@ -8,9 +8,3 @@ CSRF_TRUSTED_ORIGINS=localhost:3000,localhost:8000,localhost:8080,test.example.c
|
|||
SSL_PROTECTION=False
|
||||
AUTH_STAFF_EMAIL_DOMAINS=mozillafoundation.org
|
||||
LOGIN_ALLOWED_REDIRECT_DOMAINS=test.example.com:3000
|
||||
|
||||
# SQS information is requied for newsletter signups
|
||||
AWS_SQS_REGION=
|
||||
AWS_SQS_ACCESS_KEY_ID=
|
||||
AWS_SQS_SECRET_ACCESS_KEY=
|
||||
SQS_QUEUE_URL=
|
||||
|
|
Загрузка…
Ссылка в новой задаче