how to dry controller index actions
by Jan Provazník
Hi Ken,
new UI concept (spec/progressive_enhancement.md) requires access to same
data through multiple controllers depending JS is on/off.
Example: a user is on pools index page:
- if JS is off, pools/deployments/instances lists should be loaded
from pools#index action (including all pagination/searching/permission
logic for all 3 tabs)
- if JS is on, pools#index action renders only tabpanel with tabs for
pools/deployments/instances. When the user clicks on deployments tab,
deployment list is loaded through deployments#index (same
pagination/searching/permission logic must be here)
This differs from our current concept, when both JS and non-JS requests
use same controller#action. So I wonder what is most resonable way how
to not duplicate code on multiple places.
So solution could be this:
For each tab (pools, instances, deployments) move this 'list logic' into
separate module which will be then included both in pools and 'tab'
controller.
Example:
PoolsController
include DeploymentsListing
include PoolsListing
include InstancesListing
def index
@pools = list_pools
@instances = list_instances
@deployments = list_deployments
end
end
DeploymentsController
include DeploymentsListing
def index
list
end
end
module DeploymentListing
def list_pools
code for index action including perms check, pagination, search
end
end
What do you think? Anyone has some idea how to improve this?
Jan
12 years, 10 months
[PATCH conductor] Added permissions filtering to provider_accounts index action
by Jan Provazník
From: Jan Provaznik <jprovazn(a)redhat.com>
Temporary solution, we will need pagination+perms filtering+searching,
on many places so something smarter will be required. Maybe create named
scope from 'list_for_user' method? Fixing in this controller because
passwords are listed in XML output.
---
.../controllers/provider_accounts_controller.rb | 15 ++++++---------
1 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/src/app/controllers/provider_accounts_controller.rb b/src/app/controllers/provider_accounts_controller.rb
index 4dcd48d..40dae13 100644
--- a/src/app/controllers/provider_accounts_controller.rb
+++ b/src/app/controllers/provider_accounts_controller.rb
@@ -1,17 +1,17 @@
class ProviderAccountsController < ApplicationController
before_filter :require_user
- before_filter :load_accounts, :only => :show
+ before_filter :load_accounts, :only => [:index,:show]
before_filter :set_view_vars, :only => [:index,:show]
def index
+ # TODO: this is temporary solution how to combine search and permissions
+ # filtering
@search_term = params[:q]
- if @search_term.blank?
- load_accounts
- else
+ unless @search_term.blank?
search = ProviderAccount.search do
keywords(params[:q])
end
- @accounts = search.results
+ @accounts &= search.results
end
respond_to do |format|
@@ -172,9 +172,6 @@ class ProviderAccountsController < ApplicationController
end
def load_accounts
- @accounts = ProviderAccount.paginate(:all,
- :page => params[:page] || 1,
- :order => (params[:order_field] || 'label') +' '+ (params[:order_dir] || 'asc')
- )
+ @accounts = ProviderAccount.list_for_user(current_user, Privilege::VIEW)
end
end
--
1.7.4
12 years, 10 months
[PATCH conductor] Updated to touch thin.log instead of mongrel.log.
by Justin Clift
---
aeolus-conductor.spec.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/aeolus-conductor.spec.in b/aeolus-conductor.spec.in
index f983f8d..266ee1e 100644
--- a/aeolus-conductor.spec.in
+++ b/aeolus-conductor.spec.in
@@ -214,7 +214,7 @@ done
# by aeolus:aeolus. This is a temporary workaround while we've still
# got root-owned daemon processes. Once we resolve that issue
# these files will no longer be added explicitly here.
-touch %{buildroot}%{_localstatedir}/log/%{name}/mongrel.log
+touch %{buildroot}%{_localstatedir}/log/%{name}/thin.log
touch %{buildroot}%{_localstatedir}/log/%{name}/rails.log
touch %{buildroot}%{_localstatedir}/log/%{name}/dbomatic.log
touch %{buildroot}%{_localstatedir}/run/%{name}/event_log_position
--
1.7.4.4
12 years, 10 months
[PATCH conductor] XML format for list of provider types
by Jan Provazník
From: Jan Provaznik <jprovazn(a)redhat.com>
task #1621 (https://www.aeolusproject.org/redmine/issues/1621)
---
src/app/controllers/provider_types_controller.rb | 10 +++++++++
src/app/views/provider_types/_list.xml.haml | 7 ++++++
src/config/routes.rb | 1 +
src/db/seeds.rb | 1 +
src/features/provider_type.feature | 22 ++++++++++++++++++++
.../step_definitions/provider_type_steps.rb | 13 +++++++++++
6 files changed, 54 insertions(+), 0 deletions(-)
create mode 100644 src/app/controllers/provider_types_controller.rb
create mode 100644 src/app/views/provider_types/_list.xml.haml
create mode 100644 src/features/provider_type.feature
create mode 100644 src/features/step_definitions/provider_type_steps.rb
diff --git a/src/app/controllers/provider_types_controller.rb b/src/app/controllers/provider_types_controller.rb
new file mode 100644
index 0000000..8b65f89
--- /dev/null
+++ b/src/app/controllers/provider_types_controller.rb
@@ -0,0 +1,10 @@
+class ProviderTypesController < ApplicationController
+ before_filter :require_user
+
+ def index
+ @provider_types = ProviderType.all
+ respond_to do |format|
+ format.xml { render :partial => 'list.xml' }
+ end
+ end
+end
diff --git a/src/app/views/provider_types/_list.xml.haml b/src/app/views/provider_types/_list.xml.haml
new file mode 100644
index 0000000..6363806
--- /dev/null
+++ b/src/app/views/provider_types/_list.xml.haml
@@ -0,0 +1,7 @@
+!!! XML
+%provider_types
+ - @provider_types.each do |p|
+ %provider_type
+ %name= p.name
+ %codename= p.codename
+ %build_supported= p.build_supported
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 5d48373..5aa6414 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -48,6 +48,7 @@ ActionController::Routing::Routes.draw do |map|
map.resources :hardware_profiles, :collection => { :multi_destroy => :delete }
map.resources :providers, :collection => { :multi_destroy => :delete }
+ map.resources :provider_types
map.resources :users, :collection => { :multi_destroy => :delete }
map.resources :provider_accounts, :collection => { :multi_destroy => :delete, :set_selected_provider => :get}
map.resources :roles, :collection => { :multi_destroy => :delete }
diff --git a/src/db/seeds.rb b/src/db/seeds.rb
index 3ab3131..ad2c770 100644
--- a/src/db/seeds.rb
+++ b/src/db/seeds.rb
@@ -120,6 +120,7 @@ if ProviderType.all.empty?
ProviderType.create!(:name => "Rackspace", :codename =>"rackspace")
ProviderType.create!(:name => "RHEV-M", :codename =>"rhev-m")
ProviderType.create!(:name => "OpenNebula", :codename =>"opennebula")
+ ProviderType.create!(:name => "CondorCloud", :codename =>"condorcloud", :build_supported => 'true')
end
# fill table CredentialDefinitions by default values
diff --git a/src/features/provider_type.feature b/src/features/provider_type.feature
new file mode 100644
index 0000000..5948533
--- /dev/null
+++ b/src/features/provider_type.feature
@@ -0,0 +1,22 @@
+Feature: Manage Providers
+ In order to manage my cloud infrastructure
+ As a user
+ I want to manage cloud providers
+
+ Background:
+ Given I am an authorised user
+ And I am logged in
+
+ Scenario: List providers in XML format
+ Given I accept XML
+ When I go to the provider types page
+ Then I should get a XML document
+ And there should be these provider types:
+ | name | codename | build_supported |
+ | Mock | mock | true |
+ | GoGrid | gogrid | false |
+ | Rackspace | rackspace | false |
+ | OpenNebula | opennebula | false |
+ | Amazon EC2 | ec2 | true |
+ | CondorCloud | condorcloud | true |
+ | RHEV-M | rhev-m | false |
diff --git a/src/features/step_definitions/provider_type_steps.rb b/src/features/step_definitions/provider_type_steps.rb
new file mode 100644
index 0000000..0b0760a
--- /dev/null
+++ b/src/features/step_definitions/provider_type_steps.rb
@@ -0,0 +1,13 @@
+Then /^there should be these provider types:$/ do |table|
+ types = @xml_response.root.xpath('/provider_types/provider_type').map do |n|
+ {:name => n.xpath('name').text,
+ :codename => n.xpath('codename').text,
+ :build_supported => n.xpath('build_supported').text}
+ end
+ table.hashes.each do |hash|
+ p = types.find {|n| n[:name] == hash[:name]}
+ p.should_not be_nil
+ p[:codename].should == hash[:codename]
+ p[:build_supported].should == hash[:build_supported]
+ end
+end
--
1.7.4
12 years, 10 months