Skip to content

Commit

Permalink
Merge pull request #22 from lumsx/develop
Browse files Browse the repository at this point in the history
release-2021-01-07
  • Loading branch information
mumerfarooq000 authored Jan 7, 2021
2 parents 50ff95a + ed96117 commit f457e6f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lms/djangoapps/branding/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# encoding: utf-8
"""Tests of Branding API views. """
import copy
import json
import urllib

Expand Down Expand Up @@ -315,3 +316,26 @@ def test_header_logo_links_to_marketing_site_with_site_override(self):
self.client.login(username=self.user.username, password="password")
response = self.client.get(reverse("dashboard"))
self.assertIn(self.site_configuration_other.values["MKTG_URLS"]["ROOT"], response.content)

def test_index_redirects_to_signin_with_site_override(self):
""" Test index view redirects if ALWAYS_REDIRECT_HOMEPAGE_TO_SIGNIN_FOR_ANONYMOUS_USER is set in SiteConfiguration """
self.use_site(self.site_for_signin_redirection)
response = self.client.get(reverse("root"))
self.assertRedirects(
response,
reverse('signin_user'),
fetch_redirect_response=False
)

def test_index_redirects_to_signin_with_feature_flag(self):
""" Test index view redirects if ALWAYS_REDIRECT_HOMEPAGE_TO_SIGNIN_FOR_ANONYMOUS_USER feature flag is set """
self.use_site(self.site_for_signin_redirection)
feature_flags = copy.deepcopy(settings.FEATURES)
feature_flags['ALWAYS_REDIRECT_HOMEPAGE_TO_SIGNIN_FOR_ANONYMOUS_USER'] = True
with self.settings(FEATURES=feature_flags):
response = self.client.get(reverse("root"))
self.assertRedirects(
response,
reverse('signin_user'),
fetch_redirect_response=False
)
6 changes: 6 additions & 0 deletions lms/djangoapps/branding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def index(request):
req_new['next'] = reverse('dashboard')
request.GET = req_new
return ssl_login(request)

if request.user.is_anonymous:
if configuration_helpers.get_value(
'ALWAYS_REDIRECT_HOMEPAGE_TO_SIGNIN_FOR_ANONYMOUS_USER',
settings.FEATURES.get('ALWAYS_REDIRECT_HOMEPAGE_TO_SIGNIN_FOR_ANONYMOUS_USER', False)):
return redirect(reverse('signin_user'))

enable_mktg_site = configuration_helpers.get_value(
'ENABLE_MKTG_SITE',
Expand Down
12 changes: 12 additions & 0 deletions openedx/core/djangoapps/site_configuration/tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def setUp(self):
}
)

self.site_for_signin_redirection = SiteFactory.create(
domain='fake.site.domain',
name='fake.site.name'
)
self.site_configuration_for_signin_redirection = SiteConfigurationFactory.create(
site=self.site_for_signin_redirection,
values={
"SITE_NAME": self.site_for_signin_redirection.domain,
"ALWAYS_REDIRECT_HOMEPAGE_TO_SIGNIN_FOR_ANONYMOUS_USER": True,
}
)

# Initialize client with default site domain
self.use_site(self.site)

Expand Down

0 comments on commit f457e6f

Please sign in to comment.