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
f1f5a7dd
Commit
f1f5a7dd
authored
Nov 07, 2017
by
Clinton Blackburn
Committed by
Clinton Blackburn
Nov 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disabled edx-notes for anonymous users
parent
7c94131e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
14 deletions
+26
-14
lms/djangoapps/courseware/tests/test_tabs.py
+1
-3
lms/djangoapps/edxnotes/decorators.py
+9
-6
lms/djangoapps/edxnotes/plugins.py
+3
-0
lms/djangoapps/edxnotes/tests.py
+13
-5
No files found.
lms/djangoapps/courseware/tests/test_tabs.py
View file @
f1f5a7dd
...
...
@@ -61,9 +61,7 @@ class TabTestCase(SharedModuleStoreTestCase):
"""
Creates a mock user with the specified properties.
"""
user
=
UserFactory
()
user
.
name
=
'mock_user'
user
.
is_staff
=
is_staff
user
=
UserFactory
(
is_staff
=
is_staff
)
user
.
is_enrolled
=
is_enrolled
user
.
is_authenticated
=
lambda
:
is_authenticated
return
user
...
...
lms/djangoapps/edxnotes/decorators.py
View file @
f1f5a7dd
...
...
@@ -24,13 +24,16 @@ def edxnotes(cls):
is_studio
=
getattr
(
self
.
system
,
"is_author_mode"
,
False
)
course
=
self
.
descriptor
.
runtime
.
modulestore
.
get_course
(
self
.
runtime
.
course_id
)
# Must be disabled:
# - in Studio;
# - when Harvard Annotation Tool is enabled for the course;
# - when the feature flag or `edxnotes` setting of the course is set to False.
if
is_studio
or
not
is_feature_enabled
(
course
):
# Must be disabled when:
# - in Studio
# - Harvard Annotation Tool is enabled for the course
# - the feature flag or `edxnotes` setting of the course is set to False
# - the user is not authenticated
user
=
self
.
runtime
.
get_real_user
(
self
.
runtime
.
anonymous_student_id
)
if
is_studio
or
not
is_feature_enabled
(
course
)
or
not
user
.
is_authenticated
():
return
original_get_html
(
self
,
*
args
,
**
kwargs
)
else
:
return
render_to_string
(
"edxnotes_wrapper.html"
,
{
"content"
:
original_get_html
(
self
,
*
args
,
**
kwargs
),
"uid"
:
generate_uid
(),
...
...
@@ -41,7 +44,7 @@ def edxnotes(cls):
# Use camelCase to name keys.
"usageId"
:
unicode
(
self
.
scope_ids
.
usage_id
)
.
encode
(
"utf-8"
),
"courseId"
:
unicode
(
self
.
runtime
.
course_id
)
.
encode
(
"utf-8"
),
"token"
:
get_edxnotes_id_token
(
self
.
runtime
.
get_real_user
(
self
.
runtime
.
anonymous_student_id
)
),
"token"
:
get_edxnotes_id_token
(
user
),
"tokenUrl"
:
get_token_url
(
self
.
runtime
.
course_id
),
"endpoint"
:
get_public_endpoint
(),
"debug"
:
settings
.
DEBUG
,
...
...
lms/djangoapps/edxnotes/plugins.py
View file @
f1f5a7dd
...
...
@@ -31,6 +31,9 @@ class EdxNotesTab(EnrolledTab):
if
not
settings
.
FEATURES
.
get
(
"ENABLE_EDXNOTES"
)
or
is_harvard_notes_enabled
(
course
):
return
False
if
user
and
not
user
.
is_authenticated
():
return
False
return
course
.
edxnotes
...
...
lms/djangoapps/edxnotes/tests.py
View file @
f1f5a7dd
...
...
@@ -10,6 +10,7 @@ from unittest import skipUnless
import
ddt
import
jwt
from
django.conf
import
settings
from
django.contrib.auth.models
import
AnonymousUser
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.urlresolvers
import
reverse
from
django.test.client
import
RequestFactory
...
...
@@ -72,10 +73,10 @@ class TestProblem(object):
The purpose of this class is to imitate any problem.
"""
def
__init__
(
self
,
course
):
def
__init__
(
self
,
course
,
user
=
None
):
self
.
system
=
MagicMock
(
is_author_mode
=
False
)
self
.
scope_ids
=
MagicMock
(
usage_id
=
"test_usage_id"
)
self
.
user
=
UserFactory
.
create
(
username
=
"Joe"
,
email
=
"joe@example.com"
,
password
=
"edx"
)
self
.
user
=
user
or
UserFactory
(
)
self
.
runtime
=
MagicMock
(
course_id
=
course
.
id
,
get_real_user
=
lambda
anon_id
:
self
.
user
)
self
.
descriptor
=
MagicMock
()
self
.
descriptor
.
runtime
.
modulestore
.
get_course
.
return_value
=
course
...
...
@@ -100,9 +101,9 @@ class EdxNotesDecoratorTest(ModuleStoreTestCase):
ClientFactory
(
name
=
"edx-notes"
)
# Using old mongo because of locator comparison issues (see longer
# note below in EdxNotesHelpersTest setUp.
self
.
course
=
CourseFactory
.
create
(
edxnotes
=
True
,
default_store
=
ModuleStoreEnum
.
Type
.
mongo
)
self
.
user
=
UserFactory
.
create
(
username
=
"Bob"
,
email
=
"bob@example.com"
,
password
=
"edx"
)
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
"edx"
)
self
.
course
=
CourseFactory
(
edxnotes
=
True
,
default_store
=
ModuleStoreEnum
.
Type
.
mongo
)
self
.
user
=
UserFactory
(
)
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
UserFactory
.
_DEFAULT_PASSWORD
)
self
.
problem
=
TestProblem
(
self
.
course
)
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
'ENABLE_EDXNOTES'
:
True
})
...
...
@@ -170,6 +171,13 @@ class EdxNotesDecoratorTest(ModuleStoreTestCase):
enable_edxnotes_for_the_course
(
self
.
course
,
self
.
user
.
id
)
self
.
assertEqual
(
"original_get_html"
,
self
.
problem
.
get_html
())
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
"ENABLE_EDXNOTES"
:
True
})
def
test_anonymous_user
(
self
):
user
=
AnonymousUser
()
problem
=
TestProblem
(
self
.
course
,
user
)
enable_edxnotes_for_the_course
(
self
.
course
,
None
)
assert
problem
.
get_html
()
==
"original_get_html"
@attr
(
shard
=
3
)
@skipUnless
(
settings
.
FEATURES
[
"ENABLE_EDXNOTES"
],
"EdxNotes feature needs to be enabled."
)
...
...
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