[PATCH conductor 4/4] Updates XML format for index of Provider Accounts

Petr Blaho pblaho at redhat.com
Fri Jun 29 13:35:08 UTC 2012


On Thursday, June 28, 2012 04:34:21 PM Richard Su wrote:
> On 06/27/2012 08:30 AM, pblaho at redhat.com wrote:
> > From: Petr Blaho<pblaho at redhat.com>
> >
> > https://www.aeolusproject.org/redmine/issues/3423
> >
> > Changes rendering for xml to render template instead of calling
> > serialization from model
> > Adds templates for list of Provider Accounts and credentials partial
> > Adds routes
> > Adds before filter to load parent Provider if provider_id exists
> > Adds provider_id scope for loading Provider Accounts in load_accounts
> > before filter
> > ---
> >   .../controllers/provider_accounts_controller.rb    |   10 ++++++++--
> >   .../views/provider_accounts/_credentials.xml.haml  |    3 +++
> >   src/app/views/provider_accounts/_list.xml.haml     |   12 ++++++++++++
> >   src/config/routes.rb                               |   10 ++++++----
> >   4 files changed, 29 insertions(+), 6 deletions(-)
> >   create mode 100644 src/app/views/provider_accounts/_credentials.xml.haml
> >   create mode 100644 src/app/views/provider_accounts/_list.xml.haml
> >
> > diff --git a/src/app/controllers/provider_accounts_controller.rb b/src/app/controllers/provider_accounts_controller.rb
> > index 157251a..ce0d2ab 100644
> > --- a/src/app/controllers/provider_accounts_controller.rb
> > +++ b/src/app/controllers/provider_accounts_controller.rb
> > @@ -16,17 +16,18 @@
> >
> >   class ProviderAccountsController<  ApplicationController
> >     before_filter :require_user
> > +  before_filter :load_provider, :only =>  [:index]
> >     before_filter :load_accounts, :only =>  [:index,:show]
> >
> >     def index
> >       clear_breadcrumbs
> >       save_breadcrumb(provider_accounts_path)
> > -    load_accounts
> >
> >       respond_to do |format|
> >         #xml list of provider_accounts for aeolus-image, aeolus-image could work with prov. accounts list for givent provider
> >         #to resemble html views logic, so this route could be removed (provider_accounts could be user only as nested resource)
> > -      format.xml { render :text =>  ProviderAccount.xml_export(@provider_accounts) }
> > +      #format.xml { render :text =>  ProviderAccount.xml_export(@provider_accounts) }
> > +      format.xml { render :partial =>  'list.xml', :locals =>  { :provider_accounts =>  @provider_accounts, :with_credentials =>  true } }
> >       end
> >     end
> >
> > @@ -213,11 +214,16 @@ class ProviderAccountsController<  ApplicationController
> >       flash.now[:error] = t"provider_accounts.flash.error.test_connection_failed_provider"
> >     end
> >
> > +  def load_provider
> > +    @provider = Provider.list_for_user(current_session, current_user, Privilege::VIEW).find(params[:provider_id]) if params[:provider_id]
> > +  end
> > +
> >     def load_accounts
> >       @provider_accounts = ProviderAccount.
> >         apply_filters(:preset_filter_id =>
> >                         params[:provider_accounts_preset_filter],
> >                       :search_filter =>  params[:provider_accounts_search]).
> >         list_for_user(current_session, current_user, Privilege::VIEW)
> > +    @provider_accounts = @provider_accounts.where(:provider_id =>  @provider.id) if @provider
> >     end
> >   end
> > diff --git a/src/app/views/provider_accounts/_credentials.xml.haml b/src/app/views/provider_accounts/_credentials.xml.haml
> > new file mode 100644
> > index 0000000..0103e6c
> > --- /dev/null
> > +++ b/src/app/views/provider_accounts/_credentials.xml.haml
> > @@ -0,0 +1,3 @@
> > +-creds_label_hash.each do |h|
> > +  =content_tag(h[:label]) do
> > +    =h[:value]
> > diff --git a/src/app/views/provider_accounts/_list.xml.haml b/src/app/views/provider_accounts/_list.xml.haml
> > new file mode 100644
> > index 0000000..fefe26d
> > --- /dev/null
> > +++ b/src/app/views/provider_accounts/_list.xml.haml
> > @@ -0,0 +1,12 @@
> > +!!! XML
> > +%provider_accounts
> > +  - provider_accounts.each do |pa|
> Would it be possible to use the provider_account model's to_xml method here?

I have to use templates to avoid including url helpers to models.
I think we can use some kind of "presenter" objects around models to access presentation functions
but for now I decided to use templates - faster and less intrusive.

> > +    %provider_account{:id =>  pa.id, :href =>  api_provider_account_url(pa)}
> > +      -provider = pa.provider
> > +      -provider_type = provider.provider_type
> > +      %name= pa.name
> > +      %provider{:id =>  provider.id, :href =>  api_provider_url(provider)}= provider.name
> > +      %provider_type= provider_type.deltacloud_driver
> > +      -if local_assigns[:with_credentials]
> > +        = content_tag(provider_type.deltacloud_driver + '_credentials') do
> > +          = render 'credentials', :creds_label_hash =>  pa.creds_label_hash
> > diff --git a/src/config/routes.rb b/src/config/routes.rb
> > index da762a7..242ad34 100644
> > --- a/src/config/routes.rb
> > +++ b/src/config/routes.rb
> > @@ -264,10 +264,12 @@ Conductor::Application.routes.draw do
> >       end
> >     end
> >
> > -  scope "/api" do
> > -    resources :providers, :as =>  'api_providers', :only =>  [:index, :show, :create, :update, :destroy]
> > -    resources :provider_accounts, :as =>  'api_provider_accounts', :only =>  [:index, :show]
> > -    resources :provider_types, :as =>  'api_provider_types', :only =>  [:index, :show]
> > +  scope "/api", :as =>  'api' do
> > +    resources :providers, :only =>  [:index, :show, :create, :update, :destroy] do
> > +      resources :provider_accounts, :only =>  [:index]
> > +    end
> > +    resources :provider_accounts, :only =>  [:index, :show]
> > +    resources :provider_types, :only =>  [:index, :show]
> >     end
> >
> >     #match 'matching_profiles', :to =>  '/hardware_profiles/matching_profiles/:hardware_profile_id/provider/:provider_id', :controller =>  'hardware_profiles', :action =>  'matching_profiles', :conditions =>  { :method =>  :get }, :as =>'matching_profiles'
> 
-- 

With regards
Petr Blaho



More information about the aeolus-devel mailing list