From 38cc6c7f450f0d5fb7ea6320f5431ff0f86d8bbd Mon Sep 17 00:00:00 2001 From: Drake Harper Date: Tue, 19 Oct 2021 12:03:18 -0600 Subject: [PATCH] Add studentReporting to DiscussionTopicPermissionsType MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs VICE-2174 flag=discussions_reporting Test Plan: - turn discussion reporting ff on - go to http://localhost:3000/graphiql - run a query similar to the example below > should see studentReporting as true - go to the discussions landing page in the course you queried against - click the settings cog in the top right - change student reporting to be false (unchecked) - run the query again - studentReporting should be false Example Query: (remember to update the _id for the discussion) query MyQuery { __typename legacyNode(_id: "23", type: Discussion) { ... on Discussion { id _id title permissions { studentReporting } } } } Change-Id: Ibbbae7e546efdcbc52901a38bcf1e606f3881055 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/276278 Reviewed-by: Omar Soto-Fortuño QA-Review: Omar Soto-Fortuño Product-Review: Omar Soto-Fortuño Tested-by: Service Cloud Jenkins --- app/graphql/types/discussion_permissions_type.rb | 5 +++++ app/models/course.rb | 4 ++++ app/models/discussion_topic.rb | 3 +++ spec/graphql/types/discussion_type_spec.rb | 4 ++++ spec/models/discussion_topic_spec.rb | 2 +- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/graphql/types/discussion_permissions_type.rb b/app/graphql/types/discussion_permissions_type.rb index 70c47f98f3d..87eb238c2bc 100644 --- a/app/graphql/types/discussion_permissions_type.rb +++ b/app/graphql/types/discussion_permissions_type.rb @@ -37,6 +37,11 @@ module Types object[:loader].load(:reply) end + field :student_reporting, Boolean, null: true + def student_reporting + object[:loader].load(:student_reporting) + end + field :update, Boolean, null: true def update object[:loader].load(:update) diff --git a/app/models/course.rb b/app/models/course.rb index 5726c0a18dd..8af71d83d73 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -2632,6 +2632,10 @@ class Course < ActiveRecord::Base :homeroom_course, :course_color, :alt_name] end + def student_reporting? + !!self.allow_student_discussion_reporting + end + def set_course_dates_if_blank(shift_options) unless Canvas::Plugin.value_to_boolean(shift_options[:remove_dates]) self.start_at ||= shift_options[:default_start_at] diff --git a/app/models/discussion_topic.rb b/app/models/discussion_topic.rb index 4beb28283c1..212c12ad799 100644 --- a/app/models/discussion_topic.rb +++ b/app/models/discussion_topic.rb @@ -1173,6 +1173,9 @@ class DiscussionTopic < ActiveRecord::Base given { |user, session| context.respond_to?(:allow_student_forum_attachments) && context.allow_student_forum_attachments && context.grants_any_right?(user, session, :create_forum, :post_to_forum) } can :attach + given { course.student_reporting? } + can :student_reporting + given { |user, session| !self.root_topic_id && self.context.grants_all_rights?(user, session, :read_forum, :moderate_forum) && self.available_for?(user) } can :update and can :read_as_admin and can :delete and can :create and can :read and can :attach diff --git a/spec/graphql/types/discussion_type_spec.rb b/spec/graphql/types/discussion_type_spec.rb index 3633efc3810..94928ffdac7 100644 --- a/spec/graphql/types/discussion_type_spec.rb +++ b/spec/graphql/types/discussion_type_spec.rb @@ -58,6 +58,10 @@ RSpec.shared_examples "DiscussionType" do value: 'readAsAdmin', allowed: ->(user) { discussion.grants_right?(user, nil, :read_as_admin) } }, + { + value: 'studentReporting', + allowed: ->(user) { discussion.course.student_reporting? } + }, { value: 'manageContent', allowed: ->(user) { discussion.context.grants_right?(user, :manage_content) } diff --git a/spec/models/discussion_topic_spec.rb b/spec/models/discussion_topic_spec.rb index ac34b536014..24412f98129 100644 --- a/spec/models/discussion_topic_spec.rb +++ b/spec/models/discussion_topic_spec.rb @@ -272,7 +272,7 @@ describe DiscussionTopic do it "does not grant moderate permissions without read permissions" do @course.account.role_overrides.create!(:role => teacher_role, :permission => 'read_forum', :enabled => false) - expect(@topic.reload.check_policy(@teacher2)).to eql [:create, :duplicate, :attach] + expect(@topic.reload.check_policy(@teacher2)).to eql [:create, :duplicate, :attach, :student_reporting] end it "grants permissions if it not locked" do