allow discussion_topics to be edited without losing assingment

users with only assignment edit permissions (and not create) would
cause discussion_topics to lose their assignments if edited. This
change keeps the assignment as is when one of these users edits the
discussion, but they cannot change the assignment details themselves.

closes EVAL-3117
flag=none

test plan:
- create a role with permission 'Assignments and Quizzes - Edit' turned
    on, but the 'create' one turned off
- create a graded discussion topic on a course
- give someone in the course this new role
- masquerade as this user and edit the discussion topic
- notice that you cannot change the graded status or any assignment
    specific information (like due dates or points possible...)
- after saving, the assignment should still be 'graded' and have all
    the same assignment details

Change-Id: If25742a51f86cd925f70b8c78e611c5953e61d01
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/320395
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Kai Bjorkman <kbjorkman@instructure.com>
Reviewed-by: Cameron Ray <cameron.ray@instructure.com>
QA-Review: Kai Bjorkman <kbjorkman@instructure.com>
Product-Review: Sam Garza <sam.garza@instructure.com>
This commit is contained in:
Derek Williams 2023-06-13 12:03:40 -04:00
parent 239fd519b4
commit 97ac102945
3 changed files with 18 additions and 1 deletions

View File

@ -533,6 +533,7 @@ class DiscussionTopicsController < ApplicationController
URL_ROOT: named_context_url(@context, :api_v1_context_discussion_topics_url), URL_ROOT: named_context_url(@context, :api_v1_context_discussion_topics_url),
PERMISSIONS: { PERMISSIONS: {
CAN_CREATE_ASSIGNMENT: @context.respond_to?(:assignments) && @context.assignments.temp_record.grants_right?(@current_user, session, :create), 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_ATTACH: @topic.grants_right?(@current_user, session, :attach),
CAN_MODERATE: user_can_moderate, CAN_MODERATE: user_can_moderate,
CAN_SET_GROUP: can_set_group_category, CAN_SET_GROUP: can_set_group_category,

View File

@ -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') 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 () { test('does save todo date if allow_todo_date is checked and discussion is not graded', function () {
ENV.STUDENT_PLANNER_ENABLED = true ENV.STUDENT_PLANNER_ENABLED = true
const todo_date = new Date('2017-05-25T08:00:00-0800') const todo_date = new Date('2017-05-25T08:00:00-0800')

View File

@ -557,7 +557,14 @@ EditView.prototype.getFormData = function () {
// The controller checks for set_assignment on the assignment model, // The controller checks for set_assignment on the assignment model,
// so we can't make it undefined here for the case of discussion topics. // so we can't make it undefined here for the case of discussion topics.
data.assignment = this.model.createAssignment({ 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 // these options get passed to Backbone.sync in ValidatedFormView