diff --git a/app/controllers/discussion_topics_controller.rb b/app/controllers/discussion_topics_controller.rb index 3e171265aa8..99005f0f3e7 100644 --- a/app/controllers/discussion_topics_controller.rb +++ b/app/controllers/discussion_topics_controller.rb @@ -533,6 +533,7 @@ class DiscussionTopicsController < ApplicationController URL_ROOT: named_context_url(@context, :api_v1_context_discussion_topics_url), PERMISSIONS: { CAN_CREATE_ASSIGNMENT: @context.respond_to?(:assignments) && @context.assignments.temp_record.grants_right?(@current_user, session, :create), + CAN_UPDATE_ASSIGNMENT: @context.respond_to?(:assignments) && @context.assignments.temp_record.grants_right?(@current_user, session, :update), CAN_ATTACH: @topic.grants_right?(@current_user, session, :attach), CAN_MODERATE: user_can_moderate, CAN_SET_GROUP: can_set_group_category, diff --git a/spec/coffeescripts/views/DiscussionTopics/EditViewSpec.js b/spec/coffeescripts/views/DiscussionTopics/EditViewSpec.js index 5597117f220..75f46d1ff36 100644 --- a/spec/coffeescripts/views/DiscussionTopics/EditViewSpec.js +++ b/spec/coffeescripts/views/DiscussionTopics/EditViewSpec.js @@ -255,6 +255,15 @@ test('does not show todo date elements when grading is enabled', function () { equal(view.$el.find('#todo_options')[0].style.display, 'none') }) +test('does retain the assignment when user with assignment-edit permission edits discussion', function () { + const view = this.editView({ + withAssignment: true, + permissions: {CAN_UPDATE_ASSIGNMENT: true, CAN_CREATE_ASSIGNMENT: false}, + }) + const formData = view.getFormData() + equal(formData.set_assignment, '1') +}) + test('does save todo date if allow_todo_date is checked and discussion is not graded', function () { ENV.STUDENT_PLANNER_ENABLED = true const todo_date = new Date('2017-05-25T08:00:00-0800') diff --git a/ui/features/discussion_topic_edit/backbone/views/EditView.js b/ui/features/discussion_topic_edit/backbone/views/EditView.js index 0d43c1ee5aa..500db499579 100644 --- a/ui/features/discussion_topic_edit/backbone/views/EditView.js +++ b/ui/features/discussion_topic_edit/backbone/views/EditView.js @@ -557,7 +557,14 @@ EditView.prototype.getFormData = function () { // The controller checks for set_assignment on the assignment model, // so we can't make it undefined here for the case of discussion topics. data.assignment = this.model.createAssignment({ - set_assignment: '0', + // there are no assignment params here, so sending a '0' will cause the + // @discussion_topic.assignment to be removed in the back end if it already + // exists. By sending a '1', you can preserve the assignment as-is. + set_assignment: this.permissions.CAN_CREATE_ASSIGNMENT + ? '0' + : this.permissions.CAN_UPDATE_ASSIGNMENT + ? '1' + : '0', }) } // these options get passed to Backbone.sync in ValidatedFormView