Revision 9f68d4d9
Added by Ondřej Pražák over 7 years ago
app/controllers/concerns/foreman/controller/taxonomies_controller.rb | ||
---|---|---|
assign_selected_hosts assign_all_hosts step2 select
|
||
parent_taxonomy_selected}
|
||
before_action :count_nil_hosts, :only => %w{index create step2}
|
||
before_action :new_taxonomy, :only => %w{create}
|
||
skip_before_action :authorize, :set_taxonomy, :only => %w{select clear}
|
||
end
|
||
|
||
... | ... | |
end
|
||
|
||
def create
|
||
@taxonomy = taxonomy_class.new(resource_params)
|
||
if @taxonomy.save
|
||
switch_taxonomy
|
||
if @count_nil_hosts > 0
|
||
redirect_to send("step2_#{taxonomy_single}_path",@taxonomy)
|
||
else
|
||
... | ... | |
end
|
||
|
||
def select
|
||
taxonomy_class.current = @taxonomy
|
||
session[taxonomy_id] = @taxonomy ? @taxonomy.id : nil
|
||
|
||
TopbarSweeper.expire_cache(self)
|
||
switch_taxonomy
|
||
redirect_back_or_to root_url
|
||
end
|
||
|
||
... | ... | |
def resource_params
|
||
public_send("#{taxonomy_single}_params".to_sym)
|
||
end
|
||
|
||
def new_taxonomy
|
||
@taxonomy = taxonomy_class.new(resource_params)
|
||
end
|
||
|
||
def switch_taxonomy
|
||
taxonomy_class.current = @taxonomy
|
||
session[taxonomy_id] = @taxonomy ? @taxonomy.id : nil
|
||
|
||
TopbarSweeper.expire_cache(self)
|
||
end
|
||
end
|
test/controllers/organizations_controller_test.rb | ||
---|---|---|
Host.unstub(:authorized)
|
||
end
|
||
end
|
||
|
||
test 'should switch to newly created org' do
|
||
name = 'test-org'
|
||
put :create, { :commit => "Submit", :organization => { :name => name } }, set_session_user
|
||
new_org = Organization.find_by :name => name
|
||
assert_equal new_org.id, session[:organization_id]
|
||
end
|
||
end
|
Also available in: Unified diff
Fixes #17681 - Switch to newly created taxonomy