Skip to content

Commit ad02896

Browse files
committed
restrict api discussion updates for group discussions
test plan: * create a group set with a group * create a group discussion for the group set * in two separate tabs, open the discussion edit page for the root discussion topic (on the course) and the edit page for the group level discussion topic * make a change to the root topic (like "users must post before seeing replies" / require_initial_post) * without refreshing, save the group topic as well * view the the group topic in the API (/api/v1/groups/X/discussion_topics/Y) * the "require_initial_post" setting should be the same as the root closes #CNVS-34462 Change-Id: Id8629bc87b60ea8ea86c3148187890a985c0fc15 Reviewed-on: https://gerrit.instructure.com/101126 Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Deepeeca Soundarrajan <dsoundarrajan@instructure.com> Tested-by: Jenkins Product-Review: James Williams <jamesw@instructure.com>
1 parent 139fcc1 commit ad02896

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

app/controllers/discussion_topics_controller.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,13 +900,16 @@ def user_can_moderate
900900
end
901901

902902
API_ALLOWED_TOPIC_FIELDS = %w(title message discussion_type delayed_post_at lock_at podcast_enabled
903-
podcast_has_student_posts require_initial_post is_announcement pinned
903+
podcast_has_student_posts require_initial_post pinned
904904
group_category_id allow_rating only_graders_can_rate sort_by_rating).freeze
905905

906+
API_ALLOWED_TOPIC_FIELDS_FOR_GROUP = %w(title message discussion_type podcast_enabled pinned
907+
allow_rating only_graders_can_rate sort_by_rating).freeze
908+
909+
906910
def process_discussion_topic(is_new = false)
907911
@errors = {}
908-
discussion_topic_hash = params.permit(*API_ALLOWED_TOPIC_FIELDS)
909-
model_type = value_to_boolean(discussion_topic_hash.delete(:is_announcement)) && @context.announcements.temp_record.grants_right?(@current_user, session, :create) ? :announcements : :discussion_topics
912+
model_type = value_to_boolean(params[:is_announcement]) && @context.announcements.temp_record.grants_right?(@current_user, session, :create) ? :announcements : :discussion_topics
910913
if is_new
911914
@topic = @context.send(model_type).build
912915
else
@@ -915,6 +918,9 @@ def process_discussion_topic(is_new = false)
915918

916919
return unless authorized_action(@topic, @current_user, (is_new ? :create : :update))
917920

921+
allowed_fields = @context.is_a?(Group) ? API_ALLOWED_TOPIC_FIELDS_FOR_GROUP : API_ALLOWED_TOPIC_FIELDS
922+
discussion_topic_hash = params.permit(*allowed_fields)
923+
918924
prior_version = @topic.generate_prior_version
919925
process_podcast_parameters(discussion_topic_hash)
920926

spec/apis/v1/discussion_topics_api_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,20 @@ def blank_fallback
639639
expect(@topic).not_to be_locked
640640
end
641641

642+
it "should not update certain attributes for group discussions" do
643+
group_category = @course.group_categories.create(:name => 'watup')
644+
group = group_category.groups.create!(:name => "group1", :context => @course)
645+
gtopic = create_topic(group, :title => "topic")
646+
647+
api_call(:put, "/api/v1/groups/#{group.id}/discussion_topics/#{gtopic.id}",
648+
{:controller => "discussion_topics", :action => "update", :format => "json", :group_id => group.to_param, :topic_id => gtopic.to_param},
649+
{:allow_rating => '1', :require_initial_post => '1'})
650+
651+
gtopic.reload
652+
expect(gtopic.allow_rating).to be_truthy
653+
expect(gtopic.require_initial_post).to_not be_truthy
654+
end
655+
642656
context "publishing" do
643657
it "should publish a draft state topic" do
644658
@topic.workflow_state = 'unpublished'

0 commit comments

Comments
 (0)