canvas-lms/app/models/assessment_request.rb

148 lines
4.8 KiB
Ruby
Raw Normal View History

2011-02-01 09:57:29 +08:00
#
# Copyright (C) 2011 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/>.
#
class AssessmentRequest < ActiveRecord::Base
include Workflow
include SendToStream
2011-02-01 09:57:29 +08:00
attr_accessible :rubric_assessment, :user, :asset, :assessor_asset, :comments, :rubric_association, :assessor
EXPORTABLE_ATTRIBUTES = [
:id, :rubric_assessment_id, :user_id, :asset_id, :asset_type, :assessor_asset_id, :assessor_asset_type,
:comments, :workflow_state, :created_at, :updated_at, :uuid, :rubric_association_id, :assessor_id
]
EXPORTABLE_ASSOCIATIONS = [:user, :asset, :assessor_asset, :submission, :submission_comments, :rubric_assessment]
2011-02-01 09:57:29 +08:00
belongs_to :user
belongs_to :asset, :polymorphic => true
validates_inclusion_of :asset_type, :allow_nil => true, :in => ['Submission']
2011-02-01 09:57:29 +08:00
belongs_to :assessor_asset, :polymorphic => true
validates_inclusion_of :assessor_asset_type, :allow_nil => true, :in => ['Submission', 'User']
2011-02-01 09:57:29 +08:00
belongs_to :assessor, :class_name => 'User'
belongs_to :submission, :foreign_key => 'asset_id'
belongs_to :rubric_association
has_many :submission_comments
has_many :ignores, as: :asset
2011-02-01 09:57:29 +08:00
belongs_to :rubric_assessment
validates_presence_of :user_id, :asset_id, :asset_type, :workflow_state
2011-02-01 09:57:29 +08:00
validates_length_of :comments, :maximum => maximum_text_length, :allow_nil => true, :allow_blank => true
2011-02-01 09:57:29 +08:00
before_save :infer_uuid
has_a_broadcast_policy
2011-02-01 09:57:29 +08:00
def infer_uuid
self.uuid ||= CanvasSlug.generate_securish_uuid
2011-02-01 09:57:29 +08:00
end
protected :infer_uuid
2011-02-01 09:57:29 +08:00
set_broadcast_policy do |p|
p.dispatch :rubric_assessment_submission_reminder
2013-12-06 20:11:38 +08:00
p.to { self.assessor }
p.whenever { |record|
record.assigned? && @send_reminder && rubric_association
}
p.dispatch :peer_review_invitation
p.to { self.assessor }
p.whenever { |record|
record.assigned? && @send_reminder && !rubric_association
2011-02-01 09:57:29 +08:00
}
end
scope :incomplete, where(:workflow_state => 'assigned')
scope :for_assessee, lambda { |user_id| where(:user_id => user_id) }
peer reviews api refs: PFS-2071, PFS-2072, PFS-2073, PFS-2074 **Test Plan PFS-2071 1. Create course with assignment, teacher and two students 2. setup peer reviews on assignment 3. As student 1 create a submission 4. As student 2 peer review submission, leave comments 5. execute the following api courses/:course_id/assignments/:assignment_id/peer_reviews 6. As account admin all information should be shown 7. As teacher all information should be shown 8. As student should see all information 9. Repeat above but set anonymous peer reviews on assignment 10. As account admin all information should be shown 11. As teacher all information should be shown 12. As student should see comments but all reviewer information should not be shown 13. include the following include parameters, include[]=submission_comments, include[]=user make sure additional information is shown according to parameter. PFS-2072 1. Follow setup from PFS-2071 2. execute a get on the following api /api/v1/courses/:course_id/assignments/:assignment_id/submissions/:submission_id/peer_reviews 3. validate that only peer reviews for the given submission are shown PFS-2073 1. Follow setup from PFS-2071 2. execute a post on the following api, including a user_id parameter /api/v1/courses/:course_id/assignments/:assignment1_id/submissions/:submission_id/peer_reviews 3. validate that user from user_id parameter is added as a reviwer on the submission PFS-2074 1. follow setup from PFS-2071 2. execute a delete on the following api, including a user_id parameter /api/v1/courses/:course_id/assignments/:assignment1_id/submissions/:submission_id/peer_reviews 3. validate that user from user_id parameter is removed as a reviewer on the submission (cherry picked from commit 91744bbcd5a81be968139b1f68b65c3e9eaa7b4a) Change-Id: Ic09a16956cddb2f113625ff61bc733503d713abb Reviewed-on: https://gerrit.instructure.com/56936 Tested-by: Jenkins QA-Review: Adam Stone <astone@instructure.com> Reviewed-by: John Corrigan <jcorrigan@instructure.com> Product-Review: Brandon Broschinsky <brandonbr@instructure.com>
2015-06-18 00:34:45 +08:00
scope :for_assessor, lambda { |assessor_id| where(:assessor_id => assessor_id) }
scope :for_asset, lambda { |asset_id| where(:asset_id => asset_id)}
scope :for_assignment, lambda { |assignment_id| eager_load(:submission).where(:submissions => { :assignment_id => assignment_id})}
scope :for_course, lambda { |course_id| eager_load(:submission).where(:submissions => { :context_code => "course_#{course_id}"})}
scope :for_context_codes, lambda { |context_codes| eager_load(:submission).where(:submissions => { :context_code =>context_codes })}
scope :not_ignored_by, lambda { |user, purpose|
where("NOT EXISTS (?)",
Ignore.where("asset_id=assessment_requests.id").
where(asset_type: 'AssessmentRequest', user_id: user, purpose: purpose))
}
2011-02-01 09:57:29 +08:00
set_policy do
given {|user, session|
self.can_read_assessment_user_name?(user, session)
}
can :read_assessment_user
end
def can_read_assessment_user_name?(user, session)
!self.considered_anonymous? ||
self.user_id == user.id ||
self.submission.assignment.context.grants_right?(user, session, :view_all_grades)
end
def considered_anonymous?
self.submission.assignment.anonymous_peer_reviews?
end
2011-02-01 09:57:29 +08:00
def send_reminder!
@send_reminder = true
self.updated_at = Time.now
self.save!
ensure
2011-02-01 09:57:29 +08:00
@send_reminder = nil
end
def context
submission.try(:context)
end
2011-02-01 09:57:29 +08:00
def assessor_name
self.rubric_assessment.assessor_name rescue ((self.assessor.name rescue nil) || t("#unknown", "Unknown"))
2011-02-01 09:57:29 +08:00
end
on_create_send_to_streams do
self.assessor
end
on_update_send_to_streams do
self.assessor
end
2011-02-01 09:57:29 +08:00
workflow do
state :assigned do
event :complete, :transitions_to => :completed
end
2011-02-01 09:57:29 +08:00
# assessment request now has rubric_assessment
state :completed
end
2011-02-01 09:57:29 +08:00
def asset_title
(self.asset.assignment.title rescue self.asset.title) rescue t("#unknown", "Unknown")
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def comment_added(comment)
self.workflow_state = "completed" unless self.rubric_association && self.rubric_association.rubric
end
2011-02-01 09:57:29 +08:00
def asset_user_name
self.asset.user.name rescue t("#unknown", "Unknown")
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def asset_context_name
(self.asset.context.name rescue self.asset.assignment.context.name) rescue t("#unknown", "Unknown")
2011-02-01 09:57:29 +08:00
end
2011-02-01 09:57:29 +08:00
def self.serialization_excludes; [:uuid]; end
end