Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
2e34a5cc
Commit
2e34a5cc
authored
Apr 11, 2014
by
Jason Bau
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3193 from edx/jbau/edx-west/sneakpeek-deeplink-middleware
middleware to allow sneakpeek courses to deeplink
parents
b343335f
232b7304
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
0 deletions
+55
-0
lms/djangoapps/sneakpeek_deeplink/__init__.py
+0
-0
lms/djangoapps/sneakpeek_deeplink/middleware.py
+49
-0
lms/envs/common.py
+6
-0
No files found.
lms/djangoapps/sneakpeek_deeplink/__init__.py
0 → 100644
View file @
2e34a5cc
lms/djangoapps/sneakpeek_deeplink/middleware.py
0 → 100644
View file @
2e34a5cc
"""
Middleware class that supports deep-links for allows courses that allow sneakpeek.
The user will be registered anonymously, logged in, and enrolled in the course
"""
from
student.models
import
CourseEnrollment
from
util.request
import
course_id_from_url
from
courseware.models
import
CoursePreference
from
student.views
import
_create_and_login_nonregistered_user
,
_check_can_enroll_in_course
class
SneakPeekDeepLinkMiddleware
(
object
):
"""
Sneak Peak Deep Link Middlware
"""
def
process_request
(
self
,
request
):
"""
Only if the following are all true:
1. request.user is AnonymousUser (This middleware must be added after the AuthenticationMiddleware)
2. request has a course context
3. request's course allows sneakpeek
4. request's course's enrollment period is open
Does the following:
1. Registers an anonymous user
2. Login this user in
3. Enrolls this user in the course
"""
### Start by testing the conditions, each of which can fail fast and return,
### causing the middleware to do nothing
if
request
.
user
.
is_authenticated
():
return
None
course_id
=
course_id_from_url
(
request
.
path
)
if
not
course_id
:
return
None
if
not
CoursePreference
.
course_allows_nonregistered_access
(
course_id
):
return
None
can_enroll
,
_
=
_check_can_enroll_in_course
(
request
.
user
,
course_id
,
access_type
=
'within_enrollment_period'
)
if
not
can_enroll
:
return
None
### OK. We should now do the 3 steps to get the users access to follow the deeplink
_create_and_login_nonregistered_user
(
request
)
CourseEnrollment
.
enroll
(
request
.
user
,
course_id
)
return
None
lms/envs/common.py
View file @
2e34a5cc
...
@@ -735,6 +735,9 @@ MIDDLEWARE_CLASSES = (
...
@@ -735,6 +735,9 @@ MIDDLEWARE_CLASSES = (
#'django.contrib.auth.middleware.AuthenticationMiddleware',
#'django.contrib.auth.middleware.AuthenticationMiddleware',
'cache_toolbox.middleware.CacheBackedAuthenticationMiddleware'
,
'cache_toolbox.middleware.CacheBackedAuthenticationMiddleware'
,
'student.middleware.UserStandingMiddleware'
,
'student.middleware.UserStandingMiddleware'
,
# sneakpeek deeplinks
'sneakpeek_deeplink.middleware.SneakPeekDeepLinkMiddleware'
,
'contentserver.middleware.StaticContentServer'
,
'contentserver.middleware.StaticContentServer'
,
'crum.CurrentRequestUserMiddleware'
,
'crum.CurrentRequestUserMiddleware'
,
...
@@ -779,6 +782,7 @@ MIDDLEWARE_CLASSES = (
...
@@ -779,6 +782,7 @@ MIDDLEWARE_CLASSES = (
# use Django built in clickjacking protection
# use Django built in clickjacking protection
'django.middleware.clickjacking.XFrameOptionsMiddleware'
,
'django.middleware.clickjacking.XFrameOptionsMiddleware'
,
)
)
# Clickjacking protection can be enabled by setting this to 'DENY'
# Clickjacking protection can be enabled by setting this to 'DENY'
...
@@ -1215,6 +1219,8 @@ INSTALLED_APPS = (
...
@@ -1215,6 +1219,8 @@ INSTALLED_APPS = (
'reverification'
,
'reverification'
,
'embargo'
,
'embargo'
,
'sneakpeek_deeplink'
,
)
)
######################### MARKETING SITE ###############################
######################### MARKETING SITE ###############################
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment