[PATCH] RM#3508 - Ensure that all sessions expire, that DB session objects are cleaned up correctly and that auto-refresh in the UI doesn't keep renewing sessions.
by Tomas Hrcka
---
src/config/initializers/session_store.rb | 2 +-
src/public/javascripts/application.js | 7 +++++-
src/spec/requests/sessions_spec.rb | 37 ++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+), 2 deletions(-)
create mode 100644 src/spec/requests/sessions_spec.rb
diff --git a/src/config/initializers/session_store.rb b/src/config/initializers/session_store.rb
index 8ff62fa..5fd69a1 100644
--- a/src/config/initializers/session_store.rb
+++ b/src/config/initializers/session_store.rb
@@ -28,4 +28,4 @@ Conductor::Application.config.session = {
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rake db:sessions:create")
-Conductor::Application.config.session_store :active_record_store
+Conductor::Application.config.session_store :active_record_store, :expire_after => 15.minutes
diff --git a/src/public/javascripts/application.js b/src/public/javascripts/application.js
index 2162880..fa842b2 100644
--- a/src/public/javascripts/application.js
+++ b/src/public/javascripts/application.js
@@ -25,7 +25,12 @@ $.extend(Conductor, {
$('#tab').html(data).show();
})
.error(function(data) {
- $('#tab').html(data.responseText).show();
+ // If our session has timed out, redirect to the login page:
+ if(data.status == 401) {
+ window.location = Conductor.PATH_PREFIX + "login";
+ } else {
+ $('#tab').html(data.responseText).show();
+ }
});
Conductor.tabRemoveActiveClass();
diff --git a/src/spec/requests/sessions_spec.rb b/src/spec/requests/sessions_spec.rb
new file mode 100644
index 0000000..4bd4611
--- /dev/null
+++ b/src/spec/requests/sessions_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe "Sessions" do
+ describe "User not logged in" do
+
+ it "should not be authenticated" do
+ get pools_path
+ response.status.should be(302)
+ end
+ end
+
+ describe "User logged in" do
+ before do
+ @user = FactoryGirl.create :tuser
+ end
+
+ it "should be authenticated" do
+
+ visit root_path
+ fill_in "Username", :with => @user.login
+ fill_in "password-input", :with => "secret"
+ click_button "Login"
+ page.status_code.should be(200)
+ end
+
+ it "should have expired session" do
+ visit root_path
+ fill_in "Username", :with => @user.login
+ fill_in "password-input", :with => "secret"
+ click_button "Login"
+ visit pools_path
+ Timecop.travel(Time.now+16.minutes)
+ visit pools_path
+ page.body.should include "#login"
+ end
+ end
+end
--
1.7.10.4
11 years, 9 months
[aeolus-incubator/image-management-engine] e388ac: Updated Models to handle new Factory format
by Martyn Taylor
Branch: refs/heads/master
Home: https://github.com/aeolus-incubator/image-management-engine
Commit: e388ac1f279d741afe77582109a67d4414182ce0
https://github.com/aeolus-incubator/image-management-engine/commit/e388ac...
Author: Martyn Taylor <mtaylor(a)redhat.com>
Date: 2012-08-14 (Tue, 14 Aug 2012)
Changed paths:
M app/models/image_management/target_image.rb
M lib/image_management.rb
A lib/rails_patches/active_resource/base.rb
A lib/rails_patches/active_resource/formats.rb
M spec/controllers/provider_images_controller_spec.rb
M spec/controllers/target_images_controller_spec.rb
A spec/factories/image_management/image_factory/status_detail.rb
M spec/factories/image_management/image_factory/target_image.rb
M spec/models/target_image_spec.rb
A test/dummy/test.rb
Log Message:
-----------
Updated Models to handle new Factory format
Commit: 03d0d638b8351a28ce75d13ce024083b2b17cb2c
https://github.com/aeolus-incubator/image-management-engine/commit/03d0d6...
Author: Martyn Taylor <mtaylor(a)redhat.com>
Date: 2012-08-14 (Tue, 14 Aug 2012)
Changed paths:
M app/models/image_management/provider_image.rb
M app/models/image_management/target_image.rb
M lib/generators/image_management/templates/migrations/create_provider_images.rb
M spec/controllers/provider_images_controller_spec.rb
M spec/factories/image_management/image_factory/provider_image.rb
A spec/fixtures/template.xml
M spec/models/dummy/provider_account_spec.rb
M spec/models/provider_image_spec.rb
M spec/models/target_image_spec.rb
M test/dummy/db/migrate/20120326103723532188_create_provider_images.rb
R test/dummy/db/migrate/20120423123757262119_add_provider_account_id_to_provider_image.rb
A test/dummy/db/migrate/create_provider_images.rb
M test/dummy/db/schema.rb
Log Message:
-----------
Added Provider Image Factory Integration
Compare: https://github.com/aeolus-incubator/image-management-engine/compare/456b0...
11 years, 9 months
[PATCH conductor] pools api - create, show, and update endpoints - under RM 3542
by Richard Su
https://www.aeolusproject.org/redmine/issues/3542
Updated controller to also render xml. Created specs to convert xml
into hash params and then to post the hash params to the controller
and verify xml responses.
---
src/app/controllers/pools_controller.rb | 15 +++
src/app/views/pools/_detail.xml.haml | 6 +
src/app/views/pools/show.xml.haml | 2 +
src/config/routes.rb | 1 +
src/spec/controllers/pools_controller_spec.rb | 159 +++++++++++++++++++++++++
5 files changed, 183 insertions(+), 0 deletions(-)
create mode 100644 src/app/views/pools/_detail.xml.haml
create mode 100644 src/app/views/pools/show.xml.haml
diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index 0668217..931d25d 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -166,6 +166,7 @@ class PoolsController < ApplicationController
map{ |deployment| view_context.deployment_for_mustache(deployment) }
render :json => @pool.as_json.merge({:deployments => deployments})
end
+ format.xml { render :show, :locals => { :pool => @pool } }
end
end
@@ -186,6 +187,11 @@ class PoolsController < ApplicationController
def create
@title = t('pools.create_new_pool')
+ if !params.has_key? :quota and !params[:pool][:quota].nil?
+ params[:quota] = params[:pool][:quota]
+ params[:pool].delete(:quota)
+ end
+
@pool = Pool.new(params[:pool])
require_privilege(Privilege::CREATE, Pool, @pool.pool_family)
@pool.quota = @quota = Quota.new
@@ -197,11 +203,14 @@ class PoolsController < ApplicationController
flash[:notice] = t "pools.flash.notice.added"
format.html { redirect_to pools_path }
format.json { render :json => @pool, :status => :created }
+ format.xml {render :show, :locals => { :pool => @pool }
+ }
else
flash.now[:warning] = t "pools.flash.warning.creation_failed"
format.html { render :new }
format.js { render :partial => 'new' }
format.json { render :json => @pool.errors, :status => :unprocessable_entity }
+ format.xml { render :template => 'api/validation_error', :locals => { :errors => @pool.errors }, :status => :bad_request}
end
end
end
@@ -219,6 +228,10 @@ class PoolsController < ApplicationController
end
def update
+ if !params.has_key? :quota and !params[:pool][:quota].nil?
+ params[:quota] = params[:pool][:quota]
+ params[:pool].delete(:quota)
+ end
@pool = Pool.find(params[:id])
require_privilege(Privilege::MODIFY, @pool)
set_quota
@@ -230,11 +243,13 @@ class PoolsController < ApplicationController
format.html { redirect_to :action => 'show', :id => @pool.id }
format.js { render :partial => 'show', :id => @pool.id }
format.json { render :json => @pool }
+ format.xml {render :show, :locals => { :pool => @pool } }
else
flash[:error] = t "pools.flash.error.not_updated"
format.html { render :action => :edit }
format.js { render :partial => 'edit', :id => @pool.id }
format.json { render :json => @pool.errors, :status => :unprocessable_entity }
+ format.xml { render :template => 'api/validation_error', :locals => { :errors => @pool.errors }, :status => :bad_request}
end
end
end
diff --git a/src/app/views/pools/_detail.xml.haml b/src/app/views/pools/_detail.xml.haml
new file mode 100644
index 0000000..9214ec0
--- /dev/null
+++ b/src/app/views/pools/_detail.xml.haml
@@ -0,0 +1,6 @@
+!!! XML
+%pool{:id => pool.id, :url => api_pool_url(pool)}
+ %name= pool.name
+ %pool_family{:id => pool.pool_family.id, :url=> pool_family_url(pool.pool_family)}= pool.pool_family.name
+ %quota= pool.quota.maximum_running_instances
+ %enabled= pool.enabled
diff --git a/src/app/views/pools/show.xml.haml b/src/app/views/pools/show.xml.haml
new file mode 100644
index 0000000..297a082
--- /dev/null
+++ b/src/app/views/pools/show.xml.haml
@@ -0,0 +1,2 @@
+!!! XML
+=render 'detail', :pool => pool
\ No newline at end of file
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 119d740..8373342 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -287,6 +287,7 @@ Conductor::Application.routes.draw do
resources :provider_accounts, :only => [:index, :show, :destroy]
resources :provider_types, :only => [:index, :show]
resources :hardware_profiles, :only => [:index, :show, :destroy, :create]
+ resources :pools, :only => [:index, :show, :create, :update]
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'
diff --git a/src/spec/controllers/pools_controller_spec.rb b/src/spec/controllers/pools_controller_spec.rb
index ba68755..5afc66c 100644
--- a/src/spec/controllers/pools_controller_spec.rb
+++ b/src/spec/controllers/pools_controller_spec.rb
@@ -99,6 +99,165 @@ describe PoolsController do
end
end
+ context "API" do
+ render_views
+
+ before do
+ accept_xml
+ mock_warden(@admin)
+ @test_pool_name = "testpool1"
+ @pool_family = FactoryGirl.create :pool_family
+ end
+
+ def assert_pool_api_success_response(name, familyName, familyId, quota, enabled)
+ response.should be_success
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/pool/name").text.should == name
+ xml.xpath("/pool/pool_family").text.should == familyName
+ xml.xpath("/pool/pool_family/@id").text.should == "#{familyId}"
+ xml.xpath("/pool/quota").text.should == quota
+ xml.xpath("/pool/enabled").text.should == enabled
+ end
+
+ describe "#create" do
+
+ it "post with all expected params" do
+ xmldata = "
+ <pool>
+ <name>#{@test_pool_name}</name>
+ <pool_family_id>#{(a)pool_family.id}</pool_family_id>
+ <enabled>true</enabled>
+ <quota>
+ <maximum_running_instances>1001</maximum_running_instances>
+ </quota>
+ </pool>"
+ post :create, Hash.from_xml(xmldata)
+
+ assert_pool_api_success_response(@test_pool_name,
+ @pool_family.name,
+ @pool_family.id,
+ "1001",
+ "true")
+ end
+
+ it "post missing pool family parameter should result in error message" do
+ xmldata = "
+ <pool>
+ <name>#{@test_pool_name}</name>
+ <!--<pool_family_id>#{(a)pool_family.id}</pool_family_id>-->
+ <enabled>true</enabled>
+ <quota>
+ <maximum_running_instances>1001</maximum_running_instances>
+ </quota>
+ </pool>"
+ post :create, Hash.from_xml(xmldata)
+
+ response.status.should be_eql(400) # Bad Request
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/errors/error/message").text.should == "Pool family can't be blank"
+ end
+
+ end
+
+ describe "#show" do
+
+ it "show an existing pool" do
+ @pool = FactoryGirl.create :pool
+
+ get :show, :id => @pool.id
+
+ assert_pool_api_success_response((a)pool.name,
+ @pool.pool_family.name,
+ @pool.pool_family.id,
+ "#{(a)pool.quota.maximum_running_instances}",
+ "#{(a)pool.enabled}")
+ end
+
+ it "show a missing pool" do
+ get :show, :id => -1
+
+ response.status.should be_eql(404)
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/error/message").text.should == "Couldn't find Pool with id=-1"
+ end
+
+ end
+
+ describe "#update" do
+
+ it "update with all expected params" do
+ # we will receive unlimited quota if
+ # maximum_running_instances is not specified
+ # <quota></quota> denotes unlmited quota
+ xmldata = "
+ <pool>
+ <name>#{@test_pool_name}</name>
+ <pool_family_id>#{(a)pool_family.id}</pool_family_id>
+ <enabled>true</enabled>
+ </pool>"
+ post :create, Hash.from_xml(xmldata)
+
+ assert_pool_api_success_response(@test_pool_name,
+ @pool_family.name,
+ @pool_family.id,
+ "", #unlimited
+ "true")
+
+ xml = Nokogiri::XML(response.body)
+ pool_id = xml.xpath("/pool/@id").text
+
+ xmldata = "
+ <pool>
+ <name>pool-updated</name>
+ <pool_family_id>#{(a)pool_family.id}</pool_family_id>
+ <enabled>false</enabled>
+ <quota>
+ <maximum_running_instances>1002</maximum_running_instances>
+ </quota>
+ </pool>"
+ put :update, :id => pool_id, :pool => Hash.from_xml(xmldata)["pool"]
+
+ assert_pool_api_success_response("pool-updated",
+ @pool_family.name,
+ @pool_family.id,
+ "1002",
+ "false")
+ end
+
+ it "update missing pool" do
+ xmldata = "<pool><name>missing-pool</name></pool>"
+ put :update, :id => -1, :pool => Hash.from_xml(xmldata)["pool"]
+
+ response.status.should be_eql(404)
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/error/message").text.should == "Couldn't find Pool with id=-1"
+ end
+
+ it "update with blank name" do
+ @pool = FactoryGirl.create :pool
+ xmldata = "<pool><name></name></pool>"
+ put :update, :id => @pool.id, :pool => Hash.from_xml(xmldata)["pool"]
+
+ response.status.should be_eql(400)
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/errors/error/message").text.should == "Name can't be blank"
+ end
+
+ end
+
+ end
+
+
context "JSON format responses for " do
before do
accept_json
--
1.7.7.6
11 years, 9 months
[PATCH conductor] User/Group profile UI to show permission grants
by Scott Seago
---
src/app/controllers/application_controller.rb | 37 ++++++++++++
src/app/controllers/permissions_controller.rb | 33 ++++++++---
src/app/controllers/user_groups_controller.rb | 11 +++-
src/app/controllers/users_controller.rb | 1 +
src/app/models/common_filter_methods.rb | 9 ++-
src/app/models/derived_permission.rb | 61 ++++++++++++++++++++-
src/app/models/permission.rb | 61 ++++++++++++++++++++-
src/app/models/role.rb | 10 +++
src/app/models/user.rb | 2 +-
src/app/models/user_group.rb | 5 ++
src/app/views/permissions/_objects.html.haml | 62 +++++++++++++++++++++
src/app/views/user_groups/_list.html.haml | 2 +-
src/app/views/user_groups/show.html.haml | 5 ++
src/app/views/users/show.html.haml | 7 ++-
src/config/locales/en.yml | 2 +
src/config/routes.rb | 1 +
src/features/step_definitions/permission_steps.rb | 5 ++
src/features/user.feature | 7 ++
src/features/user_group.feature | 7 ++
19 files changed, 309 insertions(+), 19 deletions(-)
create mode 100644 src/app/views/permissions/_objects.html.haml
diff --git a/src/app/controllers/application_controller.rb b/src/app/controllers/application_controller.rb
index b6381ff..588bb12 100644
--- a/src/app/controllers/application_controller.rb
+++ b/src/app/controllers/application_controller.rb
@@ -311,6 +311,43 @@ class ApplicationController < ActionController::Base
%w[asc desc].include?(params[:order_dir]) ? params[:order_dir] : "asc"
end
+ def add_profile_permissions_inline(entity, path_prefix = '')
+ @entity = entity
+ @path_prefix = path_prefix
+ @roles = Role.all_by_scope
+ @inline = true
+ @show_inherited = params[:show_inherited]
+ @show_global = params[:show_global]
+ if @show_inherited
+ local_perms = @entity.derived_permissions
+ else
+ local_perms = @entity.permissions
+ end
+ @permissions = paginate_collection(local_perms.
+ apply_filters(:preset_filters_options =>
+ Permission::PROFILE_PRESET_FILTERS_OPTIONS,
+ :preset_filter_id =>
+ params[:profile_permissions_preset_filter],
+ :search_filter =>
+ [params[:profile_permissions_search],
+ params[:profile_permissions_preset_filter]]),
+ params[:page])
+
+ @permission_list_header = []
+ unless (@show_inherited)
+ @permission_list_header <<
+ { :name => 'checkbox', :class => 'checkbox', :sortable => false }
+ end
+ @permission_list_header += [
+ { :name => t('permissions.resource')},
+ { :name => t("role"), :sort_attr => :role},
+ ]
+ if @show_inherited
+ @permission_list_header <<
+ { :name => t('permissions.inherited_from'), :sortable => false }
+ end
+ end
+
def add_permissions_inline(perm_obj, path_prefix = '', polymorphic_path_extras = {})
@permission_object = perm_obj
require_privilege(Privilege::VIEW, @permission_object)
diff --git a/src/app/controllers/permissions_controller.rb b/src/app/controllers/permissions_controller.rb
index 9b56a49..cd80e02 100644
--- a/src/app/controllers/permissions_controller.rb
+++ b/src/app/controllers/permissions_controller.rb
@@ -173,6 +173,14 @@ class PermissionsController < ApplicationController
redirect_to_original({"entities_preset_filter" => params[:entities_preset_filter], "entities_search" => params[:entities_search]})
end
+ def profile_filter
+ redirect_to_original({"profile_permissions_preset_filter" =>
+ params[:profile_permissions_preset_filter],
+ "profile_permissions_search" =>
+ (params[:profile_permissions_preset_filter].empty? ?
+ nil : params[:profile_permissions_search])})
+ end
+
private
def load_entities
@@ -195,6 +203,7 @@ class PermissionsController < ApplicationController
def set_permission_object (required_role=Privilege::PERM_SET)
obj_type = params[:permission_object_type]
id = params[:permission_object_id]
+ @return_path = params[:return_path]
@path_prefix = params[:path_prefix]
@polymorphic_path_extras = params[:polymorphic_path_extras]
@use_tabs = params[:use_tabs]
@@ -209,16 +218,20 @@ class PermissionsController < ApplicationController
end
end
raise RuntimeError, "invalid permission object" if @permission_object.nil?
- if @permission_object == BasePermissionObject.general_permission_scope
- @return_path = permissions_path
- set_admin_users_tabs 'permissions'
- else
- @return_path = send("#{@path_prefix}polymorphic_path",
- @permission_object.respond_to?(:to_polymorphic_path_param) ?
- @permission_object.to_polymorphic_path_param(@polymorphic_path_extras) :
- @permission_object,
- @use_tabs == "yes" ? {:details_tab => :permissions,
- :only_tab => true} : {})
+ unless @return_path
+ if @permission_object == BasePermissionObject.general_permission_scope
+ @return_path = permissions_path
+ set_admin_users_tabs 'permissions'
+ else
+ @return_path = send("#{@path_prefix}polymorphic_path",
+ @permission_object.respond_to?(
+ :to_polymorphic_path_param) ?
+ @permission_object.to_polymorphic_path_param(
+ @polymorphic_path_extras) :
+ @permission_object,
+ @use_tabs == "yes" ? {:details_tab => :permissions,
+ :only_tab => true} : {})
+ end
end
require_privilege(required_role, @permission_object)
set_permissions_header
diff --git a/src/app/controllers/user_groups_controller.rb b/src/app/controllers/user_groups_controller.rb
index 6cae0fa..23cac12 100644
--- a/src/app/controllers/user_groups_controller.rb
+++ b/src/app/controllers/user_groups_controller.rb
@@ -40,6 +40,7 @@ class UserGroupsController < ApplicationController
@tab_captions = ['Properties']
@details_tab = params[:details_tab].blank? ? 'properties' : params[:details_tab]
@members = paginate_collection((a)user_group.members, params[:page])
+ add_profile_permissions_inline((a)user_group.entity)
respond_to do |format|
format.html
format.js do
@@ -222,7 +223,11 @@ class UserGroupsController < ApplicationController
def load_user_groups
sort_order = params[:sort_by].nil? ? "name" : params[:sort_by]
- @user_groups = UserGroup.apply_filters(:preset_filter_id => params[:users_preset_filter], :search_filter => params[:user_groups_search]).order(sort_order)
+ @user_groups = UserGroup.apply_filters(:preset_filter_id =>
+ params[:user_groups_preset_filter],
+ :search_filter =>
+ params[:user_groups_search]).
+ order(sort_order)
end
def load_headers
@@ -233,4 +238,8 @@ class UserGroupsController < ApplicationController
]
end
+ def filter
+ redirect_to_original({"user_groups_preset_filter" => params[:user_groups_preset_filter], "user_groups_search" => params[:user_groups_search]})
+ end
+
end
diff --git a/src/app/controllers/users_controller.rb b/src/app/controllers/users_controller.rb
index 0b8c3fe..0c9f564 100644
--- a/src/app/controllers/users_controller.rb
+++ b/src/app/controllers/users_controller.rb
@@ -81,6 +81,7 @@ class UsersController < ApplicationController
save_breadcrumb(user_path(@user), @user.name)
@tab_captions = ['Properties']
@details_tab = 'properties' # currently the only supported details tab
+ add_profile_permissions_inline((a)user.entity)
respond_to do |format|
format.html
format.js do
diff --git a/src/app/models/common_filter_methods.rb b/src/app/models/common_filter_methods.rb
index 9491ecb..555b20f 100644
--- a/src/app/models/common_filter_methods.rb
+++ b/src/app/models/common_filter_methods.rb
@@ -16,14 +16,17 @@
#this module contains functions for filtering table data
module CommonFilterMethods
def apply_filters(options = {})
- apply_preset_filter(options[:preset_filter_id]).apply_search_filter(options[:search_filter])
+ filters_options = options[:preset_filters_options] ||
+ self::PRESET_FILTERS_OPTIONS
+ apply_preset_filter(options[:preset_filter_id], filters_options).
+ apply_search_filter(options[:search_filter])
end
private
- def apply_preset_filter(preset_filter_id)
+ def apply_preset_filter(preset_filter_id, filters_options)
if preset_filter_id.present?
- option = self::PRESET_FILTERS_OPTIONS.select { |item|
+ option = filters_options.select { |item|
item[:id] == preset_filter_id}.first
if option[:query]
option[:query]
diff --git a/src/app/models/derived_permission.rb b/src/app/models/derived_permission.rb
index 80d055d..2eb2c78 100644
--- a/src/app/models/derived_permission.rb
+++ b/src/app/models/derived_permission.rb
@@ -69,9 +69,68 @@ class DerivedPermission < ActiveRecord::Base
:where => {"entities.entity_target_type" => "UserGroup"}}
]
+ PROFILE_PRESET_FILTERS_OPTIONS = [
+ {:title => "permissions.global",
+ :id => "base_permission_object_permissions",
+ :includes => [:entity, :base_permission_object],
+ :where => {"permission_object_type" => "BasePermissionObject"}},
+ {:title => "activerecord.models.provider",
+ :id => "provider_permissions",
+ :includes => [:entity, :provider],
+ :where => {"permission_object_type" => "Provider"},
+ :search_fields => ["providers.name"]},
+ {:title => "activerecord.models.provider_account",
+ :id => "provider_account_permissions",
+ :includes => [:entity, {:provider_account => :provider}],
+ :where => {"permission_object_type" => "ProviderAccount"},
+ :search_fields => ["provider_accounts.label", "providers.name"]},
+ {:title => "activerecord.models.pool",
+ :id => "pool_permissions",
+ :includes => [:entity, :pool],
+ :where => {"permission_object_type" => "Pool"},
+ :search_fields => ["pools.name"]},
+ {:title => "activerecord.models.pool_family",
+ :id => "pool_family_permissions",
+ :includes => [:entity, :pool_family],
+ :where => {"permission_object_type" => "PoolFamily"},
+ :search_fields => ["pool_families.name"]},
+ {:title => "activerecord.models.catalog",
+ :id => "catalog_permissions",
+ :includes => [:entity, :catalog],
+ :where => {"permission_object_type" => "Catalog"},
+ :search_fields => ["catalogs.name"]},
+ {:title => "activerecord.models.deployable",
+ :id => "deployable_permissions",
+ :includes => [:entity, :deployable],
+ :where => {"permission_object_type" => "Deployable"},
+ :search_fields => ["deployables.name"]},
+ {:title => "activerecord.models.deployment",
+ :id => "deployment_permissions",
+ :includes => [:entity, :deployment],
+ :where => {"permission_object_type" => "Deployment"},
+ :search_fields => ["deployments.name"]},
+ {:title => "activerecord.models.instance",
+ :id => "instance_permissions",
+ :includes => [:entity, :instance],
+ :where => {"permission_object_type" => "Instance"},
+ :search_fields => ["instances.name"]}
+ ]
def self.apply_search_filter(search)
+ search, preset_filter_id = search
if search
- includes("entity").where("lower(entities.name) LIKE :search", :search => "%#{search.downcase}%")
+ if preset_filter_id
+ search_fields = PROFILE_PRESET_FILTERS_OPTIONS.select { |item|
+ item[:id] == preset_filter_id
+ }.first[:search_fields]
+ search_fields = [] if search_fields.nil?
+ else
+ search_fields = []
+ end
+ where_str = "lower(entities.name) LIKE :search OR lower(roles.name) LIKE :search"
+ search_fields.each do |search_field|
+ where_str += " OR lower(#{search_field}) LIKE :search"
+ end
+ includes([:entity, :role]).where(where_str, :search => "%#{search.downcase}%")
else
scoped
end
diff --git a/src/app/models/permission.rb b/src/app/models/permission.rb
index 9b4c0ac..04736e2 100644
--- a/src/app/models/permission.rb
+++ b/src/app/models/permission.rb
@@ -81,6 +81,52 @@ class Permission < ActiveRecord::Base
:includes => :entity,
:where => {"entities.entity_target_type" => "UserGroup"}}
]
+ PROFILE_PRESET_FILTERS_OPTIONS = [
+ {:title => "permissions.global",
+ :id => "base_permission_object_permissions",
+ :includes => [:entity, :base_permission_object],
+ :where => {"permission_object_type" => "BasePermissionObject"}},
+ {:title => "activerecord.models.provider",
+ :id => "provider_permissions",
+ :includes => [:entity, :provider],
+ :where => {"permission_object_type" => "Provider"},
+ :search_fields => ["providers.name"]},
+ {:title => "activerecord.models.provider_account",
+ :id => "provider_account_permissions",
+ :includes => [:entity, {:provider_account => :provider}],
+ :where => {"permission_object_type" => "ProviderAccount"},
+ :search_fields => ["provider_accounts.label", "providers.name"]},
+ {:title => "activerecord.models.pool",
+ :id => "pool_permissions",
+ :includes => [:entity, :pool],
+ :where => {"permission_object_type" => "Pool"},
+ :search_fields => ["pools.name"]},
+ {:title => "activerecord.models.pool_family",
+ :id => "pool_family_permissions",
+ :includes => [:entity, :pool_family],
+ :where => {"permission_object_type" => "PoolFamily"},
+ :search_fields => ["pool_families.name"]},
+ {:title => "activerecord.models.catalog",
+ :id => "catalog_permissions",
+ :includes => [:entity, :catalog],
+ :where => {"permission_object_type" => "Catalog"},
+ :search_fields => ["catalogs.name"]},
+ {:title => "activerecord.models.deployable",
+ :id => "deployable_permissions",
+ :includes => [:entity, :deployable],
+ :where => {"permission_object_type" => "Deployable"},
+ :search_fields => ["deployables.name"]},
+ {:title => "activerecord.models.deployment",
+ :id => "deployment_permissions",
+ :includes => [:entity, :deployment],
+ :where => {"permission_object_type" => "Deployment"},
+ :search_fields => ["deployments.name"]},
+ {:title => "activerecord.models.instance",
+ :id => "instance_permissions",
+ :includes => [:entity, :instance],
+ :where => {"permission_object_type" => "Instance"},
+ :search_fields => ["instances.name"]}
+ ]
def user
entity.user
end
@@ -116,8 +162,21 @@ class Permission < ActiveRecord::Base
end
def self.apply_search_filter(search)
+ search, preset_filter_id = search
if search
- includes("entity").where("lower(entities.name) LIKE :search", :search => "%#{search.downcase}%")
+ if preset_filter_id
+ search_fields = PROFILE_PRESET_FILTERS_OPTIONS.select { |item|
+ item[:id] == preset_filter_id
+ }.first[:search_fields]
+ search_fields = [] if search_fields.nil?
+ else
+ search_fields = []
+ end
+ where_str = "lower(entities.name) LIKE :search OR lower(roles.name) LIKE :search"
+ search_fields.each do |search_field|
+ where_str += " OR lower(#{search_field}) LIKE :search"
+ end
+ includes([:entity, :role]).where(where_str, :search => "%#{search.downcase}%")
else
scoped
end
diff --git a/src/app/models/role.rb b/src/app/models/role.rb
index dcf3178..2989042 100644
--- a/src/app/models/role.rb
+++ b/src/app/models/role.rb
@@ -47,4 +47,14 @@ class Role < ActiveRecord::Base
def privilege_target_match(obj_type)
(privilege_target_types & obj_type.active_privilege_target_types).any?
end
+
+ def self.all_by_scope
+ roles = self.all
+ role_hash = {}
+ roles.each do |role|
+ role_hash[role.scope] ||= []
+ role_hash[role.scope] << role
+ end
+ role_hash
+ end
end
diff --git a/src/app/models/user.rb b/src/app/models/user.rb
index 73579e5..7d18223 100644
--- a/src/app/models/user.rb
+++ b/src/app/models/user.rb
@@ -59,7 +59,7 @@ class User < ActiveRecord::Base
attr_accessor :ignore_password
has_many :permissions, :through => :entity
- has_many :derived_permissions, :through => :entities
+ has_many :derived_permissions, :through => :entity
has_many :owned_instances, :class_name => "Instance", :foreign_key => "owner_id"
has_many :deployments, :foreign_key => "owner_id"
has_many :view_states
diff --git a/src/app/models/user_group.rb b/src/app/models/user_group.rb
index 3d4513d..9aae611 100644
--- a/src/app/models/user_group.rb
+++ b/src/app/models/user_group.rb
@@ -40,6 +40,11 @@ class UserGroup < ActiveRecord::Base
validates_inclusion_of :membership_source, :in => MEMBERSHIP_SOURCES
after_save :update_entity
+ PRESET_FILTERS_OPTIONS = [
+ {:title => "user_groups.preset_filters.local", :id => "local_user_groups", :query => where("user_groups.membership_source = ?", MEMBERSHIP_SOURCE_LOCAL)},
+ {:title => "user_groups.preset_filters.ldap", :id => "ldap_user_groups", :query => where("user_groups.membership_source = ?", MEMBERSHIP_SOURCE_LDAP)}
+ ]
+
def update_entity
self.entity = Entity.new(:entity_target => self) unless self.entity
self.entity.name = "#{self.name} (#{self.membership_source})"
diff --git a/src/app/views/permissions/_objects.html.haml b/src/app/views/permissions/_objects.html.haml
new file mode 100644
index 0000000..fd2e143
--- /dev/null
+++ b/src/app/views/permissions/_objects.html.haml
@@ -0,0 +1,62 @@
+- content_for :permissions_form_header do
+ - if not(@show_inherited) && check_privilege(Privilege::PERM_SET)
+ %li= restful_submit_tag t('permissions.revoke_access'), "destroy", multi_destroy_permissions_path, 'DELETE', :id => 'revoke_button', :class => 'button danger'
+ %li= restful_submit_tag t('edit'), "multi_update", multi_update_permissions_path, 'POST', :id => 'perm_edit_button', :class => 'hidden'
+ = hidden_field_tag :entity_id, @entity.id
+
+ = hidden_field_tag :path_prefix, @path_prefix
+ = hidden_field_tag :return_path, url_for((a)entity.entity_target)
+ = hidden_field_tag :use_tabs, @use_tabs ? @use_tabs : (@tabs ? 'yes' : 'no')
+ %span{:id => ("tab-container-1-nav" unless @inline)}
+ - if @show_inherited
+ %li= link_to t('permissions.direct_access'), params.merge(:show_inherited => false, :page => 1), { :class => 'button primary', :id => 'direct_permission_button'}
+ - else
+ %li= link_to t('permissions.inherited_access'), params.merge(:show_inherited => true, :page => 1), { :class => 'button primary', :id => 'inherited_permission_button'}
+
+- content_for :permissions_filter_controls do
+ %li
+ = label_tag :profile_permissions_preset_filter, t('filter_table.viewing')
+ = select_tag(:profile_permissions_preset_filter, preset_filters_options_for_select(Permission::PROFILE_PRESET_FILTERS_OPTIONS, params[:profile_permissions_preset_filter]), :include_blank => t("permissions.preset_filters.all_permissions"), :disabled => false)
+ = hidden_field_tag :current_path, request.fullpath
+ = restful_submit_tag t("filter_table.apply_filters"), "profile_filter", profile_filter_permissions_path, 'POST', :class => 'button', :id => 'apply_profile_permissions_preset_filter'
+ %span.label.badge.dark= @permissions.count
+ %li.table-search-filter
+ - disable_search = params[:profile_permissions_preset_filter].nil? || params[:profile_permissions_preset_filter].empty?
+ = text_field_tag :profile_permissions_search, (disable_search ? nil : params[:profile_permissions_search]), :placeholder => t("filter_table.search"), :disabled => disable_search
+ = restful_submit_tag "", "search", profile_filter_permissions_path, 'POST', :class => 'button', :id => 'apply_profile_permissions_search'
+
+ :javascript
+ $(document).ready(function(){
+ $("#apply_profile_permissions_preset_filter").hide();
+ $("#profile_permissions_preset_filter").change(function() {
+ $("#apply_profile_permissions_preset_filter").click();
+ });
+ Conductor.clickOnEnterKeypress($('#profile_permissions_search'), $('#apply_profile_permissions_search'));
+ });
+
+= filter_table(@permission_list_header,
+ @permissions,
+ :form_header => :permissions_form_header,
+ :filter_controls => :permissions_filter_controls) do |permission|
+ %tr{:class => cycle('nostripe','stripe')}
+ - if not(@show_inherited)
+ %td{:class => 'checkbox'}
+ - if check_privilege(Privilege::PERM_SET)
+ - selected = params[:select] == 'all'
+ = check_box_tag "permission_selected[]", permission.id, selected, :id => "permission_checkbox_#{permission.id}"
+ - if permission.permission_object.class == BasePermissionObject
+ %td= t'permissions.global'
+ - else
+ %td= link_to permission.permission_object.name, permission.permission_object
+ - if not(@show_inherited) && check_privilege(Privilege::PERM_SET)
+ %td= select_tag "permission_role_selected[]", options_for_select((a)roles[permission.permission_object_type].map {|r| [ t(r.name, :scope=> :role_defs, :default => r.name), "#{permission.id},#{r.id}" ] }, :selected => "#{permission.id},#{permission.role.id}", :disabled => @entity.permissions.where(["entity_id = ? and role_id != ?", permission.entity_id, permission.role_id]).collect {|p| "#{permission.id},#{p.role.id}"}), :id => "permission_role_selected_#{permission.id}"
+ :javascript
+ $("#permission_role_selected_#{permission.id}").change(function () { $("#perm_edit_button").click(); } );
+
+ -else
+ %td= t(permission.role.name, :scope=> :role_defs, :default => permission.role.name)
+ - if @show_inherited
+ - if permission.permission.permission_object.class == BasePermissionObject
+ %td= t'permissions.global'
+ - else
+ %td= link_to permission.permission.permission_object.name, permission.permission.permission_object
diff --git a/src/app/views/user_groups/_list.html.haml b/src/app/views/user_groups/_list.html.haml
index 0f6d2f3..c9af5d7 100644
--- a/src/app/views/user_groups/_list.html.haml
+++ b/src/app/views/user_groups/_list.html.haml
@@ -9,7 +9,7 @@
%li
= label_tag :user_groups_preset_filter, t('filter_table.viewing')
= hidden_field_tag :current_path, request.fullpath
- = select_tag(:user_groups_preset_filter, preset_filters_options_for_select(User::PRESET_FILTERS_OPTIONS, params[:user_groups_preset_filter]), :include_blank => t("user_groups.preset_filters.all_user_groups"), :disabled => true)
+ = select_tag(:user_groups_preset_filter, preset_filters_options_for_select(UserGroup::PRESET_FILTERS_OPTIONS, params[:user_groups_preset_filter]), :include_blank => t("user_groups.preset_filters.all_user_groups"))
= restful_submit_tag t("filter_table.apply_filters"), "index", filter_user_groups_path, 'POST', :class => 'button', :id => 'apply_user_groups_preset_filter'
%span.label.badge.dark= @user_groups.count
/ = link_to "Filter", "#", :class => 'button pill'
diff --git a/src/app/views/user_groups/show.html.haml b/src/app/views/user_groups/show.html.haml
index cb22930..f5f1890 100644
--- a/src/app/views/user_groups/show.html.haml
+++ b/src/app/views/user_groups/show.html.haml
@@ -69,3 +69,8 @@
= link_to member.login, users_path(member)
%td
= member.name
+%section.content-section.permissions
+ %header
+ %h2.permissions=t'permissions.index.permissions'
+ .content
+ = render :partial => 'permissions/objects'
diff --git a/src/app/views/users/show.html.haml b/src/app/views/users/show.html.haml
index 54ca9e3..a89581d 100644
--- a/src/app/views/users/show.html.haml
+++ b/src/app/views/users/show.html.haml
@@ -44,13 +44,18 @@
%dt=t'users.show.last_login_ip'
%dd= @user.last_login_ip
-%section.content-section.user
+%section.content-section.groups
%header
%h2.groups=t'users.groups'
= filter_table(@groups_header, @user_groups) do |user_group|
%tr{:class => cycle('nostripe','stripe')}
%td= link_to user_group.name, user_group_path(user_group)
%td= t("user_groups.#{user_group.membership_source.downcase}")
+%section.content-section.permissions
+ %header
+ %h2.permissions=t'permissions.index.permissions'
+ .content
+ = render :partial => 'permissions/objects'
/%section.content-section.user
/ %header
/ %h2.activity Activity
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 151a84e..2824cf3 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -1340,6 +1340,8 @@ en:
permissions:
direct_access: "Direct Access"
global_access: "Global Access"
+ global: "Global"
+ resource: "Resource"
inherited_access: "Inherited Access"
inherited_from: "Inherited From"
revoke_access: "Revoke Access"
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 119d740..685bbec 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -85,6 +85,7 @@ Conductor::Application.routes.draw do
post :multi_update
post :filter
post :filter_entities
+ post :profile_filter
end
end
diff --git a/src/features/step_definitions/permission_steps.rb b/src/features/step_definitions/permission_steps.rb
index 8620156..83641d8 100644
--- a/src/features/step_definitions/permission_steps.rb
+++ b/src/features/step_definitions/permission_steps.rb
@@ -35,6 +35,11 @@ Given /^there is a permission for the user "([^\"]*)" on the pool family "([^\"]
:permission_object => PoolFamily.find_by_name(pool_family_name))
end
+Given /^there is a permission for the user group "([^\"]*)" on the pool "([^\"]*)"$/ do |group_name, pool_name|
+ @pool_user_permission = FactoryGirl.create(:pool_user_permission, :entity_id => UserGroup.find_by_name(group_name).entity.id,
+ :permission_object => Pool.find_by_name(pool_name))
+end
+
Given /^I delete the permission$/ do
check "permission_checkbox_#{(a)pool_user_permission.id}"
click_button "revoke_button"
diff --git a/src/features/user.feature b/src/features/user.feature
index 46e0b38..b3bdea9 100644
--- a/src/features/user.feature
+++ b/src/features/user.feature
@@ -33,6 +33,13 @@ Feature: Manage Users
When I follow "testuser"
Then I should be on testuser's user page
+ Scenario: Show user permissions
+ Given a pool "PermissionPool" exists
+ And there is a permission for the user "testuser" on the pool "PermissionPool"
+ And I am on the users page
+ When I follow "testuser"
+ Then I should see "PermissionPool"
+
Scenario: Delete users
Given there is a user "testuser"
And I am on the users page
diff --git a/src/features/user_group.feature b/src/features/user_group.feature
index 08f4db7..2779469 100644
--- a/src/features/user_group.feature
+++ b/src/features/user_group.feature
@@ -15,6 +15,13 @@ Feature: Manage User Groups
When I follow "testgroup"
Then I should be on testgroup's user group page
+ Scenario: Show user group permissions
+ Given a pool "PermissionPool" exists
+ And there is a permission for the user group "testgroup" on the pool "PermissionPool"
+ And I am on the user groups page
+ When I follow "testgroup"
+ Then I should see "PermissionPool"
+
Scenario: Delete user groups
Given there is a user group "testgroup"
Given there is a user group "testgroup2"
--
1.7.6.5
11 years, 9 months
RFC: Notification system
by Matt Wagner
Hi folks,
I've been dwelling on user notifications a bit more. #3623 implies this
functionality, and there are some comments visible here:
https://www.aeolusproject.org/redmine/issues/3623
We have some licensing difference between our projects (grr!), but it
might make sense to see about borrowing the Katello implementation
rather than reinventing this from the ground up. They already support
persistent notifications which can be sent to multiple users, though
we'd have to add email notifications and perhaps notification
preferences. I added a couple of screenshots as well.
Let me know what you think -- does this seem like a good approach for us
to follow?
-- Matt
11 years, 9 months
Taking Aeolus To Social Networking Websites
by Nitesh Narayan
Hi,
I got a thought that it would be great if we could put up Aeolus to social networking websites like facebook , google plus etc. By this way we would be able to reach to a greater number of people as today most of the crowd uses these websites quite often .
This way users will get more number of ways to approach us and we would be able to spread the news about aeolus to a greater crowd .
I would be happy to take the intiative but surely will be needing lots of help , any further suggestions will be great .
Print only if its necessary
Regards
Nitesh Narayan Lal
11 years, 9 months
[PATCH conductor] pools api - create, show, and update endpoints - under RM 3542
by Richard Su
https://www.aeolusproject.org/redmine/issues/3542
Updated controller to also render xml. Created specs to convert xml
into hash params and then to post the hash params to the controller
and verify xml responses.
---
src/app/controllers/pools_controller.rb | 15 +++
src/app/views/pools/_detail.xml.haml | 6 +
src/app/views/pools/show.xml.haml | 2 +
src/config/routes.rb | 1 +
src/spec/controllers/pools_controller_spec.rb | 159 +++++++++++++++++++++++++
5 files changed, 183 insertions(+), 0 deletions(-)
create mode 100644 src/app/views/pools/_detail.xml.haml
create mode 100644 src/app/views/pools/show.xml.haml
diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index 0668217..931d25d 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -166,6 +166,7 @@ class PoolsController < ApplicationController
map{ |deployment| view_context.deployment_for_mustache(deployment) }
render :json => @pool.as_json.merge({:deployments => deployments})
end
+ format.xml { render :show, :locals => { :pool => @pool } }
end
end
@@ -186,6 +187,11 @@ class PoolsController < ApplicationController
def create
@title = t('pools.create_new_pool')
+ if !params.has_key? :quota and !params[:pool][:quota].nil?
+ params[:quota] = params[:pool][:quota]
+ params[:pool].delete(:quota)
+ end
+
@pool = Pool.new(params[:pool])
require_privilege(Privilege::CREATE, Pool, @pool.pool_family)
@pool.quota = @quota = Quota.new
@@ -197,11 +203,14 @@ class PoolsController < ApplicationController
flash[:notice] = t "pools.flash.notice.added"
format.html { redirect_to pools_path }
format.json { render :json => @pool, :status => :created }
+ format.xml {render :show, :locals => { :pool => @pool }
+ }
else
flash.now[:warning] = t "pools.flash.warning.creation_failed"
format.html { render :new }
format.js { render :partial => 'new' }
format.json { render :json => @pool.errors, :status => :unprocessable_entity }
+ format.xml { render :template => 'api/validation_error', :locals => { :errors => @pool.errors }, :status => :bad_request}
end
end
end
@@ -219,6 +228,10 @@ class PoolsController < ApplicationController
end
def update
+ if !params.has_key? :quota and !params[:pool][:quota].nil?
+ params[:quota] = params[:pool][:quota]
+ params[:pool].delete(:quota)
+ end
@pool = Pool.find(params[:id])
require_privilege(Privilege::MODIFY, @pool)
set_quota
@@ -230,11 +243,13 @@ class PoolsController < ApplicationController
format.html { redirect_to :action => 'show', :id => @pool.id }
format.js { render :partial => 'show', :id => @pool.id }
format.json { render :json => @pool }
+ format.xml {render :show, :locals => { :pool => @pool } }
else
flash[:error] = t "pools.flash.error.not_updated"
format.html { render :action => :edit }
format.js { render :partial => 'edit', :id => @pool.id }
format.json { render :json => @pool.errors, :status => :unprocessable_entity }
+ format.xml { render :template => 'api/validation_error', :locals => { :errors => @pool.errors }, :status => :bad_request}
end
end
end
diff --git a/src/app/views/pools/_detail.xml.haml b/src/app/views/pools/_detail.xml.haml
new file mode 100644
index 0000000..9214ec0
--- /dev/null
+++ b/src/app/views/pools/_detail.xml.haml
@@ -0,0 +1,6 @@
+!!! XML
+%pool{:id => pool.id, :url => api_pool_url(pool)}
+ %name= pool.name
+ %pool_family{:id => pool.pool_family.id, :url=> pool_family_url(pool.pool_family)}= pool.pool_family.name
+ %quota= pool.quota.maximum_running_instances
+ %enabled= pool.enabled
diff --git a/src/app/views/pools/show.xml.haml b/src/app/views/pools/show.xml.haml
new file mode 100644
index 0000000..297a082
--- /dev/null
+++ b/src/app/views/pools/show.xml.haml
@@ -0,0 +1,2 @@
+!!! XML
+=render 'detail', :pool => pool
\ No newline at end of file
diff --git a/src/config/routes.rb b/src/config/routes.rb
index c13d827..5e9dfd2 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -286,6 +286,7 @@ Conductor::Application.routes.draw do
end
resources :provider_accounts, :only => [:index, :show, :destroy]
resources :provider_types, :only => [:index, :show]
+ resources :pools, :only => [:index, :show, :create, :update]
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'
diff --git a/src/spec/controllers/pools_controller_spec.rb b/src/spec/controllers/pools_controller_spec.rb
index ba68755..5afc66c 100644
--- a/src/spec/controllers/pools_controller_spec.rb
+++ b/src/spec/controllers/pools_controller_spec.rb
@@ -99,6 +99,165 @@ describe PoolsController do
end
end
+ context "API" do
+ render_views
+
+ before do
+ accept_xml
+ mock_warden(@admin)
+ @test_pool_name = "testpool1"
+ @pool_family = FactoryGirl.create :pool_family
+ end
+
+ def assert_pool_api_success_response(name, familyName, familyId, quota, enabled)
+ response.should be_success
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/pool/name").text.should == name
+ xml.xpath("/pool/pool_family").text.should == familyName
+ xml.xpath("/pool/pool_family/@id").text.should == "#{familyId}"
+ xml.xpath("/pool/quota").text.should == quota
+ xml.xpath("/pool/enabled").text.should == enabled
+ end
+
+ describe "#create" do
+
+ it "post with all expected params" do
+ xmldata = "
+ <pool>
+ <name>#{@test_pool_name}</name>
+ <pool_family_id>#{(a)pool_family.id}</pool_family_id>
+ <enabled>true</enabled>
+ <quota>
+ <maximum_running_instances>1001</maximum_running_instances>
+ </quota>
+ </pool>"
+ post :create, Hash.from_xml(xmldata)
+
+ assert_pool_api_success_response(@test_pool_name,
+ @pool_family.name,
+ @pool_family.id,
+ "1001",
+ "true")
+ end
+
+ it "post missing pool family parameter should result in error message" do
+ xmldata = "
+ <pool>
+ <name>#{@test_pool_name}</name>
+ <!--<pool_family_id>#{(a)pool_family.id}</pool_family_id>-->
+ <enabled>true</enabled>
+ <quota>
+ <maximum_running_instances>1001</maximum_running_instances>
+ </quota>
+ </pool>"
+ post :create, Hash.from_xml(xmldata)
+
+ response.status.should be_eql(400) # Bad Request
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/errors/error/message").text.should == "Pool family can't be blank"
+ end
+
+ end
+
+ describe "#show" do
+
+ it "show an existing pool" do
+ @pool = FactoryGirl.create :pool
+
+ get :show, :id => @pool.id
+
+ assert_pool_api_success_response((a)pool.name,
+ @pool.pool_family.name,
+ @pool.pool_family.id,
+ "#{(a)pool.quota.maximum_running_instances}",
+ "#{(a)pool.enabled}")
+ end
+
+ it "show a missing pool" do
+ get :show, :id => -1
+
+ response.status.should be_eql(404)
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/error/message").text.should == "Couldn't find Pool with id=-1"
+ end
+
+ end
+
+ describe "#update" do
+
+ it "update with all expected params" do
+ # we will receive unlimited quota if
+ # maximum_running_instances is not specified
+ # <quota></quota> denotes unlmited quota
+ xmldata = "
+ <pool>
+ <name>#{@test_pool_name}</name>
+ <pool_family_id>#{(a)pool_family.id}</pool_family_id>
+ <enabled>true</enabled>
+ </pool>"
+ post :create, Hash.from_xml(xmldata)
+
+ assert_pool_api_success_response(@test_pool_name,
+ @pool_family.name,
+ @pool_family.id,
+ "", #unlimited
+ "true")
+
+ xml = Nokogiri::XML(response.body)
+ pool_id = xml.xpath("/pool/@id").text
+
+ xmldata = "
+ <pool>
+ <name>pool-updated</name>
+ <pool_family_id>#{(a)pool_family.id}</pool_family_id>
+ <enabled>false</enabled>
+ <quota>
+ <maximum_running_instances>1002</maximum_running_instances>
+ </quota>
+ </pool>"
+ put :update, :id => pool_id, :pool => Hash.from_xml(xmldata)["pool"]
+
+ assert_pool_api_success_response("pool-updated",
+ @pool_family.name,
+ @pool_family.id,
+ "1002",
+ "false")
+ end
+
+ it "update missing pool" do
+ xmldata = "<pool><name>missing-pool</name></pool>"
+ put :update, :id => -1, :pool => Hash.from_xml(xmldata)["pool"]
+
+ response.status.should be_eql(404)
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/error/message").text.should == "Couldn't find Pool with id=-1"
+ end
+
+ it "update with blank name" do
+ @pool = FactoryGirl.create :pool
+ xmldata = "<pool><name></name></pool>"
+ put :update, :id => @pool.id, :pool => Hash.from_xml(xmldata)["pool"]
+
+ response.status.should be_eql(400)
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/errors/error/message").text.should == "Name can't be blank"
+ end
+
+ end
+
+ end
+
+
context "JSON format responses for " do
before do
accept_json
--
1.7.7.6
11 years, 9 months