From 9abdd0af3d16f0b05af7b38e9a2ac79c26ba44cc Mon Sep 17 00:00:00 2001
From: attiyaishaque <atiya.ishaq@arbisoft.com>
Date: Mon, 16 Apr 2018 12:30:56 +0500
Subject: [PATCH] Discussion moderators, TA's and admins see the posts
 according to cohorts.

---
 .../js/discussion/views/new_post_view.js      | 10 ++++++++++
 .../discussion/view/new_post_view_spec.js     | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/common/static/common/js/discussion/views/new_post_view.js b/common/static/common/js/discussion/views/new_post_view.js
index 2ba9c63db1e..db9a886de54 100644
--- a/common/static/common/js/discussion/views/new_post_view.js
+++ b/common/static/common/js/discussion/views/new_post_view.js
@@ -135,6 +135,7 @@
                 },
                 'submit .forum-new-post-form': 'createPost',
                 'change .post-option-input': 'postOptionChange',
+                'change .js-group-select': 'groupOptionChange',
                 'click .cancel': 'cancel',
                 'click  .add-post-cancel': 'cancel',
                 'reset .forum-new-post-form': 'updateStyles',
@@ -146,6 +147,7 @@
             NewPostView.prototype.toggleGroupDropdown = function($target) {
                 if ($target.data('divided')) {
                     $('.js-group-select').prop('disabled', false);
+                    $('.js-group-select').val('').prop('selected', true);
                     return $('.group-selector-wrapper').removeClass('disabled');
                 } else {
                     $('.js-group-select').val('').prop('disabled', true);
@@ -257,6 +259,14 @@
                 return setTimeout(function() { return self.$('.post-option-input').trigger('change'); }, 1);
             };
 
+            NewPostView.prototype.groupOptionChange = function(event) {
+                var $target = $(event.target),
+                    data = $target.data();
+                this.group_name = this.$('.js-group-select option:selected').text();
+                data.divided = true;
+                this.updateVisibilityMessage($target);
+            };
+
             return NewPostView;
         }(Backbone.View));
     }
diff --git a/common/static/common/js/spec/discussion/view/new_post_view_spec.js b/common/static/common/js/spec/discussion/view/new_post_view_spec.js
index b1b292941e8..b388526befd 100644
--- a/common/static/common/js/spec/discussion/view/new_post_view_spec.js
+++ b/common/static/common/js/spec/discussion/view/new_post_view_spec.js
@@ -95,6 +95,25 @@
                 $('.post-topic').trigger('change');
                 return checkVisibility(this.view, true, false, false);
             });
+            it('visibility message changes when group is changed', function() {
+                DiscussionSpecHelper.makeModerator();
+                checkVisibility(this.view, true, false, true);
+
+                $('option:contains(Topic)').prop('selected', true);
+                $('.post-topic').trigger('change');
+                expect($('.js-group-select option:selected').text())
+                    .toEqual('All Groups');
+                expect($('.group-visibility').text().trim())
+                    .toEqual('This post will be visible only to All Groups.');
+
+                $('.js-group-select option:contains(Cohort1)').prop('selected', true);
+                $('.js-group-select').trigger('change');
+                expect($('.js-group-select option:selected').text())
+                    .toEqual('Cohort1');
+                expect($('.group-visibility').text().trim())
+                    .toEqual('This post will be visible only to Cohort1.');
+                return checkVisibility(this.view, true, false, false);
+            });
             it('allows the user to make a group selection', function() {
                 var expectedGroupId,
                     self = this;
-- 
GitLab