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
81dfcb04
Commit
81dfcb04
authored
Jul 03, 2014
by
Waqas Khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show thread user to staff when only anonymous_to_peers is true
FOR-122
parent
d94b9202
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
10 deletions
+35
-10
common/test/acceptance/fixtures/discussion.py
+2
-0
common/test/acceptance/pages/lms/discussion.py
+3
-0
common/test/acceptance/tests/test_discussion.py
+17
-1
lms/djangoapps/django_comment_client/forum/views.py
+11
-7
lms/djangoapps/django_comment_client/utils.py
+2
-2
No files found.
common/test/acceptance/fixtures/discussion.py
View file @
81dfcb04
...
@@ -30,6 +30,8 @@ class ContentFactory(factory.Factory):
...
@@ -30,6 +30,8 @@ class ContentFactory(factory.Factory):
class
Thread
(
ContentFactory
):
class
Thread
(
ContentFactory
):
anonymous
=
False
anonymous_to_peers
=
False
comments_count
=
0
comments_count
=
0
unread_comments_count
=
0
unread_comments_count
=
0
title
=
"dummy thread title"
title
=
"dummy thread title"
...
...
common/test/acceptance/pages/lms/discussion.py
View file @
81dfcb04
...
@@ -267,6 +267,9 @@ class InlineDiscussionThreadPage(DiscussionThreadPage):
...
@@ -267,6 +267,9 @@ class InlineDiscussionThreadPage(DiscussionThreadPage):
"Thread expanded"
"Thread expanded"
)
.
fulfill
()
)
.
fulfill
()
def
is_thread_anonymous
(
self
):
return
not
self
.
q
(
css
=
".posted-details > .username"
)
.
present
class
DiscussionUserProfilePage
(
CoursePage
):
class
DiscussionUserProfilePage
(
CoursePage
):
...
...
common/test/acceptance/tests/test_discussion.py
View file @
81dfcb04
...
@@ -297,7 +297,8 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix
...
@@ -297,7 +297,8 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix
AutoAuthPage
(
self
.
browser
,
course_id
=
self
.
course_id
)
.
visit
()
AutoAuthPage
(
self
.
browser
,
course_id
=
self
.
course_id
)
.
visit
()
CoursewarePage
(
self
.
browser
,
self
.
course_id
)
.
visit
()
self
.
courseware_page
=
CoursewarePage
(
self
.
browser
,
self
.
course_id
)
self
.
courseware_page
.
visit
()
self
.
discussion_page
=
InlineDiscussionPage
(
self
.
browser
,
self
.
discussion_id
)
self
.
discussion_page
=
InlineDiscussionPage
(
self
.
browser
,
self
.
discussion_id
)
def
setup_thread_page
(
self
,
thread_id
):
def
setup_thread_page
(
self
,
thread_id
):
...
@@ -313,6 +314,21 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix
...
@@ -313,6 +314,21 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix
self
.
discussion_page
.
expand_discussion
()
self
.
discussion_page
.
expand_discussion
()
self
.
assertEqual
(
self
.
discussion_page
.
get_num_displayed_threads
(),
0
)
self
.
assertEqual
(
self
.
discussion_page
.
get_num_displayed_threads
(),
0
)
def
check_anonymous_to_peers
(
self
,
is_staff
):
thread
=
Thread
(
id
=
uuid4
()
.
hex
,
anonymous_to_peers
=
True
,
commentable_id
=
self
.
discussion_id
)
thread_fixture
=
SingleThreadViewFixture
(
thread
)
thread_fixture
.
push
()
self
.
setup_thread_page
(
thread
.
get
(
"id"
))
self
.
assertEqual
(
self
.
thread_page
.
is_thread_anonymous
(),
not
is_staff
)
def
test_anonymous_to_peers_threads_as_staff
(
self
):
AutoAuthPage
(
self
.
browser
,
course_id
=
self
.
course_id
,
roles
=
"Administrator"
)
.
visit
()
self
.
courseware_page
.
visit
()
self
.
check_anonymous_to_peers
(
True
)
def
test_anonymous_to_peers_threads_as_peer
(
self
):
self
.
check_anonymous_to_peers
(
False
)
class
DiscussionUserProfileTest
(
UniqueCourseTest
):
class
DiscussionUserProfileTest
(
UniqueCourseTest
):
"""
"""
...
...
lms/djangoapps/django_comment_client/forum/views.py
View file @
81dfcb04
...
@@ -148,9 +148,9 @@ def inline_discussion(request, course_id, discussion_id):
...
@@ -148,9 +148,9 @@ def inline_discussion(request, course_id, discussion_id):
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"get_metadata_for_threads"
):
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"get_metadata_for_threads"
):
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
is_staff
=
cached_has_permission
(
request
.
user
,
'openclose_thread'
,
course
.
id
)
return
utils
.
JsonResponse
({
return
utils
.
JsonResponse
({
'discussion_data'
:
map
(
utils
.
safe_content
,
threads
)
,
'discussion_data'
:
[
utils
.
safe_content
(
thread
,
is_staff
)
for
thread
in
threads
]
,
'user_info'
:
user_info
,
'user_info'
:
user_info
,
'annotated_content_info'
:
annotated_content_info
,
'annotated_content_info'
:
annotated_content_info
,
'page'
:
query_params
[
'page'
],
'page'
:
query_params
[
'page'
],
...
@@ -172,7 +172,8 @@ def forum_form_discussion(request, course_id):
...
@@ -172,7 +172,8 @@ def forum_form_discussion(request, course_id):
try
:
try
:
unsafethreads
,
query_params
=
get_threads
(
request
,
course_id
)
# This might process a search query
unsafethreads
,
query_params
=
get_threads
(
request
,
course_id
)
# This might process a search query
threads
=
[
utils
.
safe_content
(
thread
)
for
thread
in
unsafethreads
]
is_staff
=
cached_has_permission
(
request
.
user
,
'openclose_thread'
,
course
.
id
)
threads
=
[
utils
.
safe_content
(
thread
,
is_staff
)
for
thread
in
unsafethreads
]
except
cc
.
utils
.
CommentClientMaintenanceError
:
except
cc
.
utils
.
CommentClientMaintenanceError
:
log
.
warning
(
"Forum is in maintenance mode"
)
log
.
warning
(
"Forum is in maintenance mode"
)
return
render_to_response
(
'discussion/maintenance.html'
,
{})
return
render_to_response
(
'discussion/maintenance.html'
,
{})
...
@@ -248,10 +249,11 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -248,10 +249,11 @@ def single_thread(request, course_id, discussion_id, thread_id):
raise
Http404
raise
Http404
raise
raise
is_staff
=
cached_has_permission
(
request
.
user
,
'openclose_thread'
,
course
.
id
)
if
request
.
is_ajax
():
if
request
.
is_ajax
():
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"get_annotated_content_infos"
):
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"get_annotated_content_infos"
):
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
=
user_info
)
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
=
user_info
)
content
=
utils
.
safe_content
(
thread
.
to_dict
())
content
=
utils
.
safe_content
(
thread
.
to_dict
()
,
is_staff
)
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"add_courseware_context"
):
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"add_courseware_context"
):
add_courseware_context
([
content
],
course
)
add_courseware_context
([
content
],
course
)
return
utils
.
JsonResponse
({
return
utils
.
JsonResponse
({
...
@@ -274,7 +276,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -274,7 +276,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
if
not
"pinned"
in
thread
:
if
not
"pinned"
in
thread
:
thread
[
"pinned"
]
=
False
thread
[
"pinned"
]
=
False
threads
=
[
utils
.
safe_content
(
thread
)
for
thread
in
threads
]
threads
=
[
utils
.
safe_content
(
thread
,
is_staff
)
for
thread
in
threads
]
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"get_metadata_for_threads"
):
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"get_metadata_for_threads"
):
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
...
@@ -331,8 +333,9 @@ def user_profile(request, course_id, user_id):
...
@@ -331,8 +333,9 @@ def user_profile(request, course_id, user_id):
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
if
request
.
is_ajax
():
if
request
.
is_ajax
():
is_staff
=
cached_has_permission
(
request
.
user
,
'openclose_thread'
,
course
.
id
)
return
utils
.
JsonResponse
({
return
utils
.
JsonResponse
({
'discussion_data'
:
map
(
utils
.
safe_content
,
threads
)
,
'discussion_data'
:
[
utils
.
safe_content
(
thread
,
is_staff
)
for
thread
in
threads
]
,
'page'
:
query_params
[
'page'
],
'page'
:
query_params
[
'page'
],
'num_pages'
:
query_params
[
'num_pages'
],
'num_pages'
:
query_params
[
'num_pages'
],
'annotated_content_info'
:
_attr_safe_json
(
annotated_content_info
),
'annotated_content_info'
:
_attr_safe_json
(
annotated_content_info
),
...
@@ -380,9 +383,10 @@ def followed_threads(request, course_id, user_id):
...
@@ -380,9 +383,10 @@ def followed_threads(request, course_id, user_id):
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"get_metadata_for_threads"
):
with
newrelic
.
agent
.
FunctionTrace
(
nr_transaction
,
"get_metadata_for_threads"
):
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
annotated_content_info
=
utils
.
get_metadata_for_threads
(
course_id
,
threads
,
request
.
user
,
user_info
)
if
request
.
is_ajax
():
if
request
.
is_ajax
():
is_staff
=
cached_has_permission
(
request
.
user
,
'openclose_thread'
,
course
.
id
)
return
utils
.
JsonResponse
({
return
utils
.
JsonResponse
({
'annotated_content_info'
:
annotated_content_info
,
'annotated_content_info'
:
annotated_content_info
,
'discussion_data'
:
map
(
utils
.
safe_content
,
threads
)
,
'discussion_data'
:
[
utils
.
safe_content
(
thread
,
is_staff
)
for
thread
in
threads
]
,
'page'
:
query_params
[
'page'
],
'page'
:
query_params
[
'page'
],
'num_pages'
:
query_params
[
'num_pages'
],
'num_pages'
:
query_params
[
'num_pages'
],
})
})
...
...
lms/djangoapps/django_comment_client/utils.py
View file @
81dfcb04
...
@@ -360,7 +360,7 @@ def add_courseware_context(content_list, course):
...
@@ -360,7 +360,7 @@ def add_courseware_context(content_list, course):
content
.
update
({
"courseware_url"
:
url
,
"courseware_title"
:
title
})
content
.
update
({
"courseware_url"
:
url
,
"courseware_title"
:
title
})
def
safe_content
(
content
):
def
safe_content
(
content
,
is_staff
=
False
):
fields
=
[
fields
=
[
'id'
,
'title'
,
'body'
,
'course_id'
,
'anonymous'
,
'anonymous_to_peers'
,
'id'
,
'title'
,
'body'
,
'course_id'
,
'anonymous'
,
'anonymous_to_peers'
,
'endorsed'
,
'parent_id'
,
'thread_id'
,
'votes'
,
'closed'
,
'created_at'
,
'endorsed'
,
'parent_id'
,
'thread_id'
,
'votes'
,
'closed'
,
'created_at'
,
...
@@ -372,7 +372,7 @@ def safe_content(content):
...
@@ -372,7 +372,7 @@ def safe_content(content):
]
]
if
(
content
.
get
(
'anonymous'
)
is
False
)
and
(
content
.
get
(
'anonymous_to_peers'
)
is
False
):
if
(
content
.
get
(
'anonymous'
)
is
False
)
and
(
(
content
.
get
(
'anonymous_to_peers'
)
is
False
)
or
is_staff
):
fields
+=
[
'username'
,
'user_id'
]
fields
+=
[
'username'
,
'user_id'
]
if
'children'
in
content
:
if
'children'
in
content
:
...
...
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