Allow group category sis ids to be changed

fixes CORE-913

test plan:
- Generate documentation, make sure that the
  change_sis_id.csv parts about group_categories
  make sense.
- Upload a change_sis_id.csv and make sure you
  can change the SIS ID on a group category.

Change-Id: Id3e5813dd1cee371784d43cd9ba9dce90ef9fcd4
Reviewed-on: https://gerrit.instructure.com/139534
Reviewed-by: Rob Orton <rob@instructure.com>
Tested-by: Jenkins
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Tucker McKnight 2018-01-30 11:27:01 -07:00
parent ce9d55989c
commit 48e0221073
4 changed files with 54 additions and 7 deletions

View File

@ -1118,7 +1118,8 @@ object type and the root_account.</td>
<td>text</td>
<td>&#42;</td>
<td></td>
<td>The current integration_id of the object that should be changed.</td>
<td>The current integration_id of the object that should be changed. This
column is not supported for group categories.</td>
</tr>
<tr>
<td>new_integration_id</td>
@ -1126,15 +1127,16 @@ object type and the root_account.</td>
<td>&#42;</td>
<td></td>
<td>The desired integration_id of the object. This id must be currently unique
to the object type and the root_account. Can pass "&lt;delete>" to
remove the integration_id from the object.</td>
to the object type and the root_account. This column is not supported for group
categories. Can pass "&lt;delete>" to remove the integration_id from the
object.</td>
</tr>
<tr>
<td>type</td>
<td>text</td>
<td></td>
<td></td>
<td>account, term, course, section, group, user</td>
<td>account, term, course, section, group, group_category, user</td>
</tr>
</table>

View File

@ -32,7 +32,8 @@ module SIS
'section' => {scope: @root_account.course_sections},
'term' => {scope: @root_account.enrollment_terms},
'account' => {scope: @root_account.all_accounts},
'group' => {scope: @root_account.all_groups}
'group' => {scope: @root_account.all_groups},
'group_category' => {scope: @root_account.all_group_categories},
}
importer.things_to_update_batch_ids.each do |key, value|
@ -79,7 +80,8 @@ module SIS
'section' => {scope: @root_account.course_sections},
'term' => {scope: @root_account.enrollment_terms},
'account' => {scope: @root_account.all_accounts},
'group' => {scope: @root_account.all_groups}
'group' => {scope: @root_account.all_groups},
'group_category' => {scope: @root_account.all_group_categories},
}
details = types[type]
@ -108,6 +110,9 @@ module SIS
end
def check_for_conflicting_ids(column, details, type, data_change)
if type == 'group_category' && (data_change.old_integration_id || data_change.new_integration_id)
raise ImportError, "Group categories should not have integration IDs."
end
check_new = details[:scope].where(column => data_change.new_id).exists? if data_change.new_id.present?
raise ImportError, "A new_id, '#{data_change.new_id}', referenced an existing #{type} and the #{type} with #{column} '#{data_change.old_id}' was not updated" if check_new
check_int = details[:scope].where(integration_id: data_change.new_integration_id).exists? if data_change.new_integration_id.present?

View File

@ -16,7 +16,7 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
module Factories
VALID_GROUP_CATEGORY_ATTRIBUTES = [:name, :context, :group_limit]
VALID_GROUP_CATEGORY_ATTRIBUTES = [:name, :context, :group_limit, :sis_source_id]
def group_category(opts = {})
opts[:name] = opts[:name].present? ? opts[:name] : 'foo'

View File

@ -139,4 +139,44 @@ describe SIS::CSV::ChangeSisIdImporter do
expect(importer.errors).not_to be_nil
end
describe 'group categories' do
let!(:gc) {group_category(context: @account, sis_source_id: 'GC1')}
it 'should change the sis id for a group category' do
importer = process_csv_data(
'old_id,new_id,type',
'GC1,GC2,group_category'
)
expect(importer.errors).to be_empty
gc.reload
expect(gc.sis_source_id).to eq('GC2')
end
it 'should not error if other rows have an integration_id' do
u1 = user_with_managed_pseudonym(account: @account, sis_user_id: 'U001')
u1.pseudonym.integration_id = 'int1'
u1.pseudonym.save!
importer = process_csv_data(
'old_id,new_id,old_integration_id,new_integration_id,type',
',,int1,int2,user',
'GC1,GC2,,,group_category'
)
gc.reload
expect(gc.sis_source_id).to eq('GC2')
end
it 'should cleanly handle error if integration_id is given' do
u1 = user_with_managed_pseudonym(account: @account, sis_user_id: 'U001')
importer = process_csv_data(
'old_id,new_integration_id,new_id,type',
'GC1,INTID,group_category',
'U001,,U002,user'
)
expect(importer.errors).not_to be_empty
u1.reload
expect(u1.pseudonym.sis_user_id).to eq('U002')
end
end
end