canvas-lms/app/models/sub_assignment.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.9 KiB
Ruby
Raw Normal View History

make grading endpoints support checkpoint discussions closes VICE-3836 flag=discussion_checkpoints Test Plan: 1. Enable the "discussion_checkpoints" root account feature flag. 2. Create a graded discussion 3. In a rails console, create two checkpoints for the discussion: ``` discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_TOPIC, due_at: 2.days.from_now ) discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_ENTRY, due_at: 3.days.from_now ) ``` 4. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: POST /courses/:course_id/gradebook/update_submission submission: { assignment_id: <the discussion topic's assignment_id>, user_id: <an assigned student's ID>, grade: 10, checkpoint_label: "reply_to_topic" } The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 10 ``` 5. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: PUT /api/v1/courses/:course_id/assignments/:assignment_id /submissions/:user_id submission: { posted_grade: 5 }, checkpoint_label: "reply_to_topic" The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 5 ``` Change-Id: I09d141af0278d5a5d3134f458cc698e0fec60db2 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/330375 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Reviewed-by: Jason Gillett <jason.gillett@instructure.com>
2023-10-14 03:17:48 +08:00
# frozen_string_literal: true
#
# Copyright (C) 2023 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
make grading endpoints support checkpoint discussions closes VICE-3836 flag=discussion_checkpoints Test Plan: 1. Enable the "discussion_checkpoints" root account feature flag. 2. Create a graded discussion 3. In a rails console, create two checkpoints for the discussion: ``` discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_TOPIC, due_at: 2.days.from_now ) discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_ENTRY, due_at: 3.days.from_now ) ``` 4. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: POST /courses/:course_id/gradebook/update_submission submission: { assignment_id: <the discussion topic's assignment_id>, user_id: <an assigned student's ID>, grade: 10, checkpoint_label: "reply_to_topic" } The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 10 ``` 5. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: PUT /api/v1/courses/:course_id/assignments/:assignment_id /submissions/:user_id submission: { posted_grade: 5 }, checkpoint_label: "reply_to_topic" The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 5 ``` Change-Id: I09d141af0278d5a5d3134f458cc698e0fec60db2 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/330375 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Reviewed-by: Jason Gillett <jason.gillett@instructure.com>
2023-10-14 03:17:48 +08:00
class SubAssignment < AbstractAssignment
validates :parent_assignment_id, presence: true, comparison: { other_than: :id, message: -> { I18n.t("cannot reference self") }, allow_blank: true }
validates :has_sub_assignments, inclusion: { in: [false], message: -> { I18n.t("cannot be true for sub assignments") } }
validates :sub_assignment_tag, inclusion: { in: [CheckpointLabels::REPLY_TO_TOPIC, CheckpointLabels::REPLY_TO_ENTRY] }
after_commit :aggregate_checkpoint_assignments, if: :checkpoint_changes?
make grading endpoints support checkpoint discussions closes VICE-3836 flag=discussion_checkpoints Test Plan: 1. Enable the "discussion_checkpoints" root account feature flag. 2. Create a graded discussion 3. In a rails console, create two checkpoints for the discussion: ``` discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_TOPIC, due_at: 2.days.from_now ) discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_ENTRY, due_at: 3.days.from_now ) ``` 4. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: POST /courses/:course_id/gradebook/update_submission submission: { assignment_id: <the discussion topic's assignment_id>, user_id: <an assigned student's ID>, grade: 10, checkpoint_label: "reply_to_topic" } The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 10 ``` 5. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: PUT /api/v1/courses/:course_id/assignments/:assignment_id /submissions/:user_id submission: { posted_grade: 5 }, checkpoint_label: "reply_to_topic" The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 5 ``` Change-Id: I09d141af0278d5a5d3134f458cc698e0fec60db2 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/330375 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Reviewed-by: Jason Gillett <jason.gillett@instructure.com>
2023-10-14 03:17:48 +08:00
set_broadcast_policy do
# TODO: define broadcast policies for checkpoints
end
delegate :effective_group_category_id, to: :parent_assignment
aggregate checkpoint submissions' grade attrs closes VICE-3873 closes VICE-3875 flag=discussion_checkpoints Updates the following attributes on the "parent" submission when a checkpoint submission is updated: - grade - graded_at - graded_anonymously - grader_id - grade_matches_current_submission - published_grade - published_score - posted_at - score - submission_type - submitted_at - updated_at - workflow_state Some fields are aggregated across all checkpoint submissions (like score), whereas some fields have special rules (e.g. posted_at is only set on the parent if all checkpoint submissions have a posted_at). Test Plan: - For score and published_score, ensure that grading a checkpoint stores the aggregate value on the parent submission - For grade and published_grade, ensure that grading a checkpoint sets the value to be the grade interpretation of the score/published_score. For instance, if a checkpointed discussion displays the grade as Letter Grade and the two checkpoints are worth 5 points each, grading each checkpoint with a grade of 5 should result in an "A" being stored on the parent submission. - For grader_id, graded_at, and graded_anonymously, ensure that the value on the parent submission matches the value on the most-recently-graded checkpoint - For grade_matches_current_submission, ensure that the value on the parent is: - true if the student has submitted for at least one checkpoint and has not been graded on any checkpoints - false if there's any checkpoint where the student submitted after they were graded - true if the student was graded on both checkpoints after submitting - For posted_at, ensure that the value is: - nil if both checkpoints have not been posted to - the most recent posted_at of the checkpoints, if they have both been posted to - For submission_type, ensure the value is: - the same as the checkpoints' submission_type values, if they match - nil otherwise - For submitted_at, ensure the value is: - the most recent checkpoint submitted_at when both checkpoints are submitted - nil otherwise - For updated_at, ensure that the value is equal to the most recent updated_at of the checkpoint submissions - For workflow_state, ensure that the value is: - the same as the checkpoints' workflow_state values, if they match - 'unsubmitted' otherwise Change-Id: I8e5fe14d2c9e0cdedccab0e9867bad22613a4753 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/330497 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Omar Soto-Fortuño <omar.soto@instructure.com> Reviewed-by: Aaron Suggs <aaron.suggs@instructure.com> Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com>
2023-10-17 05:50:28 +08:00
def checkpoint?
true
make grading endpoints support checkpoint discussions closes VICE-3836 flag=discussion_checkpoints Test Plan: 1. Enable the "discussion_checkpoints" root account feature flag. 2. Create a graded discussion 3. In a rails console, create two checkpoints for the discussion: ``` discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_TOPIC, due_at: 2.days.from_now ) discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_ENTRY, due_at: 3.days.from_now ) ``` 4. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: POST /courses/:course_id/gradebook/update_submission submission: { assignment_id: <the discussion topic's assignment_id>, user_id: <an assigned student's ID>, grade: 10, checkpoint_label: "reply_to_topic" } The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 10 ``` 5. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: PUT /api/v1/courses/:course_id/assignments/:assignment_id /submissions/:user_id submission: { posted_grade: 5 }, checkpoint_label: "reply_to_topic" The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 5 ``` Change-Id: I09d141af0278d5a5d3134f458cc698e0fec60db2 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/330375 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Reviewed-by: Jason Gillett <jason.gillett@instructure.com>
2023-10-14 03:17:48 +08:00
end
private
def aggregate_checkpoint_assignments
Checkpoints::AssignmentAggregatorService.call(assignment: parent_assignment)
end
def checkpoint_changes?
!!root_account&.feature_enabled?(:discussion_checkpoints) && checkpoint_attributes_changed?
end
def checkpoint_attributes_changed?
tracked_attributes = Checkpoints::AssignmentAggregatorService::AggregateAssignment.members.map(&:to_s) - ["updated_at"]
relevant_changes = tracked_attributes & previous_changes.keys
relevant_changes.any?
end
def governs_submittable?
false
end
make grading endpoints support checkpoint discussions closes VICE-3836 flag=discussion_checkpoints Test Plan: 1. Enable the "discussion_checkpoints" root account feature flag. 2. Create a graded discussion 3. In a rails console, create two checkpoints for the discussion: ``` discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_TOPIC, due_at: 2.days.from_now ) discussion_topic.assignment.checkpoint_assignments.create!( context: discussion_topic.course, checkpoint_label: CheckpointLabels::REPLY_TO_ENTRY, due_at: 3.days.from_now ) ``` 4. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: POST /courses/:course_id/gradebook/update_submission submission: { assignment_id: <the discussion topic's assignment_id>, user_id: <an assigned student's ID>, grade: 10, checkpoint_label: "reply_to_topic" } The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 10 ``` 5. As a teacher, verify you can grade an assigned student for the "reply to topic" checkpoint with the following request: PUT /api/v1/courses/:course_id/assignments/:assignment_id /submissions/:user_id submission: { posted_grade: 5 }, checkpoint_label: "reply_to_topic" The student's submission for the "reply to topic" assignment should be graded: ``` a = discussion_topic.reply_to_topic_assignment a.submissions.find_by(user: <the student's ID>).score # should be 5 ``` Change-Id: I09d141af0278d5a5d3134f458cc698e0fec60db2 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/330375 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com> Reviewed-by: Jason Gillett <jason.gillett@instructure.com>
2023-10-14 03:17:48 +08:00
end