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
c905cc74
Commit
c905cc74
authored
Apr 02, 2013
by
ichuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add masquerade.py
parent
260dc84f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
0 deletions
+103
-0
lms/djangoapps/courseware/masquerade.py
+103
-0
No files found.
lms/djangoapps/courseware/masquerade.py
0 → 100644
View file @
c905cc74
#---------------------------------------- Masequerade ----------------------------------------
#
# Allow course staff to see a student or staff view of courseware.
# Which kind of view has been selected is stored in the session state.
import
json
import
logging
import
urllib
from
functools
import
partial
from
django.conf
import
settings
from
django.core.context_processors
import
csrf
from
django.core.urlresolvers
import
reverse
from
django.contrib.auth.models
import
User
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
Http404
from
django.shortcuts
import
redirect
from
mitxmako.shortcuts
import
render_to_response
,
render_to_string
#from django.views.decorators.csrf import ensure_csrf_cookie
from
django_future.csrf
import
ensure_csrf_cookie
from
django.views.decorators.cache
import
cache_control
from
django.http
import
HttpResponse
from
courseware
import
grades
from
courseware.access
import
has_access
from
courseware.courses
import
(
get_courses
,
get_course_with_access
,
get_courses_by_university
,
sort_by_announcement
)
import
courseware.tabs
as
tabs
from
courseware.models
import
StudentModuleCache
from
module_render
import
toc_for_course
,
get_module
,
get_instance_module
,
get_module_for_descriptor
from
django_comment_client.utils
import
get_discussion_title
from
student.models
import
UserTestGroup
,
CourseEnrollment
from
util.cache
import
cache
,
cache_if_anonymous
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.exceptions
import
InvalidLocationError
,
ItemNotFoundError
,
NoPathToItem
from
xmodule.modulestore.search
import
path_to_location
log
=
logging
.
getLogger
(
__name__
)
def
handle_ajax
(
request
,
marg
):
log
.
debug
(
'masquerade handle_ajax marg=
%
s'
%
marg
)
return
HttpResponse
(
json
.
dumps
({}))
MASQ_VAR
=
'masquerade_identity'
class
Masquerade
(
object
):
'''
Manage masquerade identity (allows staff to view courseware as either staff or student)
State variables:
actual_user = User instance of the real, un-masqueraded user
user = User instance (what actual user is masquerading as)
usertype = "staff" or "student" or "nonstaff"
'''
def
__init__
(
self
,
request
,
staff_access
=
False
):
'''
request = Django http request object
'''
self
.
request
=
request
self
.
actual_user
=
request
.
user
self
.
user
=
request
.
user
self
.
usertype
=
"nonstaff"
if
request
.
user
is
not
None
and
staff_access
:
self
.
usertype
=
request
.
session
.
get
(
MASQ_VAR
,
'staff'
)
if
self
.
usertype
==
'student'
:
self
.
user
=
self
.
get_student_user
()
def
get_student_user
(
self
):
'''
Each staff user can have a corresponding student identity, with
the same username + "__student". Return that User.
Create the student user if doesn't already exist.
'''
suffix
=
'__student'
if
self
.
user
.
username
.
endswith
(
suffix
):
return
self
.
user
user
=
User
.
get_or_create
(
username
=
self
.
user
+
suffix
,
email
=
self
.
user
.
email
)
profile
=
UserProfile
.
get_or_create
(
user
=
user
,
name
=
self
.
user
.
profile
.
name
+
suffix
)
return
user
def
toggle_status
(
self
):
"""
Toggle status from staff from student
"""
if
self
.
usertype
==
'student'
:
self
.
user
=
self
.
actual_user
elif
self
.
usertype
==
'staff'
:
self
.
user
=
self
.
get_student_user
()
def
view_status
(
self
):
'''
Return string version of status of view
'''
STAT
=
{
'staff'
:
'<font color="red">Staff view</font>'
,
'student'
:
'<font color="orange">Student view</font>'
}
return
STAT
.
get
(
self
.
usertype
,
''
)
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