Skip to content

Commit 9d16bb5

Browse files
committed
Merge branch 'bs/fixed_issue_3975_' of github.com:openvinotoolkit/cvat into bs/fixed_issue_3975_
2 parents 1e3f9ac + ce27de9 commit 9d16bb5

File tree

4 files changed

+79
-5
lines changed

4 files changed

+79
-5
lines changed

CHANGELOG.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## \[2.0.0] - Unreleased
99
### Added
10-
1110
- Add additional environment variables for Nuclio configuration (<https://github.com/openvinotoolkit/cvat/pull/3894>)
1211
- Add KITTI segmentation and detection format (<https://github.com/openvinotoolkit/cvat/pull/3757>)
1312
- Add LFW format (<https://github.com/openvinotoolkit/cvat/pull/3770>)
@@ -59,7 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5958
- Bug: canvas is busy when start playing, start resizing a shape and do not release the mouse cursor (<https://github.com/openvinotoolkit/cvat/pull/4151>)
6059
- Fixed tus upload error over https (<https://github.com/openvinotoolkit/cvat/pull/4154>)
6160
- Issues disappear when rescale a browser (<https://github.com/openvinotoolkit/cvat/pull/4189>)
62-
61+
- Auth token key is not returned when registering without email verification (<https://github.com/openvinotoolkit/cvat/pull/4092>)
6362

6463
### Security
6564
- Updated ELK to 6.8.22 which uses log4j 2.17.0 (<https://github.com/openvinotoolkit/cvat/pull/4052>)

cvat/apps/iam/tests/__init__.py

Whitespace-only changes.

cvat/apps/iam/tests/test_rest_api.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright (C) 2021 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
from django.urls import reverse
6+
from rest_framework import status
7+
from rest_framework.test import APITestCase
8+
from rest_framework.authtoken.models import Token
9+
from django.test import override_settings
10+
from cvat.apps.iam.urls import urlpatterns as iam_url_patterns
11+
from django.urls import path, re_path
12+
from allauth.account.views import ConfirmEmailView, EmailVerificationSentView
13+
14+
15+
urlpatterns = iam_url_patterns + [
16+
re_path(r'^account-confirm-email/(?P<key>[-:\w]+)/$', ConfirmEmailView.as_view(),
17+
name='account_confirm_email'),
18+
path('register/account-email-verification-sent', EmailVerificationSentView.as_view(),
19+
name='account_email_verification_sent'),
20+
]
21+
22+
23+
class UserRegisterAPITestCase(APITestCase):
24+
25+
user_data = {'first_name': 'test_first', 'last_name': 'test_last', 'username': 'test_username',
26+
'email': '[email protected]', 'password1': '$Test357Test%', 'password2': '$Test357Test%',
27+
'confirmations': []}
28+
29+
def _run_api_v1_user_register(self, data):
30+
url = reverse('rest_register')
31+
response = self.client.post(url, data, format='json')
32+
return response
33+
34+
def _check_response(self, response, data):
35+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
36+
self.assertEqual(response.data, data)
37+
38+
@override_settings(ACCOUNT_EMAIL_VERIFICATION='none')
39+
def test_api_v1_user_register_with_email_verification_none(self):
40+
"""
41+
Ensure we can register a user and get auth token key when email verification is none
42+
"""
43+
response = self._run_api_v1_user_register(self.user_data)
44+
user_token = Token.objects.get(user__username=response.data['username'])
45+
self._check_response(response, {'first_name': 'test_first', 'last_name': 'test_last',
46+
'username': 'test_username', 'email': '[email protected]',
47+
'email_verification_required': False, 'key': user_token.key})
48+
49+
# Since URLConf is executed before running the tests, so we have to manually configure the url patterns for
50+
# the tests and pass it using ROOT_URLCONF in the override settings decorator
51+
52+
@override_settings(ACCOUNT_EMAIL_VERIFICATION='optional', ROOT_URLCONF=__name__)
53+
def test_api_v1_user_register_with_email_verification_optional(self):
54+
"""
55+
Ensure we can register a user and get auth token key when email verification is optional
56+
"""
57+
response = self._run_api_v1_user_register(self.user_data)
58+
user_token = Token.objects.get(user__username=response.data['username'])
59+
self._check_response(response, {'first_name': 'test_first', 'last_name': 'test_last',
60+
'username': 'test_username', 'email': '[email protected]',
61+
'email_verification_required': False, 'key': user_token.key})
62+
63+
@override_settings(ACCOUNT_EMAIL_REQUIRED=True, ACCOUNT_EMAIL_VERIFICATION='mandatory',
64+
EMAIL_BACKEND='django.core.mail.backends.console.EmailBackend', ROOT_URLCONF=__name__)
65+
def test_register_account_with_email_verification_mandatory(self):
66+
"""
67+
Ensure we can register a user and it does not return auth token key when email verification is mandatory
68+
"""
69+
response = self._run_api_v1_user_register(self.user_data)
70+
self._check_response(response, {'first_name': 'test_first', 'last_name': 'test_last',
71+
'username': 'test_username', 'email': '[email protected]',
72+
'email_verification_required': True, 'key': None})

cvat/apps/iam/views.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ def post(self, request):
108108
class RegisterViewEx(RegisterView):
109109
def get_response_data(self, user):
110110
data = self.get_serializer(user).data
111-
data['email_verification_required'] = allauth_settings.EMAIL_VERIFICATION == \
112-
allauth_settings.EmailVerificationMethod.MANDATORY
113-
111+
data['email_verification_required'] = True
112+
data['key'] = None
113+
if allauth_settings.EMAIL_VERIFICATION != \
114+
allauth_settings.EmailVerificationMethod.MANDATORY:
115+
data['email_verification_required'] = False
116+
data['key'] = user.auth_token.key
114117
return data

0 commit comments

Comments
 (0)