[PATCH conductor 3/3] Adds XML format for Provider Accounts API - update
pblaho at redhat.com
pblaho at redhat.com
Wed Aug 15 23:30:40 UTC 2012
From: Petr Blaho <pblaho at redhat.com>
https://www.aeolusproject.org/redmine/issues/3692
Adds block for XML format.
Adds handling of credentials param
Adds route to create action
---
.../controllers/provider_accounts_controller.rb | 40 +++++++++++++-------
src/config/routes.rb | 2 +-
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/src/app/controllers/provider_accounts_controller.rb b/src/app/controllers/provider_accounts_controller.rb
index f845346..b73e57f 100644
--- a/src/app/controllers/provider_accounts_controller.rb
+++ b/src/app/controllers/provider_accounts_controller.rb
@@ -87,14 +87,7 @@ class ProviderAccountsController < ApplicationController
require_privilege(Privilege::CREATE, ProviderAccount, @provider)
params[:provider_account][:provider_id] = @provider.id
@providers = Provider.all
- credentials_hash = if params[:provider_account][:credentials]
- params[:provider_account].delete( :credentials )
- elsif params[:provider_account][:credentials_hash]
- params[:provider_account].delete( :credentials_hash )
- else
- nil
- end
-
+ credentials_hash = credentials_hash_prepare
@provider_account = ProviderAccount.new(params[:provider_account])
@provider_account.credentials_hash = credentials_hash
@provider_account.quota = @quota = Quota.new
@@ -150,18 +143,27 @@ class ProviderAccountsController < ApplicationController
require_privilege(Privilege::MODIFY, at provider_account)
@quota = @provider_account.quota
@providers = Provider.find(:all)
-
limit = params[:quota][:maximum_running_instances] if params[:quota]
@provider_account.quota.set_maximum_running_instances(limit)
- credentials_hash = params[:provider_account].delete(:credentials_hash)
+ credentials_hash = credentials_hash_prepare
@provider_account.attributes = params[:provider_account]
@provider_account.credentials_hash= credentials_hash
if @provider_account.save
- flash[:notice] = t"provider_accounts.flash.notice.updated"
- redirect_to edit_provider_path(@provider, :details_tab => 'accounts')
+ respond_to do |format|
+ format.html do
+ flash[:notice] = t"provider_accounts.flash.notice.updated"
+ redirect_to edit_provider_path(@provider, :details_tab => 'accounts')
+ end
+ format.xml { render 'show', :locals => { :provider_account => @provider_account, :with_credentials => true, :with_quota => true }, :status => :ok }
+ end
else
- flash[:error] = t"provider_accounts.flash.error.not_updated"
- render :action => :edit
+ respond_to do |format|
+ format.html do
+ flash[:error] = t"provider_accounts.flash.error.not_updated"
+ render :action => :edit
+ end
+ format.xml { render 'api/validation_error', :locals => { :errors => @provider_account.errors }, :status => :bad_request }
+ end
end
end
@@ -266,4 +268,14 @@ class ProviderAccountsController < ApplicationController
list_for_user(current_session, current_user, Privilege::VIEW)
@provider_accounts = @provider_accounts.where(:provider_id => @provider.id) if @provider
end
+
+ def credentials_hash_prepare
+ if params[:provider_account][:credentials]
+ params[:provider_account].delete( :credentials )
+ elsif params[:provider_account][:credentials_hash]
+ params[:provider_account].delete( :credentials_hash )
+ else
+ nil
+ end
+ end
end
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 6fc18ab..7d7704e 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -292,7 +292,7 @@ Conductor::Application.routes.draw do
resources :providers, :only => [:index, :show, :create, :update, :destroy] do
resources :provider_accounts, :only => [:index, :create]
end
- resources :provider_accounts, :only => [:index, :show, :destroy]
+ resources :provider_accounts, :only => [:index, :show, :update, :destroy]
resources :provider_types, :only => [:index, :show]
resources :hardware_profiles, :only => [:index, :show, :destroy, :create]
resources :pools, :only => [:index, :show, :create, :update, :destroy]
--
1.7.7.6
More information about the aeolus-devel
mailing list