Hides groups from courses that are unpublished
closes CNVS-17635 closes gh-97 Test Plan: - Create a course that is unpublished - Add a student to the class - Add the student to a group - Login as the student - Go to the courses index page (/courses) - The group should not be shown - Publish the course - The group should now be shown with a link to it Change-Id: I3588cbd323cd065a33898c91021f475507101dee Reviewed-on: https://gerrit.instructure.com/46266 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Clare Strong <clare@instructure.com> Product-Review: Clay Diffrient <cdiffrient@instructure.com>
This commit is contained in:
parent
833d1e82ef
commit
1d2094e35d
|
@ -357,6 +357,8 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
@visible_groups = @current_user.visible_groups
|
||||
|
||||
@past_enrollments.sort_by!{|e| Canvas::ICU.collation_key(e.long_name)}
|
||||
[@current_enrollments, @future_enrollments].each{|list| list.sort_by!{|e| [e.active? ? 1 : 0, Canvas::ICU.collation_key(e.long_name)] }}
|
||||
}
|
||||
|
|
|
@ -581,6 +581,16 @@ class User < ActiveRecord::Base
|
|||
where("groups.workflow_state <> 'deleted'")
|
||||
end
|
||||
|
||||
# Returns an array of groups which are currently visible for the user.
|
||||
def visible_groups
|
||||
@visible_groups ||= begin
|
||||
enrollments = self.cached_current_enrollments(preload_courses: true)
|
||||
visible_groups = self.current_groups.select do |group|
|
||||
group.context_type != 'Course' || enrollments.any? { |en| en.course == group.context && (en.admin? || en.course.available?)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def <=>(other)
|
||||
self.name <=> other.name
|
||||
end
|
||||
|
|
|
@ -40,10 +40,10 @@
|
|||
<% end %>
|
||||
|
||||
<% @show_star_column = false %>
|
||||
<% unless @current_user.current_groups.empty? %>
|
||||
<% unless @visible_groups.empty? %>
|
||||
<h2><%= t('headings.my_groups', %{My Groups}) %></h2>
|
||||
<table id="my_groups_table" class="table table-bordered current_groups course-list-table">
|
||||
<% @current_user.current_groups.each do |group| %>
|
||||
<% @visible_groups.each do |group| %>
|
||||
<% group_name = group.name %>
|
||||
<tr>
|
||||
<td>
|
||||
|
|
|
@ -2796,4 +2796,31 @@ describe User do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'visible_groups' do
|
||||
it "should include groups in published courses" do
|
||||
course_with_student active_all:true
|
||||
@group = Group.create! context: @course, name: "GroupOne"
|
||||
@group.users << @student
|
||||
@group.save!
|
||||
expect(@student.visible_groups.size).to eq 1
|
||||
end
|
||||
|
||||
it "should not include groups that belong to unpublished courses" do
|
||||
course_with_student
|
||||
@group = Group.create! context: @course, name: "GroupOne"
|
||||
@group.users << @student
|
||||
@group.save!
|
||||
expect(@student.visible_groups.size).to eq 0
|
||||
end
|
||||
|
||||
it "should include account groups" do
|
||||
account = account_model(:parent_account => Account.default)
|
||||
student = user active_all: true
|
||||
@group = Group.create! context: account, name: "GroupOne"
|
||||
@group.users << student
|
||||
@group.save!
|
||||
expect(student.visible_groups.size).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -372,6 +372,7 @@ describe "courses" do
|
|||
it "should display user groups on courses page" do
|
||||
group = Group.create!(:name => "group1", :context => @course)
|
||||
group.add_user(@student)
|
||||
enroll_student(@student, true)
|
||||
|
||||
login_as(@student.name)
|
||||
get '/courses'
|
||||
|
|
|
@ -26,6 +26,7 @@ describe "/courses/index" do
|
|||
assigns[:current_enrollments] = [@enrollment]
|
||||
assigns[:past_enrollments] = []
|
||||
assigns[:future_enrollments] = []
|
||||
assigns[:visible_groups] = []
|
||||
render "courses/index"
|
||||
expect(response).not_to be_nil
|
||||
end
|
||||
|
@ -37,6 +38,7 @@ describe "/courses/index" do
|
|||
assigns[:current_enrollments] = [@enrollment]
|
||||
assigns[:past_enrollments] = []
|
||||
assigns[:future_enrollments] = []
|
||||
assigns[:visible_groups] = [@group]
|
||||
render "courses/index"
|
||||
doc = Nokogiri::HTML.parse(response.body)
|
||||
expect(doc.at_css('#my_groups_table tr:first span.subtitle').text).to eq @course.name
|
||||
|
|
Loading…
Reference in New Issue