Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.5.1 #104

Merged
merged 3 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
See for sample https://raw.githubusercontent.com/favoloso/conventional-changelog-emoji/master/CHANGELOG.md
-->

## [1.5.1] - 2024-02-04
### 🐛 Bug Fixes
- Check **email syntax** on update request (#17)

## [1.5.0] - 2024-01-02
### ✨ Feature
- Make **trial period** customizable (#98)
Expand Down
31 changes: 30 additions & 1 deletion seven23/api/users/tests_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ApiUsersTest(TransactionTestCase):

def setUp(self):
self.client = APIClient()
self.user = User.objects.create_user(username='foo', email='test2@sebastienbarbier.com')

def test_registration_new_user(self):
"""
Expand All @@ -45,10 +46,38 @@ def test_registration_new_user(self):
# Test if response data key is define, a string, and not empty or blank
self.assertTrue('username' in data)
self.assertEqual(data['username'], 'test')
self.assertTrue('email' in data)
self.assertTrue('profile' in data)
self.assertTrue('avatar' in data['profile'])
self.assertTrue('auto_sync' in data['profile'])
self.assertTrue('key_verified' in data['profile'])
self.assertTrue('social_networks' in data['profile'])
self.assertTrue(data['profile']['auto_sync'])
self.assertFalse(data['profile']['key_verified'])
self.assertFalse(data['profile']['key_verified'])


def test_wrong_email_syntax(self):
"""
Create a user using rest-auth and get auth key in response.
"""
self.client.force_authenticate(user=self.user)
# Fetch newly created profile and verify if email is valid
response = self.client.get('/api/v1/rest-auth/user/')
self.assertEqual(response.status_code, status.HTTP_200_OK)
data = response.json()
self.assertEqual(data['email'], 'test2@sebastienbarbier.com')
# Update email with valid email return 200
response = self.client.post('/api/v1/users/email', {
'email': 'test2@sebastienbarbier.com',
}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)

response = self.client.get('/api/v1/rest-auth/user/')
data = response.json()
self.assertEqual(data['email'], 'test2@sebastienbarbier.com')

# Update email with vunalid email return 400
response = self.client.post('/api/v1/users/email', {
'email': 'ThisIsNotAnEmail',
}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
7 changes: 6 additions & 1 deletion seven23/api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rest_framework.authtoken.models import Token
from allauth.account.models import EmailAddress
from django.contrib.auth import authenticate
from django.core.validators import validate_email
from seven23.models.rest_auth.serializers import UserSerializer

@api_view(['POST'])
Expand All @@ -19,7 +20,9 @@ def email(request):
"""
try:
email = EmailAddress.objects.get(user=request.user)
email.email = request.data['email']
new_email = request.data.get("email", "")
validate_email(new_email) # Raises a ValidationError if the email is invalid
email.email = new_email
email.primary = True
email.save()

Expand All @@ -33,6 +36,8 @@ def email(request):

request.user.email = request.data['email']
request.user.save()
except:
return HttpResponse(status=400)

# Return json format string.
j = json.dumps(UserSerializer(request.user).data, separators=(',', ':'))
Expand Down
2 changes: 1 addition & 1 deletion seven23/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
integrations=[DjangoIntegration()]
)

VERSION = [1, 5, 0]
VERSION = [1, 5, 1]
API_VERSION = [1, 1, 0]

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
Expand Down
Loading