Publish student-duplicated group context discussions.
If a student creates, and then duplicates, a discussion in a group context, that duplicate needs to be published for the student to then be able to do anything with it; students can't publish after the fact, so the duplicate needs to be _created_ published. Fixes COMMS-1243. Test Plan: * Have a course with a student and a teacher. * make a group in the course, add the student to it. * Go to the group home page. * As the student, make a discussion *FOR THE GROUP* and duplicate it. * The duplicate should be published. * As the teacher, do the same thing, but the result should be an unpublished copy (since teachers can publish after the fact) Change-Id: If745a8c83da098fbb8902841caed73bafdaef6e1 Reviewed-on: https://gerrit.instructure.com/155188 Tested-by: Jenkins Reviewed-by: Steven Burnett <sburnett@instructure.com> QA-Review: Steven Burnett <sburnett@instructure.com> Product-Review: Venk Natarajan <vnatarajan@instructure.com>
This commit is contained in:
parent
d9d9d70dcb
commit
48cd64645f
|
@ -250,6 +250,11 @@ class DiscussionTopicsApiController < ApplicationController
|
|||
if @topic.pinned
|
||||
new_topic.position = @topic.context.discussion_topics.maximum(:position) + 1
|
||||
end
|
||||
# People that can't moderate don't have power to publish separately, so
|
||||
# just publish their topics straightaway.
|
||||
if !@context.grants_right?(@current_user, session, :moderate_forum)
|
||||
new_topic.publish
|
||||
end
|
||||
if new_topic.save!
|
||||
result = discussion_topic_api_json(new_topic, @context, @current_user, session,
|
||||
:include_sections => true)
|
||||
|
|
|
@ -2862,6 +2862,7 @@ describe DiscussionTopicsController, type: :request do
|
|||
describe "duplicate" do
|
||||
before :once do
|
||||
course_with_teacher(:active_all => true)
|
||||
@student = User.create!(:name => "foo", :short_name => "fo")
|
||||
student_in_course(:course => @course, :active_all => true)
|
||||
group_discussion_topic_model()
|
||||
end
|
||||
|
@ -2976,6 +2977,48 @@ describe DiscussionTopicsController, type: :request do
|
|||
expect(json["sections"][0]["id"]).to eq section1.id
|
||||
end
|
||||
|
||||
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)
|
||||
group = group_category.groups.create!(:name => "group", :context => @course)
|
||||
group.add_user(@student)
|
||||
topic = group.discussion_topics.create!(:title => "student topic", :user => @student,
|
||||
:workflow_state => "active", :message => "hello")
|
||||
json = api_call(:post, "/api/v1/groups/#{group.id}/discussion_topics/#{topic.id}/duplicate",
|
||||
{ :controller => "discussion_topics_api",
|
||||
:action => "duplicate",
|
||||
:format => "json",
|
||||
:group_id => group.to_param,
|
||||
:topic_id => topic.to_param },
|
||||
{},
|
||||
{},
|
||||
:expected_status => 200)
|
||||
duplicated_topic = DiscussionTopic.last
|
||||
expect(duplicated_topic.published?).to be_truthy
|
||||
expect(json["published"]).to be_truthy
|
||||
end
|
||||
|
||||
it "duplicate does not publish group context discussions if its a teacher duplicating" do
|
||||
@user = @teacher
|
||||
group_category = @course.group_categories.create!(:name => 'group category')
|
||||
group = group_category.groups.create!(:name => "group", :context => @course)
|
||||
topic = group.discussion_topics.create!(:title => "teacher topic", :user => @teacher,
|
||||
:workflow_state => "active", :message => "hello")
|
||||
json = api_call(:post, "/api/v1/groups/#{group.id}/discussion_topics/#{topic.id}/duplicate",
|
||||
{ :controller => "discussion_topics_api",
|
||||
:action => "duplicate",
|
||||
:format => "json",
|
||||
:group_id => group.to_param,
|
||||
:topic_id => topic.to_param },
|
||||
{},
|
||||
{},
|
||||
:expected_status => 200)
|
||||
duplicated_topic = DiscussionTopic.last
|
||||
expect(duplicated_topic.published?).to be_falsey
|
||||
expect(json["published"]).to be_falsey
|
||||
end
|
||||
|
||||
it "duplicate updates positions" do
|
||||
@user = @teacher
|
||||
topic1 = DiscussionTopic.create!(:context => @course, :pinned => true, :position => 20,
|
||||
|
|
Loading…
Reference in New Issue