allow special account ids for contexts
test plan: * access /accounts/self, /accounts/default, and /accounts/site_admin Change-Id: I655c6575d72e9199414515afd03c087cbf9fd8b1 Reviewed-on: https://gerrit.instructure.com/8043 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
parent
7dac720e62
commit
bacc7a192f
|
@ -130,7 +130,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
# retrieves the root account for the given domain
|
||||
def load_account
|
||||
@domain_root_account = request.env['canvas.domain_root_account'] || Account.default
|
||||
@domain_root_account = request.env['canvas.domain_root_account'] || LoadAccount.default_domain_root_account
|
||||
@files_domain = request.host_with_port != HostUrl.context_host(@domain_root_account) && HostUrl.is_file_host?(request.host_with_port)
|
||||
# we can't block frames on the files domain, since files domain requests
|
||||
# are typically embedded in an iframe in canvas, but the hostname is
|
||||
|
@ -296,9 +296,18 @@ class ApplicationController < ActionController::Base
|
|||
@context_enrollment = @context.enrollments.find_all_by_user_id(@current_user.id).sort_by{|e| [e.state_sortable, e.rank_sortable] }.first if @context && @current_user
|
||||
@context_membership = @context_enrollment
|
||||
elsif params[:account_id] || (self.is_a?(AccountsController) && params[:account_id] = params[:id])
|
||||
case params[:account_id]
|
||||
when 'self'
|
||||
@context = @domain_root_account
|
||||
when 'default'
|
||||
@context = Account.default
|
||||
when 'site_admin'
|
||||
@context = Account.site_admin
|
||||
else
|
||||
@context = api_request? ?
|
||||
api_find(Account, params[:account_id]) : Account.find(params[:account_id])
|
||||
params[:context_id] = params[:account_id]
|
||||
end
|
||||
params[:context_id] = @context.id
|
||||
params[:context_type] = "Account"
|
||||
@context_enrollment = @context.account_users.find_by_user_id(@current_user.id) if @context && @current_user
|
||||
@context_membership = @context_enrollment
|
||||
|
|
|
@ -240,6 +240,29 @@ describe AccountsController do
|
|||
assigns[:associated_courses_count].should == 1
|
||||
end
|
||||
|
||||
context "special account ids" do
|
||||
before do
|
||||
account_with_admin_logged_in(:account => Account.site_admin)
|
||||
@account = Account.create!
|
||||
LoadAccount.stubs(:default_domain_root_account).returns(@account)
|
||||
end
|
||||
|
||||
it "should allow self" do
|
||||
get 'show', :id => 'self', :format => 'html'
|
||||
assigns[:account].should == @account
|
||||
end
|
||||
|
||||
it "should allow default" do
|
||||
get 'show', :id => 'default', :format => 'html'
|
||||
assigns[:account].should == Account.default
|
||||
end
|
||||
|
||||
it "should allow site_admin" do
|
||||
get 'show', :id => 'site_admin', :format => 'html'
|
||||
assigns[:account].should == Account.site_admin
|
||||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
it "should allow admins to set the sis_source_id on sub accounts" do
|
||||
account_with_admin_logged_in
|
||||
|
|
Loading…
Reference in New Issue