Skip to content

Commit 285ae5e

Browse files
authored
Merge pull request #6901 from readthedocs/allow-override-views
Allow to override sign in and sign out views
2 parents 1a02937 + 83b2442 commit 285ae5e

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

readthedocs/profiles/urls/private.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
urlpatterns = []
1212

1313
account_urls = [
14+
url(
15+
r'^login',
16+
views.LoginView.as_view(),
17+
name='account_login',
18+
),
19+
url(
20+
r'^logout/',
21+
views.LogoutView.as_view(),
22+
name='account_logout',
23+
),
1424
url(
1525
r'^edit/',
1626
views.ProfileEdit.as_view(),

readthedocs/profiles/views.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Views for creating, editing and viewing site-specific user profiles."""
22

3+
from allauth.account.views import LoginView as AllAuthLoginView
4+
from allauth.account.views import LogoutView as AllAuthLogoutView
35
from django.contrib import messages
46
from django.contrib.auth import logout
57
from django.contrib.auth.models import User
@@ -27,6 +29,26 @@
2729
from readthedocs.core.utils.extend import SettingsOverrideObject
2830

2931

32+
class LoginViewBase(AllAuthLoginView):
33+
34+
pass
35+
36+
37+
class LoginView(SettingsOverrideObject):
38+
39+
_default_class = LoginViewBase
40+
41+
42+
class LogoutViewBase(AllAuthLogoutView):
43+
44+
pass
45+
46+
47+
class LogoutView(SettingsOverrideObject):
48+
49+
_default_class = LogoutViewBase
50+
51+
3052
class ProfileEdit(PrivateViewMixin, UpdateView):
3153

3254
"""Edit the current user's profile."""

readthedocs/rtd_tests/tests/test_privacy_urls.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
2-
32
from unittest import mock
3+
44
from allauth.socialaccount.models import SocialAccount
55
from django.contrib.admindocs.views import extract_views_from_urlpatterns
66
from django.test import TestCase
@@ -9,13 +9,17 @@
99
from taggit.models import Tag
1010

1111
from readthedocs.builds.constants import BRANCH
12-
from readthedocs.builds.models import Build, BuildCommandResult
12+
from readthedocs.builds.models import (
13+
Build,
14+
BuildCommandResult,
15+
RegexAutomationRule,
16+
VersionAutomationRule,
17+
)
1318
from readthedocs.core.utils.tasks import TaskNoPermission
1419
from readthedocs.integrations.models import HttpExchange, Integration
1520
from readthedocs.oauth.models import RemoteOrganization, RemoteRepository
1621
from readthedocs.projects.models import Domain, EnvironmentVariable, Project
1722
from readthedocs.rtd_tests.utils import create_user
18-
from readthedocs.builds.models import RegexAutomationRule, VersionAutomationRule
1923

2024

2125
class URLAccessMixin:
@@ -479,6 +483,12 @@ def test_private_urls(self):
479483

480484
class PrivateUserProfileAdminAccessTest(PrivateUserProfileMixin, TestCase):
481485

486+
def setUp(self):
487+
super().setUp()
488+
self.response_data.update({
489+
'/accounts/login/': {'status_code': 302},
490+
})
491+
482492
def login(self):
483493
return self.client.login(username='owner', password='test')
484494

@@ -488,6 +498,12 @@ def is_admin(self):
488498

489499
class PrivateUserProfileUserAccessTest(PrivateUserProfileMixin, TestCase):
490500

501+
def setUp(self):
502+
super().setUp()
503+
self.response_data.update({
504+
'/accounts/login/': {'status_code': 302},
505+
})
506+
491507
def login(self):
492508
return self.client.login(username='tester', password='test')
493509

@@ -506,6 +522,7 @@ def setUp(self):
506522
self.response_data.update({
507523
'/accounts/tokens/create/': {'status_code': 302},
508524
'/accounts/tokens/delete/': {'status_code': 302},
525+
'/accounts/login/': {'status_code': 200},
509526
})
510527

511528
def login(self):

0 commit comments

Comments
 (0)