Commit 308fd664 by rabia23

TNL-6740 Fix previously cohorted discussion posts still show cohorting visibility message.

parent 53bf4ef3
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
this.pages = options.pages || 1; this.pages = options.pages || 1;
this.current_page = 1; this.current_page = 1;
this.sort_preference = options.sort; this.sort_preference = options.sort;
this.is_commentable_cohorted = options.is_commentable_cohorted;
this.bind('add', function(item) { this.bind('add', function(item) {
item.discussion = self; item.discussion = self;
}); });
...@@ -141,6 +142,7 @@ ...@@ -141,6 +142,7 @@
Content.loadContentInfos(response.annotated_content_info); Content.loadContentInfos(response.annotated_content_info);
self.pages = response.num_pages; self.pages = response.num_pages;
self.current_page = response.page; self.current_page = response.page;
self.is_commentable_cohorted = response.is_commentable_cohorted;
return self.reset(new_collection); return self.reset(new_collection);
}, },
error: error error: error
......
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
DiscussionUtil.loadRoles(response.roles); DiscussionUtil.loadRoles(response.roles);
this.courseSettings = new DiscussionCourseSettings(response.course_settings); this.courseSettings = new DiscussionCourseSettings(response.course_settings);
this.is_commentable_cohorted = response.is_commentable_cohorted;
this.discussion = new Discussion(undefined, {pages: response.num_pages}); this.discussion = new Discussion(undefined, {pages: response.num_pages});
this.discussion.reset(response.discussion_data, { this.discussion.reset(response.discussion_data, {
...@@ -152,7 +153,8 @@ ...@@ -152,7 +153,8 @@
model: thread, model: thread,
mode: 'inline', mode: 'inline',
startHeader: this.startHeader, startHeader: this.startHeader,
courseSettings: this.courseSettings courseSettings: this.courseSettings,
is_commentable_cohorted: this.is_commentable_cohorted
}); });
this.threadView.render(); this.threadView.render();
this.listenTo(this.threadView.showView, 'thread:_delete', this.navigateToAllPosts); this.listenTo(this.threadView.showView, 'thread:_delete', this.navigateToAllPosts);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
DiscussionThreadShowView.__super__.initialize.call(this); DiscussionThreadShowView.__super__.initialize.call(this);
this.mode = options.mode || 'inline'; this.mode = options.mode || 'inline';
this.startHeader = options.startHeader; this.startHeader = options.startHeader;
this.is_commentable_cohorted = options.is_commentable_cohorted;
if ((_ref = this.mode) !== 'tab' && _ref !== 'inline') { if ((_ref = this.mode) !== 'tab' && _ref !== 'inline') {
throw new Error('invalid mode: ' + this.mode); throw new Error('invalid mode: ' + this.mode);
} }
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
mode: this.mode, mode: this.mode,
startHeader: this.startHeader, startHeader: this.startHeader,
flagged: this.model.isFlagged(), flagged: this.model.isFlagged(),
is_commentable_cohorted: this.is_commentable_cohorted,
author_display: this.getAuthorDisplay(), author_display: this.getAuthorDisplay(),
cid: this.model.cid, cid: this.model.cid,
readOnly: $('.discussion-module').data('read-only') readOnly: $('.discussion-module').data('read-only')
......
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
self.model = collection.get(id); self.model = collection.get(id);
} }
}); });
this.is_commentable_cohorted = options.is_commentable_cohorted;
this.createShowView(); this.createShowView();
this.responses = new Comments(); this.responses = new Comments();
this.loadedResponses = false; this.loadedResponses = false;
...@@ -422,7 +422,8 @@ ...@@ -422,7 +422,8 @@
this.showView = new DiscussionThreadShowView({ this.showView = new DiscussionThreadShowView({
model: this.model, model: this.model,
mode: this.mode, mode: this.mode,
startHeader: this.startHeader startHeader: this.startHeader,
is_commentable_cohorted: this.is_commentable_cohorted
}); });
this.showView.bind('thread:_delete', this._delete); this.showView.bind('thread:_delete', this._delete);
return this.showView.bind('thread:edit', this.edit); return this.showView.bind('thread:edit', this.edit);
......
...@@ -181,10 +181,19 @@ ...@@ -181,10 +181,19 @@
it('renders correctly for a cohorted thread', function() { it('renders correctly for a cohorted thread', function() {
this.thread.set('group_id', '1'); this.thread.set('group_id', '1');
this.thread.set('group_name', 'Mock Cohort'); this.thread.set('group_name', 'Mock Cohort');
this.view.is_commentable_cohorted = true;
this.view.render(); this.view.render();
return expect(this.view.$('.group-visibility-label').text().trim()) return expect(this.view.$('.group-visibility-label').text().trim())
.toEqual('This post is visible only to Mock Cohort.'); .toEqual('This post is visible only to Mock Cohort.');
}); });
it('renders correctly for a grouped uncohorted thread', function() {
this.thread.set('group_id', '1');
this.thread.set('group_name', 'Mock Cohort');
this.view.is_commentable_cohorted = false;
this.view.render();
return expect(this.view.$('.group-visibility-label').text().trim())
.toEqual('This post is visible to everyone.');
});
}); });
}); });
}).call(this); }).call(this);
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
%> %>
<% } %> <% } %>
<div class="group-visibility-label"> <div class="group-visibility-label">
<% if (obj.group_name) { %> <% if (obj.group_name && is_commentable_cohorted) { %>
<%- <%-
interpolate( interpolate(
gettext('This post is visible only to %(group_name)s.'), gettext('This post is visible only to %(group_name)s.'),
......
...@@ -6,7 +6,7 @@ from uuid import uuid4 ...@@ -6,7 +6,7 @@ from uuid import uuid4
import json import json
from common.test.acceptance.fixtures import LMS_BASE_URL from common.test.acceptance.fixtures import LMS_BASE_URL
from common.test.acceptance.fixtures.course import CourseFixture from common.test.acceptance.fixtures.course import (CourseFixture, XBlockFixtureDesc)
from common.test.acceptance.fixtures.discussion import ( from common.test.acceptance.fixtures.discussion import (
SingleThreadViewFixture, SingleThreadViewFixture,
Thread, Thread,
...@@ -74,6 +74,14 @@ class CohortTestMixin(object): ...@@ -74,6 +74,14 @@ class CohortTestMixin(object):
}, },
}) })
def enable_cohorting(self, course_fixture):
"""
enables cohorting for the current course fixture.
"""
url = LMS_BASE_URL + "/courses/" + course_fixture._course_key + '/cohorts/settings' # pylint: disable=protected-access
data = json.dumps({'always_cohort_inline_discussions': True})
response = course_fixture.session.patch(url, data=data, headers=course_fixture.headers)
def disable_cohorting(self, course_fixture): def disable_cohorting(self, course_fixture):
""" """
Disables cohorting for the current course fixture. Disables cohorting for the current course fixture.
...@@ -111,8 +119,21 @@ class BaseDiscussionTestCase(UniqueCourseTest, ForumsConfigMixin): ...@@ -111,8 +119,21 @@ class BaseDiscussionTestCase(UniqueCourseTest, ForumsConfigMixin):
self.discussion_id = "test_discussion_{}".format(uuid4().hex) self.discussion_id = "test_discussion_{}".format(uuid4().hex)
self.course_fixture = CourseFixture(**self.course_info) self.course_fixture = CourseFixture(**self.course_info)
self.course_fixture.add_children(
XBlockFixtureDesc("chapter", "Test Section").add_children(
XBlockFixtureDesc("sequential", "Test Subsection").add_children(
XBlockFixtureDesc("vertical", "Test Unit").add_children(
XBlockFixtureDesc(
"discussion",
"Test Discussion",
metadata={"discussion_id": self.discussion_id}
)
)
)
)
)
self.course_fixture.add_advanced_settings( self.course_fixture.add_advanced_settings(
{'discussion_topics': {'value': {'Test Discussion Topic': {'id': self.discussion_id}}}} {'discussion_topics': {'value': {'General': {'id': 'course'}}}}
) )
self.course_fixture.install() self.course_fixture.install()
......
...@@ -49,6 +49,10 @@ class CohortedDiscussionTestMixin(BaseDiscussionMixin, CohortTestMixin): ...@@ -49,6 +49,10 @@ class CohortedDiscussionTestMixin(BaseDiscussionMixin, CohortTestMixin):
# Must be moderator to view content in a cohort other than your own # Must be moderator to view content in a cohort other than your own
AutoAuthPage(self.browser, course_id=self.course_id, roles="Moderator").visit() AutoAuthPage(self.browser, course_id=self.course_id, roles="Moderator").visit()
self.thread_id = self.setup_thread(1, group_id=self.cohort_1_id) self.thread_id = self.setup_thread(1, group_id=self.cohort_1_id)
# Enable cohorts and verify that the post shows to cohort only.
self.enable_cohorting(self.course_fixture)
self.refresh_thread_page(self.thread_id)
self.assertEquals( self.assertEquals(
self.thread_page.get_group_visibility_label(), self.thread_page.get_group_visibility_label(),
"This post is visible only to {}.".format(self.cohort_1_name) "This post is visible only to {}.".format(self.cohort_1_name)
......
...@@ -270,12 +270,13 @@ class DiscussionNavigationTest(BaseDiscussionTestCase): ...@@ -270,12 +270,13 @@ class DiscussionNavigationTest(BaseDiscussionTestCase):
css=".forum-nav-browse-menu-item[data-discussion-id='{}']".format(self.discussion_id) css=".forum-nav-browse-menu-item[data-discussion-id='{}']".format(self.discussion_id)
) )
self.assertTrue(topic_button.visible) self.assertTrue(topic_button.visible)
topic_button.click() topic_button.click()
# Verify the thread's topic has been pushed to breadcrumbs # Verify the thread's topic has been pushed to breadcrumbs
breadcrumbs = self.thread_page.q(css=".breadcrumbs .nav-item") breadcrumbs = self.thread_page.q(css=".breadcrumbs .nav-item")
self.assertEqual(len(breadcrumbs), 2) self.assertEqual(len(breadcrumbs), 3)
self.assertEqual(breadcrumbs[1].text, "Test Discussion Topic") self.assertEqual(breadcrumbs[2].text, "Topic-Level Student-Visible Label")
def test_breadcrumbs_back_to_all_topics(self): def test_breadcrumbs_back_to_all_topics(self):
topic_button = self.thread_page.q( topic_button = self.thread_page.q(
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
sortPreference = options.sortPreference, sortPreference = options.sortPreference,
threads = options.threads, threads = options.threads,
threadPages = options.threadPages, threadPages = options.threadPages,
isCommentableCohorted = options.isCommentableCohorted,
contentInfo = options.contentInfo, contentInfo = options.contentInfo,
user = new DiscussionUser(userInfo), user = new DiscussionUser(userInfo),
discussion, discussion,
...@@ -39,7 +40,8 @@ ...@@ -39,7 +40,8 @@
Content.loadContentInfos(contentInfo); Content.loadContentInfos(contentInfo);
// Create a discussion model // Create a discussion model
discussion = new Discussion(threads, {pages: threadPages, sort: sortPreference}); discussion = new Discussion(threads, {pages: threadPages, sort: sortPreference,
is_commentable_cohorted: isCommentableCohorted});
courseSettings = new DiscussionCourseSettings(options.courseSettings); courseSettings = new DiscussionCourseSettings(options.courseSettings);
// Create the discussion board view // Create the discussion board view
......
...@@ -102,7 +102,8 @@ ...@@ -102,7 +102,8 @@
model: this.thread, model: this.thread,
mode: 'tab', mode: 'tab',
startHeader: this.startHeader, startHeader: this.startHeader,
courseSettings: this.courseSettings courseSettings: this.courseSettings,
is_commentable_cohorted: this.discussion.is_commentable_cohorted
}); });
this.main.render(); this.main.render();
this.main.on('thread:responses:rendered', function() { this.main.on('thread:responses:rendered', function() {
......
...@@ -56,7 +56,8 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str ...@@ -56,7 +56,8 @@ from openedx.core.djangolib.js_utils import dump_js_escaped_json, js_escaped_str
threadPages: '${thread_pages | n, js_escaped_string}', threadPages: '${thread_pages | n, js_escaped_string}',
contentInfo: ${annotated_content_info | n, dump_js_escaped_json}, contentInfo: ${annotated_content_info | n, dump_js_escaped_json},
courseName: '${course.display_name_with_default | n, js_escaped_string}', courseName: '${course.display_name_with_default | n, js_escaped_string}',
courseSettings: ${course_settings | n, dump_js_escaped_json} courseSettings: ${course_settings | n, dump_js_escaped_json},
isCommentableCohorted: ${is_commentable_cohorted | n, dump_js_escaped_json}
}); });
}); });
}); });
......
...@@ -438,6 +438,7 @@ def _create_discussion_board_context(request, course_key, discussion_id=None, th ...@@ -438,6 +438,7 @@ def _create_discussion_board_context(request, course_key, discussion_id=None, th
'sort_preference': cc_user.default_sort_key, 'sort_preference': cc_user.default_sort_key,
'category_map': course_settings["category_map"], 'category_map': course_settings["category_map"],
'course_settings': course_settings, 'course_settings': course_settings,
'is_commentable_cohorted': is_commentable_cohorted(course_key, discussion_id)
}) })
return context return context
......
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