Commit b19e534c by Waqas Khalid

Merge pull request #4461 from mlkwaqas/waqas/for108-discussion-blackout-period-inconsistent-ui

Fix inconsistent ui issues on discussion during blackout period
parents 74f5adae 3d5dde81
...@@ -52,6 +52,7 @@ class DiscussionModule(DiscussionFields, XModule): ...@@ -52,6 +52,7 @@ class DiscussionModule(DiscussionFields, XModule):
def get_html(self): def get_html(self):
context = { context = {
'discussion_id': self.discussion_id, 'discussion_id': self.discussion_id,
'course': self.get_course(),
} }
if getattr(self.system, 'is_author_mode', False): if getattr(self.system, 'is_author_mode', False):
template = 'discussion/_discussion_module_studio.html' template = 'discussion/_discussion_module_studio.html'
...@@ -59,6 +60,12 @@ class DiscussionModule(DiscussionFields, XModule): ...@@ -59,6 +60,12 @@ class DiscussionModule(DiscussionFields, XModule):
template = 'discussion/_discussion_module.html' template = 'discussion/_discussion_module.html'
return self.system.render_template(template, context) return self.system.render_template(template, context)
def get_course(self):
"""
Return course by course id.
"""
return self.descriptor.runtime.modulestore.get_course(self.course_id)
class DiscussionDescriptor(DiscussionFields, MetadataOnlyEditingDescriptor, RawDescriptor): class DiscussionDescriptor(DiscussionFields, MetadataOnlyEditingDescriptor, RawDescriptor):
......
...@@ -286,6 +286,10 @@ class XBlockWrapperTestMixin(object): ...@@ -286,6 +286,10 @@ class XBlockWrapperTestMixin(object):
descriptor_cls, fields = cls_and_fields descriptor_cls, fields = cls_and_fields
self.skip_if_invalid(descriptor_cls) self.skip_if_invalid(descriptor_cls)
descriptor = LeafModuleFactory(descriptor_cls=descriptor_cls, **fields) descriptor = LeafModuleFactory(descriptor_cls=descriptor_cls, **fields)
mocked_course = Mock()
modulestore = Mock()
modulestore.get_course.return_value = mocked_course
descriptor.runtime.modulestore = modulestore
self.check_property(descriptor) self.check_property(descriptor)
# Test that when an xmodule is generated from descriptor_cls # Test that when an xmodule is generated from descriptor_cls
......
...@@ -83,6 +83,10 @@ class DiscussionThreadPage(PageObject, DiscussionPageMixin): ...@@ -83,6 +83,10 @@ class DiscussionThreadPage(PageObject, DiscussionPageMixin):
"""Returns true if the response editor is present, false otherwise""" """Returns true if the response editor is present, false otherwise"""
return self._is_element_visible(".response_{} .edit-post-body".format(response_id)) return self._is_element_visible(".response_{} .edit-post-body".format(response_id))
def is_response_editable(self, response_id):
"""Returns true if the edit response button is present, false otherwise"""
return self._is_element_visible(".response_{} .discussion-response .action-edit".format(response_id))
def start_response_edit(self, response_id): def start_response_edit(self, response_id):
"""Click the edit button for the response, loading the editing view""" """Click the edit button for the response, loading the editing view"""
self._find_within(".response_{} .discussion-response .action-edit".format(response_id)).first.click() self._find_within(".response_{} .discussion-response .action-edit".format(response_id)).first.click()
...@@ -251,6 +255,8 @@ class InlineDiscussionPage(PageObject): ...@@ -251,6 +255,8 @@ class InlineDiscussionPage(PageObject):
def get_num_displayed_threads(self): def get_num_displayed_threads(self):
return len(self._find_within(".discussion-thread")) return len(self._find_within(".discussion-thread"))
def element_exists(self, selector):
return self.q(css=self._discussion_selector + " " + selector).present
class InlineDiscussionThreadPage(DiscussionThreadPage): class InlineDiscussionThreadPage(DiscussionThreadPage):
def __init__(self, browser, thread_id): def __init__(self, browser, thread_id):
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
Tests for discussion pages Tests for discussion pages
""" """
import datetime
from pytz import UTC
from uuid import uuid4 from uuid import uuid4
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
...@@ -286,7 +288,7 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix ...@@ -286,7 +288,7 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix
def setUp(self): def setUp(self):
super(InlineDiscussionTest, self).setUp() super(InlineDiscussionTest, self).setUp()
self.discussion_id = "test_discussion_{}".format(uuid4().hex) self.discussion_id = "test_discussion_{}".format(uuid4().hex)
CourseFixture(**self.course_info).add_children( self.course_fix = CourseFixture(**self.course_info).add_children(
XBlockFixtureDesc("chapter", "Test Section").add_children( XBlockFixtureDesc("chapter", "Test Section").add_children(
XBlockFixtureDesc("sequential", "Test Subsection").add_children( XBlockFixtureDesc("sequential", "Test Subsection").add_children(
XBlockFixtureDesc("vertical", "Test Unit").add_children( XBlockFixtureDesc("vertical", "Test Unit").add_children(
...@@ -300,7 +302,7 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix ...@@ -300,7 +302,7 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix
) )
).install() ).install()
AutoAuthPage(self.browser, course_id=self.course_id).visit() self.user_id = AutoAuthPage(self.browser, course_id=self.course_id).visit().get_user_id()
self.courseware_page = CoursewarePage(self.browser, self.course_id) self.courseware_page = CoursewarePage(self.browser, self.course_id)
self.courseware_page.visit() self.courseware_page.visit()
...@@ -334,6 +336,38 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix ...@@ -334,6 +336,38 @@ class InlineDiscussionTest(UniqueCourseTest, DiscussionResponsePaginationTestMix
def test_anonymous_to_peers_threads_as_peer(self): def test_anonymous_to_peers_threads_as_peer(self):
self.check_anonymous_to_peers(False) self.check_anonymous_to_peers(False)
def test_discussion_blackout_period(self):
now = datetime.datetime.now(UTC)
self.course_fix.add_advanced_settings(
{
u"discussion_blackouts": {
"value": [
[
(now - datetime.timedelta(days=14)).isoformat(),
(now + datetime.timedelta(days=2)).isoformat()
]
]
}
}
)
self.course_fix._add_advanced_settings()
self.browser.refresh()
thread = Thread(id=uuid4().hex, commentable_id=self.discussion_id)
thread_fixture = SingleThreadViewFixture(thread)
thread_fixture.addResponse(
Response(id="response1"),
[Comment(id="comment1", user_id="other"), Comment(id="comment2", user_id=self.user_id)])
thread_fixture.push()
self.setup_thread_page(thread.get("id"))
self.assertFalse(self.discussion_page.element_exists(".new-post-btn"))
self.assertFalse(self.thread_page.has_add_response_button())
self.assertFalse(self.thread_page.is_response_editable("response1"))
self.assertFalse(self.thread_page.is_add_comment_visible("response1"))
self.assertFalse(self.thread_page.is_comment_editable("comment1"))
self.assertFalse(self.thread_page.is_comment_editable("comment2"))
self.assertFalse(self.thread_page.is_comment_deletable("comment1"))
self.assertFalse(self.thread_page.is_comment_deletable("comment2"))
@attr('shard_1') @attr('shard_1')
class DiscussionUserProfileTest(UniqueCourseTest): class DiscussionUserProfileTest(UniqueCourseTest):
......
<%! from django.utils.translation import ugettext as _ %> <%! from django.utils.translation import ugettext as _ %>
<%! from django_comment_client.permissions import has_permission %>
<%include file="_underscore_templates.html" /> <%include file="_underscore_templates.html" />
<div class="discussion-module" data-discussion-id="${discussion_id | h}"> <div class="discussion-module" data-discussion-id="${discussion_id | h}">
<a class="discussion-show control-button" href="javascript:void(0)" data-discussion-id="${discussion_id | h}" role="button"><span class="show-hide-discussion-icon"></span><span class="button-text">${_("Show Discussion")}</span></a> <a class="discussion-show control-button" href="javascript:void(0)" data-discussion-id="${discussion_id | h}" role="button"><span class="show-hide-discussion-icon"></span><span class="button-text">${_("Show Discussion")}</span></a>
<a href="#" class="new-post-btn" role="button"><span class="icon icon-edit new-post-icon"></span>${_("New Post")}</a> % if has_permission(user, 'create_thread', course.id):
<a href="#" class="new-post-btn" role="button"><span class="icon icon-edit new-post-icon"></span>${_("New Post")}</a>
% endif
</div> </div>
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
</div> </div>
<ol class="responses"/> <ol class="responses"/>
<div class="response-pagination"/> <div class="response-pagination"/>
{{#ability.can_reply}}
<form class="local discussion-reply-new" data-id="{{id}}"> <form class="local discussion-reply-new" data-id="{{id}}">
<h4>${_("Post a response:")}</h4> <h4>${_("Post a response:")}</h4>
<ul class="discussion-errors"></ul> <ul class="discussion-errors"></ul>
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
<a class="discussion-submit-post control-button" href="#">${_("Submit")}</a> <a class="discussion-submit-post control-button" href="#">${_("Submit")}</a>
</div> </div>
</form> </form>
{{/ability.can_reply}}
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment