fix creating user with no sis_user_id. fixes #6872

admin can now create user with no sis_user_id without receiving
an error about the sis id already existing.

also includes a migration to set all empty string sis_user_ids to
NULL.

test plan:
  * enable sis imports on an account;
  * as an admin in that account, create a new user, leaving the
    sis id blank;
  * create a second new user, also with a blank sis id;
  * verify that the second user is creating without any errors.

test plan:

Change-Id: Ia247c58e0070a4b02ecc584c18ed20bb5c05dcd3
Reviewed-on: https://gerrit.instructure.com/8665
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Zach Pendleton 2012-02-13 09:13:48 -07:00
parent 046cc263a1
commit 05cabac7b3
3 changed files with 19 additions and 0 deletions

View File

@ -133,6 +133,7 @@ class Pseudonym < ActiveRecord::Base
if !crypted_password || crypted_password == ""
self.generate_temporary_password
end
self.sis_user_id = nil if self.sis_user_id.blank?
end
def update_passwords_on_related_pseudonyms

View File

@ -0,0 +1,9 @@
class SetBlankSisUserIdsToNull < ActiveRecord::Migration
def self.up
Pseudonym.update_all({ :sis_user_id => nil }, :sis_user_id => '')
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -135,6 +135,15 @@ describe Pseudonym do
@pseudonym.should be_deleted
end
it "should change a blank sis_user_id to nil" do
user
pseudonym = Pseudonym.new(:user => @user, :unique_id => 'test@example.com', :password => 'pwd123')
pseudonym.password_confirmation = 'pwd123'
pseudonym.sis_user_id = ''
pseudonym.should be_valid
pseudonym.sis_user_id.should be_nil
end
it "should gracefully handle unreachable LDAP servers" do
require 'net/ldap'
module Net