Skip to content
Snippets Groups Projects
Commit 50cdd2b0 authored by Chris Dodge's avatar Chris Dodge
Browse files

only redirect to dashboard if user has course enrollments, otherwise remain on...

only redirect to dashboard if user has course enrollments, otherwise remain on the course catalog page (aka homepage or root)

update lettuce test to match new expected behavior

add Jason's feedback

only apply new redirect logic for microsites

switch to use a feature flag to determine whether to support redirect behavior
parent 4c3b4a59
No related merge requests found
...@@ -3,9 +3,10 @@ from django.core.urlresolvers import reverse ...@@ -3,9 +3,10 @@ from django.core.urlresolvers import reverse
from django.http import Http404 from django.http import Http404
from django.shortcuts import redirect from django.shortcuts import redirect
from django_future.csrf import ensure_csrf_cookie from django_future.csrf import ensure_csrf_cookie
from edxmako.shortcuts import render_to_response
import student.views import student.views
from student.models import CourseEnrollment
import courseware.views import courseware.views
from microsite_configuration import microsite from microsite_configuration import microsite
...@@ -13,6 +14,24 @@ from edxmako.shortcuts import marketing_link ...@@ -13,6 +14,24 @@ from edxmako.shortcuts import marketing_link
from util.cache import cache_if_anonymous from util.cache import cache_if_anonymous
def get_course_enrollments(user):
"""
Returns the course enrollments for the passed in user within the context of a microsite, that
is filtered by course_org_filter
"""
enrollments = CourseEnrollment.enrollments_for_user(user)
microsite_org = microsite.get_value('course_org_filter')
if microsite_org:
site_enrollments = [
enrollment for enrollment in enrollments if enrollment.course_id.org == microsite_org
]
else:
site_enrollments = [
enrollment for enrollment in enrollments
]
return site_enrollments
@ensure_csrf_cookie @ensure_csrf_cookie
@cache_if_anonymous @cache_if_anonymous
def index(request): def index(request):
...@@ -21,7 +40,15 @@ def index(request): ...@@ -21,7 +40,15 @@ def index(request):
''' '''
if settings.COURSEWARE_ENABLED and request.user.is_authenticated(): if settings.COURSEWARE_ENABLED and request.user.is_authenticated():
return redirect(reverse('dashboard')) # For microsites, only redirect to dashboard if user has
# courses in his/her dashboard. Otherwise UX is a bit cryptic.
# In this case, we want to have the user stay on a course catalog
# page to make it easier to browse for courses (and register)
if microsite.get_value('ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER', \
settings.FEATURES.get('ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER', True)) or \
get_course_enrollments(request.user):
return redirect(reverse('dashboard'))
if settings.FEATURES.get('AUTH_USE_CERTIFICATES'): if settings.FEATURES.get('AUTH_USE_CERTIFICATES'):
from external_auth.views import ssl_login from external_auth.views import ssl_login
...@@ -53,7 +80,6 @@ def index(request): ...@@ -53,7 +80,6 @@ def index(request):
return student.views.index(request, user=request.user) return student.views.index(request, user=request.user)
@ensure_csrf_cookie @ensure_csrf_cookie
@cache_if_anonymous @cache_if_anonymous
def courses(request): def courses(request):
......
...@@ -5,7 +5,6 @@ from django.core.urlresolvers import reverse ...@@ -5,7 +5,6 @@ from django.core.urlresolvers import reverse
from django.test.utils import override_settings from django.test.utils import override_settings
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from helpers import LoginEnrollmentTestCase from helpers import LoginEnrollmentTestCase
...@@ -44,10 +43,7 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -44,10 +43,7 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.course_outside_microsite = CourseFactory.create(display_name='Robot_Course_Outside_Microsite', org='FooX') self.course_outside_microsite = CourseFactory.create(display_name='Robot_Course_Outside_Microsite', org='FooX')
def create_student_accounts(self): def setup_users(self):
"""
Build out the test accounts we'll use in these tests
"""
# Create student accounts and activate them. # Create student accounts and activate them.
for i in range(len(self.STUDENT_INFO)): for i in range(len(self.STUDENT_INFO)):
email, password = self.STUDENT_INFO[i] email, password = self.STUDENT_INFO[i]
...@@ -55,7 +51,6 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -55,7 +51,6 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.create_account(username, email, password) self.create_account(username, email, password)
self.activate_user(email) self.activate_user(email)
@override_settings(SITE_NAME=MICROSITE_TEST_HOSTNAME) @override_settings(SITE_NAME=MICROSITE_TEST_HOSTNAME)
def test_microsite_anonymous_homepage_content(self): def test_microsite_anonymous_homepage_content(self):
""" """
...@@ -89,7 +84,6 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -89,7 +84,6 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
# assert that the edX partners tag line is not in the HTML # assert that the edX partners tag line is not in the HTML
self.assertNotContains(resp, 'Explore free courses from') self.assertNotContains(resp, 'Explore free courses from')
def test_not_microsite_anonymous_homepage_content(self): def test_not_microsite_anonymous_homepage_content(self):
""" """
Make sure we see the right content on the homepage if we are not in a microsite Make sure we see the right content on the homepage if we are not in a microsite
...@@ -114,16 +108,39 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -114,16 +108,39 @@ class TestMicrosites(ModuleStoreTestCase, LoginEnrollmentTestCase):
# assert that footer template has been properly overriden on homepage # assert that footer template has been properly overriden on homepage
self.assertNotContains(resp, 'This is a Test Microsite footer') self.assertNotContains(resp, 'This is a Test Microsite footer')
def test_no_redirect_on_homepage_when_no_enrollments(self):
"""
Verify that a user going to homepage will not redirect if he/she has no course enrollments
"""
self.setup_users()
email, password = self.STUDENT_INFO[0]
self.login(email, password)
resp = self.client.get(reverse('root'), HTTP_HOST=MICROSITE_TEST_HOSTNAME)
self.assertEquals(resp.status_code, 200)
def test_redirect_on_homepage_when_has_enrollments(self):
"""
Verify that a user going to homepage will redirect to dashboard if he/she has
a course enrollment
"""
self.setup_users()
email, password = self.STUDENT_INFO[0]
self.login(email, password)
self.enroll(self.course, True)
resp = self.client.get(reverse('root'), HTTP_HOST=MICROSITE_TEST_HOSTNAME)
self.assertEquals(resp.status_code, 302)
def test_microsite_course_enrollment(self): def test_microsite_course_enrollment(self):
""" """
Enroll user in a course scoped in a Microsite and one course outside of a Microsite Enroll user in a course scoped in a Microsite and one course outside of a Microsite
and make sure that they are only visible in the right Dashboards and make sure that they are only visible in the right Dashboards
""" """
self.setup_users()
self.create_student_accounts() email, password = self.STUDENT_INFO[1]
email, password = self.STUDENT_INFO[0]
self.login(email, password) self.login(email, password)
self.enroll(self.course, True) self.enroll(self.course, True)
self.enroll(self.course_outside_microsite, True) self.enroll(self.course_outside_microsite, True)
......
...@@ -59,7 +59,6 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -59,7 +59,6 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
display_name='progress_tab', display_name='progress_tab',
default_tab = 'progress') default_tab = 'progress')
# Create student accounts and activate them. # Create student accounts and activate them.
for i in range(len(self.STUDENT_INFO)): for i in range(len(self.STUDENT_INFO)):
email, password = self.STUDENT_INFO[i] email, password = self.STUDENT_INFO[i]
......
...@@ -279,6 +279,11 @@ FEATURES = { ...@@ -279,6 +279,11 @@ FEATURES = {
# when the styles appropriately match the edX.org website. # when the styles appropriately match the edX.org website.
'ENABLE_NEW_EDX_HEADER': False, 'ENABLE_NEW_EDX_HEADER': False,
# When a logged in user goes to the homepage ('/') should the user be
# redirected to the dashboard - this is default Open edX behavior. Set to
# False to not redirect the user
'ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER': True,
} }
# Ignore static asset files on import which match this pattern # Ignore static asset files on import which match this pattern
......
...@@ -330,7 +330,8 @@ MICROSITE_CONFIGURATION = { ...@@ -330,7 +330,8 @@ MICROSITE_CONFIGURATION = {
"show_homepage_promo_video": False, "show_homepage_promo_video": False,
"course_index_overlay_text": "This is a Test Microsite Overlay Text.", "course_index_overlay_text": "This is a Test Microsite Overlay Text.",
"course_index_overlay_logo_file": "test_microsite/images/header-logo.png", "course_index_overlay_logo_file": "test_microsite/images/header-logo.png",
"homepage_overlay_html": "<h1>This is a Test Microsite Overlay HTML</h1>" "homepage_overlay_html": "<h1>This is a Test Microsite Overlay HTML</h1>",
"ALWAYS_REDIRECT_HOMEPAGE_TO_DASHBOARD_FOR_AUTHENTICATED_USER": False,
}, },
"default": { "default": {
"university": "default_university", "university": "default_university",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment