allow creating section with only integration_id

fixes CORE-1139


test plan
 - create a section in the api with integration_id
 - it should work even if sis id is not present

Change-Id: I5c5d8a752d2bc69a2629b2c9047ee748088385d8
Reviewed-on: https://gerrit.instructure.com/146256
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Tucker McKnight <tmcknight@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2018-04-07 15:17:33 -06:00
parent 83acfd961e
commit 0c8c01e9c1
2 changed files with 11 additions and 3 deletions

View File

@ -152,10 +152,9 @@ class SectionsController < ApplicationController
if authorized_action(@context.course_sections.temp_record, @current_user, :create)
sis_section_id = params[:course_section].try(:delete, :sis_section_id)
integration_id = params[:course_section].try(:delete, :integration_id)
can_manage_sis = api_request? && sis_section_id.present? &&
@context.root_account.grants_right?(@current_user, session, :manage_sis)
can_manage_sis = api_request? && @context.root_account.grants_right?(@current_user, session, :manage_sis)
if can_manage_sis && value_to_boolean(params[:enable_sis_reactivation])
if can_manage_sis && sis_section_id.present? && value_to_boolean(params[:enable_sis_reactivation])
@section = @context.course_sections.where(:sis_source_id => sis_section_id, :workflow_state => 'deleted').first
@section.workflow_state = 'active' if @section
end

View File

@ -385,6 +385,15 @@ describe SectionsController, type: :request do
expect(section.sis_batch_id).to eq nil
end
it "should set the integration_id by itself" do
section_params = {name: 'Name', integration_id: 'int1'}
json = api_call(:post, @path_prefix, @path_params, {course_section: section_params})
@course.reload
section = @course.active_course_sections.find(json['id'].to_i)
expect(section.name).to eq 'Name'
expect(section.integration_id).to eq 'int1'
end
it "should allow reactivating deleting sections using sis_section_id" do
old_section = @course.course_sections.create!
old_section.sis_source_id = 'fail'