From 2000a050eae4856b63edbce49a17666041f5839f Mon Sep 17 00:00:00 2001 From: Aaron Kc Hsu Date: Thu, 18 Oct 2018 14:28:38 -0600 Subject: [PATCH] Stop Hard concluded enrollments fromn participating in groups fixes COMMS-1488 Test Plan * Create a course and enroll at least 1 student * Create a group set and a group to add the student to * Manually conclude the students enrollment * As the student navigate to your dashboard * Notice you won't have access to the group Change-Id: Ie5d6689e435af060352e02b2762d39351c5a131f Reviewed-on: https://gerrit.instructure.com/168892 Tested-by: Jenkins Reviewed-by: Landon Gilbert-Bland QA-Review: Landon Gilbert-Bland Product-Review: Aaron Hsu --- app/models/group.rb | 21 +++++++++++---------- spec/apis/v1/discussion_topics_api_spec.rb | 2 +- spec/models/announcement_spec.rb | 13 ++++++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index 191e296596a..f77f83b3dc6 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -473,9 +473,17 @@ class Group < ActiveRecord::Base # if you modify this set_policy block, note that we've denormalized this # permission check for efficiency -- see User#cached_contexts set_policy do + # Participate means the user is connected to the group somehow and can be - given { |user| user && can_participate?(user) } - can :participate + given { |user| user && can_participate?(user) && self.has_member?(user) } + can :participate and + can :manage_calendar and + can :manage_content and + can :manage_files and + can :manage_wiki and + can :post_to_forum and + can :create_collaborations and + can :create_forum # Course-level groups don't grant any permissions besides :participate (because for a teacher to add a student to a # group, the student must be able to :participate, and the teacher should be able to add students while the course @@ -485,15 +493,8 @@ class Group < ActiveRecord::Base use_additional_policy do given { |user| user && self.has_member?(user) } - can :create_collaborations and - can :manage_calendar and - can :manage_content and - can :manage_files and - can :manage_wiki and - can :post_to_forum and - can :create_forum and - can :read and can :read_forum and + can :read and can :read_announcements and can :read_roster and can :view_unpublished_items diff --git a/spec/apis/v1/discussion_topics_api_spec.rb b/spec/apis/v1/discussion_topics_api_spec.rb index c5629061012..7e0e67ce262 100644 --- a/spec/apis/v1/discussion_topics_api_spec.rb +++ b/spec/apis/v1/discussion_topics_api_spec.rb @@ -2976,7 +2976,7 @@ describe DiscussionTopicsController, type: :request do it "duplicate publishes group context discussions if its a student duplicating" do @user = @student group_category = @course.group_categories.create!(:name => 'group category') - @course.enroll_student(@student, :active_all => true) + @course.enroll_student(@student, :enrollment_state => "active") group = group_category.groups.create!(:name => "group", :context => @course) group.add_user(@student) topic = group.discussion_topics.create!(:title => "student topic", :user => @student, diff --git a/spec/models/announcement_spec.rb b/spec/models/announcement_spec.rb index 76ac831356d..551d8cdf007 100644 --- a/spec/models/announcement_spec.rb +++ b/spec/models/announcement_spec.rb @@ -102,9 +102,16 @@ describe Announcement do expect(Announcement.context_allows_user_to_create?(@course, @user, {})).to be_falsey end - it "should allow announcements on a group" do - group_with_user(:active_user => 1) - expect(Announcement.context_allows_user_to_create?(@group, @user, {})).to be_truthy + it "should not allow announcements creation by students on a group" do + course_with_student + group_with_user(is_public: true, :active_user => 1, :context => @course) + expect(Announcement.context_allows_user_to_create?(@group, @student, {})).to be_falsey + end + + it "should allow announcements creation by teacher on a group" do + course_with_teacher(:active_all => true) + group_with_user(is_public: true, :active_user => 1, :context => @course) + expect(Announcement.context_allows_user_to_create?(@group, @teacher, {})).to be_truthy end it 'allows announcements to be viewed without :read_forum' do