add integration_data, integration_id for assignment through api
Test Plan: see SIS-281 fixes SIS-281 Change-Id: I25b7d18a7cd752826ff38d0f795cba0059b56df1 Reviewed-on: https://gerrit.instructure.com/35071 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: Eric Adams <eadams@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com>
This commit is contained in:
parent
48aeb982b3
commit
e6db8e37e1
|
@ -312,6 +312,16 @@
|
|||
# "type" : "boolean",
|
||||
# "description" : "(optional, present if Post Grades to SIS feature is enabled)"
|
||||
# },
|
||||
# "integration_id": {
|
||||
# "example": "12341234",
|
||||
# "type" : "string",
|
||||
# "description" : "(optional, Third Party unique identifier for Assignment)"
|
||||
# },
|
||||
# "integration_data": {
|
||||
# "example": "12341234",
|
||||
# "type" : "string",
|
||||
# "description" : "(optional, Third Party integration data for assignment)"
|
||||
# },
|
||||
# "muted": {
|
||||
# "description": "whether the assignment is muted",
|
||||
# "type": "boolean"
|
||||
|
@ -576,6 +586,12 @@ class AssignmentsApiController < ApplicationController
|
|||
# Toggles Turnitin submissions for the assignment.
|
||||
# Will be ignored if Turnitin is not available for the course.
|
||||
#
|
||||
# @argument assignment[integration_data] [Optional]
|
||||
# Data related to third party integrations, JSON string required.
|
||||
#
|
||||
# @argument assignment[integration_id] [Optional]
|
||||
# Unique ID from third party integrations
|
||||
#
|
||||
# @argument assignment[turnitin_settings] [Optional]
|
||||
# Settings to send along to turnitin. See Assignment object definition for
|
||||
# format.
|
||||
|
@ -818,7 +834,7 @@ class AssignmentsApiController < ApplicationController
|
|||
|
||||
def save_and_render_response
|
||||
@assignment.content_being_saved_by(@current_user)
|
||||
if update_api_assignment(@assignment, params[:assignment])
|
||||
if update_api_assignment(@assignment, params[:assignment], @current_user)
|
||||
render :json => assignment_json(@assignment, @current_user, session), :status => 201
|
||||
else
|
||||
errors = @assignment.errors.as_json[:errors]
|
||||
|
|
|
@ -857,7 +857,7 @@ class DiscussionTopicsController < ApplicationController
|
|||
elsif (@assignment = @topic.assignment || @topic.restore_old_assignment || (@topic.assignment = @context.assignments.build)) &&
|
||||
@assignment.grants_right?(@current_user, session, :update)
|
||||
params[:assignment][:group_category_id] = nil unless @topic.group_category_id || @assignment.has_submitted_submissions?
|
||||
update_api_assignment(@assignment, params[:assignment].merge(@topic.attributes.slice('title')))
|
||||
update_api_assignment(@assignment, params[:assignment].merge(@topic.attributes.slice('title')), @current_user)
|
||||
@assignment.submission_types = 'discussion_topic'
|
||||
@assignment.saved_by = :discussion_topic
|
||||
@topic.assignment = @assignment
|
||||
|
|
|
@ -38,14 +38,14 @@ class Assignment < ActiveRecord::Base
|
|||
:notify_of_update, :time_zone_edited, :turnitin_enabled,
|
||||
:turnitin_settings, :context, :position, :allowed_extensions,
|
||||
:external_tool_tag_attributes, :freeze_on_copy, :assignment_group_id,
|
||||
:only_visible_to_overrides, :post_to_sis
|
||||
:only_visible_to_overrides, :post_to_sis, :integration_id, :integration_data
|
||||
|
||||
EXPORTABLE_ATTRIBUTES = [
|
||||
:id, :title, :description, :due_at, :unlock_at, :lock_at, :points_possible, :min_score, :max_score, :mastery_score, :grading_type,
|
||||
:submission_types, :workflow_state, :context_id, :context_type, :assignment_group_id, :grading_scheme_id, :grading_standard_id, :location, :created_at,
|
||||
:updated_at, :group_category, :submissions_downloads, :peer_review_count, :peer_reviews_due_at, :peer_reviews_assigned, :peer_reviews, :automatic_peer_reviews,
|
||||
:all_day, :all_day_date, :could_be_locked, :cloned_item_id, :context_code, :position, :grade_group_students_individually, :anonymous_peer_reviews, :time_zone_edited,
|
||||
:turnitin_enabled, :allowed_extensions, :needs_grading_count, :turnitin_settings, :muted, :group_category_id, :freeze_on_copy, :copied, :only_visible_to_overrides
|
||||
:turnitin_enabled, :allowed_extensions, :needs_grading_count, :turnitin_settings, :muted, :group_category_id, :freeze_on_copy, :copied, :only_visible_to_overrides, :integration_id, :integration_data
|
||||
]
|
||||
|
||||
EXPORTABLE_ASSOCIATIONS = [
|
||||
|
@ -154,6 +154,7 @@ class Assignment < ActiveRecord::Base
|
|||
updated_at
|
||||
post_to_sis
|
||||
integration_data
|
||||
integration_id
|
||||
)
|
||||
|
||||
def external_tool?
|
||||
|
|
|
@ -33,7 +33,6 @@ module Api::V1::Assignment
|
|||
lock_at
|
||||
unlock_at
|
||||
assignment_group_id
|
||||
integration_id
|
||||
peer_reviews
|
||||
automatic_peer_reviews
|
||||
post_to_sis
|
||||
|
@ -70,7 +69,6 @@ module Api::V1::Assignment
|
|||
hash = api_json(assignment, user, session, fields)
|
||||
hash['course_id'] = assignment.context_id
|
||||
hash['name'] = assignment.title
|
||||
|
||||
hash['post_to_sis'] = assignment.post_to_sis
|
||||
hash['submission_types'] = assignment.submission_types_array
|
||||
hash['has_submitted_submissions'] = assignment.has_submitted_submissions?
|
||||
|
@ -118,6 +116,11 @@ module Api::V1::Assignment
|
|||
hash['needs_grading_count'] = assignment.needs_grading_count_for_user user
|
||||
end
|
||||
|
||||
if assignment.context.grants_rights?(user, :read_sis, :manage_sis).values.any?
|
||||
hash['integration_id'] = assignment.integration_id
|
||||
hash['integration_data'] = assignment.integration_data
|
||||
end
|
||||
|
||||
if assignment.quiz
|
||||
hash['quiz_id'] = assignment.quiz.id
|
||||
hash['anonymous_submissions'] = !!(assignment.quiz.anonymous_submissions)
|
||||
|
@ -240,6 +243,8 @@ module Api::V1::Assignment
|
|||
grading_standard_id
|
||||
freeze_on_copy
|
||||
notify_of_update
|
||||
integration_id
|
||||
integration_data
|
||||
)
|
||||
|
||||
API_ALLOWED_TURNITIN_SETTINGS = %w(
|
||||
|
@ -253,7 +258,7 @@ module Api::V1::Assignment
|
|||
exclude_small_matches_value
|
||||
)
|
||||
|
||||
def update_api_assignment(assignment, assignment_params)
|
||||
def update_api_assignment(assignment, assignment_params, user)
|
||||
return nil unless assignment_params.is_a?(Hash)
|
||||
|
||||
old_assignment = assignment.new_record? ? nil : assignment.clone
|
||||
|
@ -267,7 +272,7 @@ module Api::V1::Assignment
|
|||
return false unless valid_assignment_group_id?(assignment, assignment_params)
|
||||
return false unless valid_assignment_dates?(assignment, assignment_params)
|
||||
|
||||
assignment = update_from_params(assignment, assignment_params)
|
||||
assignment = update_from_params(assignment, assignment_params, user)
|
||||
|
||||
if overrides
|
||||
assignment.transaction do
|
||||
|
@ -309,7 +314,7 @@ module Api::V1::Assignment
|
|||
end
|
||||
end
|
||||
|
||||
def update_from_params(assignment, assignment_params)
|
||||
def update_from_params(assignment, assignment_params, user)
|
||||
update_params = assignment_params.slice(*API_ALLOWED_ASSIGNMENT_INPUT_FIELDS)
|
||||
|
||||
if update_params.has_key?('peer_reviews_assign_at')
|
||||
|
@ -349,6 +354,15 @@ module Api::V1::Assignment
|
|||
assignment.muted = value_to_boolean(assignment_params.delete("muted"))
|
||||
end
|
||||
|
||||
if assignment.context.grants_right?(user, :manage_sis)
|
||||
if update_params['integration_data']
|
||||
update_params['integration_data'] = JSON.parse(update_params['integration_data'])
|
||||
end
|
||||
else
|
||||
update_params.delete('integration_id')
|
||||
update_params.delete('integration_data')
|
||||
end
|
||||
|
||||
# do some fiddling with due_at for fancy midnight and add to update_params
|
||||
if update_params['due_at'].present? && update_params['due_at'] =~ Api::ISO8601_REGEX
|
||||
update_params['time_zone_edited'] = Time.zone.name
|
||||
|
@ -396,7 +410,7 @@ module Api::V1::Assignment
|
|||
assignment.post_to_sis = value_to_boolean(assignment_params['post_to_sis'])
|
||||
end
|
||||
end
|
||||
assignment.updating_user = @current_user
|
||||
assignment.updating_user = user
|
||||
assignment.attributes = update_params
|
||||
assignment.infer_times
|
||||
|
||||
|
|
|
@ -1720,6 +1720,30 @@ describe AssignmentsApiController, type: :request do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "update_from_params" do
|
||||
before do
|
||||
course_with_teacher(:active_all => true)
|
||||
@assignment = @course.assignments.create!(:title => "some assignment")
|
||||
end
|
||||
|
||||
it "does not update integration_data when lacking permission" do
|
||||
json = %{{"key": "value"}}
|
||||
params = {"integration_data" => json}
|
||||
|
||||
update_from_params(@assignment, params, @user)
|
||||
@assignment.integration_data.should == nil
|
||||
end
|
||||
|
||||
it "updates integration_data with permission" do
|
||||
json = %{{"key": "value"}}
|
||||
params = {"integration_data" => json}
|
||||
account_admin_user_with_role_changes(
|
||||
:role_changes => {:manage_sis => true})
|
||||
update_from_params(@assignment, params, @admin)
|
||||
@assignment.integration_data.should == {"key" => "value"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def api_get_assignments_index_from_course(course)
|
||||
|
|
Loading…
Reference in New Issue