Skip to content

Commit 9bb60e4

Browse files
committed
don't allow setting sis id on root accounts
testplan: try to set an sis id via the UI, a raw request, or the console Change-Id: I9749031729bf7d94070f4fd67c0a2f595ce337ed Reviewed-on: https://gerrit.instructure.com/7007 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com>
1 parent 8dc786c commit 9bb60e4

7 files changed

Lines changed: 36 additions & 12 deletions

File tree

app/controllers/accounts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def update
9898
end
9999
end
100100
if sis_id = params[:account].delete(:sis_source_id)
101-
if sis_id != @account.sis_source_id && (@account.root_account || @account).grants_right?(@current_user, session, :manage_sis)
101+
if !@account.root_account? && sis_id != @account.sis_source_id && (@account.root_account || @account).grants_right?(@current_user, session, :manage_sis)
102102
if sis_id == ''
103103
@account.sis_source_id = nil
104104
else

app/models/account.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,16 @@ def ensure_defaults
198198

199199
def verify_unique_sis_source_id
200200
return true unless self.sis_source_id
201-
root = self.root_account || self
202-
existing_account = Account.find_by_root_account_id_and_sis_source_id(root.id, self.sis_source_id)
203-
204201
if self.root_account?
205-
return true if !existing_account
206-
elsif root.sis_source_id != self.sis_source_id
207-
return true if !existing_account || existing_account.id == self.id
202+
self.errors.add(:sis_source_id, t('#account.root_account_cant_have_sis_id', "SIS IDs cannot be set on root accounts"))
203+
return false
208204
end
205+
206+
root = self.root_account
207+
existing_account = Account.find_by_root_account_id_and_sis_source_id(root.id, self.sis_source_id)
209208

209+
return true if !existing_account || existing_account.id == self.id
210+
210211
self.errors.add(:sis_source_id, t('#account.sis_id_in_use', "SIS ID \"%{sis_id}\" is already in use", :sis_id => self.sis_source_id))
211212
false
212213
end

app/views/accounts/settings.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<td><%= f.blabel :name, :en => "Account Name" %></td>
5454
<td><%= f.text_field :name %></td>
5555
</tr>
56-
<% if (@context.sis_source_id || can_do(@context.root_account || @context, @current_user, :manage_sis)) && !@account.site_admin? %>
56+
<% if !@account.root_account? && (@context.sis_source_id || can_do(@context.root_account || @context, @current_user, :manage_sis)) %>
5757
<tr>
5858
<td><%= f.blabel :sis_source_id, :en => "SIS ID" %></td>
5959
<td>

spec/apis/v1/accounts_api_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
user_with_pseudonym(:active_all => true)
2424
@a1 = account_model(:name => 'root')
2525
@a1.add_user(@user)
26-
@a2 = account_model(:name => 'subby', :parent_account => @a1, :sis_source_id => 'sis1')
26+
@a2 = account_model(:name => 'subby', :parent_account => @a1, :root_account => @a1, :sis_source_id => 'sis1')
2727
@a2.add_user(@user)
2828
@a3 = account_model(:name => 'no-access')
2929
# even if we have access to it implicitly, it's not listed
30-
@a4 = account_model(:name => 'implicit-access', :parent_account => @a1)
30+
@a4 = account_model(:name => 'implicit-access', :parent_account => @a1, :root_account => @a1)
3131
end
3232

3333
it "should return the account list" do
@@ -67,7 +67,7 @@
6767

6868
it "should find accounts by sis in only this root account" do
6969
Account.default.add_user(@user)
70-
other_sub = account_model(:name => 'other_sub', :parent_account => Account.default, :sis_source_id => 'sis1')
70+
other_sub = account_model(:name => 'other_sub', :parent_account => Account.default, :root_account => Account.default, :sis_source_id => 'sis1')
7171
other_sub.add_user(@user)
7272

7373
# this is scoped to Account.default

spec/controllers/accounts_controller_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,21 @@ def cross_listed_course
141141

142142
assigns[:associated_courses_count].should == 1
143143
end
144+
145+
describe "update" do
146+
it "should allow admins to set the sis_source_id on sub accounts" do
147+
account_with_admin_logged_in
148+
@account = @account.sub_accounts.create!
149+
post 'update', :id => @account.id, :account => { :sis_source_id => 'abc' }
150+
@account.reload
151+
@account.sis_source_id.should == 'abc'
152+
end
153+
154+
it "should not allow setting the sis_source_id on root accounts" do
155+
account_with_admin_logged_in
156+
post 'update', :id => @account.id, :account => { :sis_source_id => 'abc' }
157+
@account.reload
158+
@account.sis_source_id.should be_nil
159+
end
160+
end
144161
end

spec/models/account_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,12 @@ def account_with_admin_and_restricted_user(account)
597597
end
598598
end
599599

600+
it "should not allow setting an sis id for a root account" do
601+
@account = Account.create!
602+
@account.sis_source_id = 'abc'
603+
@account.save.should be_false
604+
end
605+
600606
describe "open_registration_for?" do
601607
it "should be true for anyone if open registration is turned on" do
602608
account = Account.default

spec/views/accounts/settings.html.erb_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
describe "accounts/settings.html.erb" do
2323
describe "sis_source_id edit box" do
2424
before do
25-
@account = Account.default
25+
@account = Account.default.sub_accounts.create!
2626
@account.sis_source_id = "so_special_sis_id"
2727
@account.save
2828

0 commit comments

Comments
 (0)