[PATCH aggregator] Consolidating 2 separate registration_service_spec-s.
by lmartinc@redhat.com
From: Ladislav Martincik <lmartinc(a)redhat.com>
- Fixing validations for User with maximum allowing blank
- Merged 2 spec files for registration service to one file
---
src/app/models/user.rb | 5 +-
src/spec/models/registration_service_spec.rb | 64 ------------------------
src/spec/services/registration_service_spec.rb | 37 ++++++++++++++
3 files changed, 39 insertions(+), 67 deletions(-)
delete mode 100644 src/spec/models/registration_service_spec.rb
diff --git a/src/app/models/user.rb b/src/app/models/user.rb
index aed6fe6..7942ae4 100644
--- a/src/app/models/user.rb
+++ b/src/app/models/user.rb
@@ -28,9 +28,8 @@ class User < ActiveRecord::Base
belongs_to :quota, :autosave => true
accepts_nested_attributes_for :quota
- validates_length_of :first_name, :maximum => 255
- validates_length_of :last_name, :maximum => 255
-
+ validates_length_of :first_name, :maximum => 255, :allow_blank => true
+ validates_length_of :last_name, :maximum => 255, :allow_blank => true
# authlogic's password confirmation doesn't fire up when we fill in the
# confirmation field but leave the password field blank. We have to check
diff --git a/src/spec/models/registration_service_spec.rb b/src/spec/models/registration_service_spec.rb
deleted file mode 100644
index 2a97d11..0000000
--- a/src/spec/models/registration_service_spec.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-require 'spec_helper'
-
-describe RegistrationService do
- fixtures :all
- before(:each) do
- @tuser = Factory :tuser
- end
-
- it "should initialize a new instance given valid attributes" do
- RegistrationService.new(@tuser)
- end
-
- describe "#save" do
-
- context "adding valid user with no errors" do
- it "should create user, pool and self-service permission" do
- user = User.new({:login => 'gooduser',
- :email => 'guser(a)example.com',
- :password => 'password',
- :password_confirmation => 'password'})
- r = RegistrationService.new(user)
- end
- end
-
- context "save fails" do
- it "should return errors on user when user is missing required field" do
- user = User.new(:login => 'baduser')
- r = RegistrationService.new(user)
- r.save.should be_false
- user.errors.empty?.should be_false
- user.errors.find_all {|attr,msg|
- ["email", "password", "password_confirmation"].include?(attr).should be_true
- }
- end
-
- it "should return pool errors if pool create fails" do
- #TODO: implement this test. We should check this, but not sure of best
- # way right now.
- end
- end
- end
-
- it "should register a user with default pool/quota/role when default settings set" do
- @user = Factory :user
- @pool = Factory(:pool, :name => "default_pool")
- @role = Role.find_by_name("Instance Creator and User")
- @quota = Factory :quota
-
- MetadataObject.set("allow_self_service_logins", "true")
- MetadataObject.set("self_service_default_pool", @pool)
- MetadataObject.set("self_service_default_role", @role)
- MetadataObject.set("self_service_default_quota", @quota)
-
- @registration_service = RegistrationService.new(@user)
- @registration_service.save
-
- @pools = Pool.list_for_user(@user, Privilege::INSTANCE_VIEW)
- @pools.size.should == 1
- @pools[0].name.should == "default_pool"
-
- @user.quota.maximum_running_instances.should == @quota.maximum_running_instances
- @user.quota.maximum_total_instances.should == @quota.maximum_total_instances
- end
-end
diff --git a/src/spec/services/registration_service_spec.rb b/src/spec/services/registration_service_spec.rb
index 6764715..1d17ba2 100644
--- a/src/spec/services/registration_service_spec.rb
+++ b/src/spec/services/registration_service_spec.rb
@@ -10,6 +10,43 @@ describe RegistrationService do
Factory.create(:default_pool_metadata)
end
+ describe "with validations" do
+
+ it "should return errors on user when user is missing required fields" do
+ user = User.new(:login => 'baduser')
+ r = RegistrationService.new(user)
+ r.save.should be_false
+ user.errors.empty?.should be_false
+ user.errors.find_all do |attr,msg|
+ ["email","password","password_confirmation"].include?(attr).should be_true
+ end
+ end
+
+ it "should register a user with default pool/quota/role when default settings set" do
+ @user = Factory :user
+ @pool = Factory(:pool, :name => "default_pool")
+ privilege = Privilege.find_by_name('instance_view')
+ @role = Factory(:role, :privileges => [privilege])
+ @quota = Factory :quota
+
+ MetadataObject.set("allow_self_service_logins", "true")
+ MetadataObject.set("self_service_default_pool", @pool)
+ MetadataObject.set("self_service_default_role", @role)
+ MetadataObject.set("self_service_default_quota", @quota)
+
+ @registration_service = RegistrationService.new(@user)
+ @registration_service.save
+
+ @pools = Pool.list_for_user(@user, Privilege::INSTANCE_VIEW)
+ @pools.length.should == 1
+ @pools[0].name.should == "default_pool"
+
+ @user.quota.maximum_running_instances.should == @quota.maximum_running_instances
+ @user.quota.maximum_total_instances.should == @quota.maximum_total_instances
+ end
+
+ end
+
describe "with quota" do
it "passed via nested attributes to user model" do
--
1.7.3.1
13 years, 6 months
[PATCH aeolus] BZ#654663/BZ#651353 Added Validation to Name field on Provider Model
by Martyn Taylor
From: Martyn Taylor <mtaylor(a)redhat.com>
---
src/app/models/provider.rb | 3 +++
src/spec/models/provider_spec.rb | 5 ++++-
2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index 6ec3cc3..c203d1f 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -34,6 +34,9 @@ class Provider < ActiveRecord::Base
validates_presence_of :cloud_type
validates_presence_of :url
+ validates_format_of :name, :with => /^[\w -]*$/n, :message => "must only contain: numbers, letters, spaces, '_' and '-'"
+ validates_length_of :name, :maximum => 255
+
has_many :permissions, :as => :permission_object, :dependent => :destroy,
:include => [:role],
:order => "permissions.id ASC"
diff --git a/src/spec/models/provider_spec.rb b/src/spec/models/provider_spec.rb
index fcec747..1b86f92 100644
--- a/src/spec/models/provider_spec.rb
+++ b/src/spec/models/provider_spec.rb
@@ -17,7 +17,10 @@ describe Provider do
end
it "should require a valid name" do
- [nil, ""].each do |invalid_value|
+ long_name = ""
+ 256.times { long_name << 'a' }
+
+ [nil, "", "£*(&", long_name].each do |invalid_value|
@provider.name = invalid_value
@provider.should_not be_valid
end
--
1.7.2.3
13 years, 6 months
Re: [deltacloud-devel] [PATCH aggregator] Comment Pool Cucumber test until it's disabled
by Martyn Taylor
Nack, Just one minor point.
The New Pool functionality is not turned off per se, we have just disabled the link to the new pool page. We can test navigating straight to the New Pool Page URL like in this scenario: Scenario: Enter invalid characters into Name field
For this scenario: Scenario: Create a new Pool
I think it might be better to just comment out the navigation and start the scenario from the new pool page.
----- Original Message -----
From: lmartinc(a)redhat.com
To: deltacloud-devel(a)lists.fedorahosted.org
Sent: Thursday, November 18, 2010 12:52:05 PM GMT +00:00 GMT Britain, Ireland, Portugal
Subject: [deltacloud-devel] [PATCH aggregator] Comment Pool Cucumber test until it's disabled
From: Ladislav Martincik <lmartinc(a)redhat.com>
---
src/features/pool.feature | 108 +++++++++++++++++++++++----------------------
1 files changed, 55 insertions(+), 53 deletions(-)
diff --git a/src/features/pool.feature b/src/features/pool.feature
index b85b930..51ad615 100644
--- a/src/features/pool.feature
+++ b/src/features/pool.feature
@@ -7,65 +7,67 @@ Feature: Manage Pools
Given I am an authorised user
And I am logged in
- Scenario: Create a new Pool
- Given I am on the pools page
- And there is not a pool named "mockpool"
- When I follow "New pool"
- Then I should be on the new pool page
- And I should see "Create a new Pool"
- When I fill in "pool_name" with "mockpool"
- And I press "Save"
- Then I should be on the show pool page
- And I should see "Pool added"
- And I should see "mockpool"
- And I should have a pool named "mockpool"
+ # NOTE: New pool functionality is turned of for now
+ #
+ # Scenario: Create a new Pool
+ # Given I am on the pools page
+ # And there is not a pool named "mockpool"
+ # When I follow "New pool"
+ # Then I should be on the new pool page
+ # And I should see "Create a new Pool"
+ # When I fill in "pool_name" with "mockpool"
+ # And I press "Save"
+ # Then I should be on the show pool page
+ # And I should see "Pool added"
+ # And I should see "mockpool"
+ # And I should have a pool named "mockpool"
- Scenario: View Pool's Hardware Profiles
- Given I have Pool Creator permissions on a pool named "mockpool"
- And the Pool has the following Hardware Profiles:
- | name | memory | cpu |storage | architecture |
- | m1-small | 1740 | 2 | 160.0 | i386 |
- | m1-large | 4096 | 4 | 850.0 | x86_64 |
- | m1-xlarge | 8192 | 8 | 1690.0 | x86_64 |
- And I am on the instances page
- When I follow "mockpool"
- Then I should be on the show pool page
- When I follow "Hardware Profiles"
- Then I should see the following:
- | m1-small | 1740 | 2 | 160.0 | i386 |
- | m1-large | 4096 | 4 | 850.0 | x86_64 |
- | m1-xlarge | 8192 | 8 | 1690.0 | x86_64 |
+ # Scenario: View Pool's Hardware Profiles
+ # Given I have Pool Creator permissions on a pool named "mockpool"
+ # And the Pool has the following Hardware Profiles:
+ # | name | memory | cpu |storage | architecture |
+ # | m1-small | 1740 | 2 | 160.0 | i386 |
+ # | m1-large | 4096 | 4 | 850.0 | x86_64 |
+ # | m1-xlarge | 8192 | 8 | 1690.0 | x86_64 |
+ # And I am on the instances page
+ # When I follow "mockpool"
+ # Then I should be on the show pool page
+ # When I follow "Hardware Profiles"
+ # Then I should see the following:
+ # | m1-small | 1740 | 2 | 160.0 | i386 |
+ # | m1-large | 4096 | 4 | 850.0 | x86_64 |
+ # | m1-xlarge | 8192 | 8 | 1690.0 | x86_64 |
- Scenario: View Pool's Realms
- Given I have Pool Creator permissions on a pool named "mockpool"
- And the Pool has the following Realms named "Europe, United States"
- And I am on the instances page
- When I follow "mockpool"
- Then I should be on the show pool page
- When I follow "Realms"
- Then I should see "Europe"
- And I should see "United States"
+ # Scenario: View Pool's Realms
+ # Given I have Pool Creator permissions on a pool named "mockpool"
+ # And the Pool has the following Realms named "Europe, United States"
+ # And I am on the instances page
+ # When I follow "mockpool"
+ # Then I should be on the show pool page
+ # When I follow "Realms"
+ # Then I should see "Europe"
+ # And I should see "United States"
- @tag
- Scenario: View Pool's Quota Usage
- Given I have Pool Creator permissions on a pool named "mockpool"
- And the Pool has a quota with following capacities:
- | resource | capacity |
- | maximum_running_instances | 10 |
- | maximum_total_instances | 15 |
- | running_instances | 8 |
- | total_instances | 15 |
- And I am on the instances page
- When I follow "mockpool"
- Then I should be on the show pool page
- When I follow "Quota"
- Then I should see the following:
- | Running Instances | 10 | 8 |
- | Total Instances | 15 | 15 |
+ # @tag
+ # Scenario: View Pool's Quota Usage
+ # Given I have Pool Creator permissions on a pool named "mockpool"
+ # And the Pool has a quota with following capacities:
+ # | resource | capacity |
+ # | maximum_running_instances | 10 |
+ # | maximum_total_instances | 15 |
+ # | running_instances | 8 |
+ # | total_instances | 15 |
+ # And I am on the instances page
+ # When I follow "mockpool"
+ # Then I should be on the show pool page
+ # When I follow "Quota"
+ # Then I should see the following:
+ # | Running Instances | 10 | 8 |
+ # | Total Instances | 15 | 15 |
Scenario: Enter invalid characters into Name field
Given I am an authorised user
And I am on the new pool page
When I fill in "pool[name]" with "@%&*())_@!#!"
And I press "Save"
- Then I should see "Name must only contain: numbers, letters, spaces, '_' and '-'"
\ No newline at end of file
+ Then I should see "Name must only contain: numbers, letters, spaces, '_' and '-'"
--
1.7.3.1
_______________________________________________
deltacloud-devel mailing list
deltacloud-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/deltacloud-devel
13 years, 7 months
[PATCH aggregator] Comment Pool Cucumber test until it's disabled
by lmartinc@redhat.com
From: Ladislav Martincik <lmartinc(a)redhat.com>
---
src/features/pool.feature | 108 +++++++++++++++++++++++----------------------
1 files changed, 55 insertions(+), 53 deletions(-)
diff --git a/src/features/pool.feature b/src/features/pool.feature
index b85b930..51ad615 100644
--- a/src/features/pool.feature
+++ b/src/features/pool.feature
@@ -7,65 +7,67 @@ Feature: Manage Pools
Given I am an authorised user
And I am logged in
- Scenario: Create a new Pool
- Given I am on the pools page
- And there is not a pool named "mockpool"
- When I follow "New pool"
- Then I should be on the new pool page
- And I should see "Create a new Pool"
- When I fill in "pool_name" with "mockpool"
- And I press "Save"
- Then I should be on the show pool page
- And I should see "Pool added"
- And I should see "mockpool"
- And I should have a pool named "mockpool"
+ # NOTE: New pool functionality is turned of for now
+ #
+ # Scenario: Create a new Pool
+ # Given I am on the pools page
+ # And there is not a pool named "mockpool"
+ # When I follow "New pool"
+ # Then I should be on the new pool page
+ # And I should see "Create a new Pool"
+ # When I fill in "pool_name" with "mockpool"
+ # And I press "Save"
+ # Then I should be on the show pool page
+ # And I should see "Pool added"
+ # And I should see "mockpool"
+ # And I should have a pool named "mockpool"
- Scenario: View Pool's Hardware Profiles
- Given I have Pool Creator permissions on a pool named "mockpool"
- And the Pool has the following Hardware Profiles:
- | name | memory | cpu |storage | architecture |
- | m1-small | 1740 | 2 | 160.0 | i386 |
- | m1-large | 4096 | 4 | 850.0 | x86_64 |
- | m1-xlarge | 8192 | 8 | 1690.0 | x86_64 |
- And I am on the instances page
- When I follow "mockpool"
- Then I should be on the show pool page
- When I follow "Hardware Profiles"
- Then I should see the following:
- | m1-small | 1740 | 2 | 160.0 | i386 |
- | m1-large | 4096 | 4 | 850.0 | x86_64 |
- | m1-xlarge | 8192 | 8 | 1690.0 | x86_64 |
+ # Scenario: View Pool's Hardware Profiles
+ # Given I have Pool Creator permissions on a pool named "mockpool"
+ # And the Pool has the following Hardware Profiles:
+ # | name | memory | cpu |storage | architecture |
+ # | m1-small | 1740 | 2 | 160.0 | i386 |
+ # | m1-large | 4096 | 4 | 850.0 | x86_64 |
+ # | m1-xlarge | 8192 | 8 | 1690.0 | x86_64 |
+ # And I am on the instances page
+ # When I follow "mockpool"
+ # Then I should be on the show pool page
+ # When I follow "Hardware Profiles"
+ # Then I should see the following:
+ # | m1-small | 1740 | 2 | 160.0 | i386 |
+ # | m1-large | 4096 | 4 | 850.0 | x86_64 |
+ # | m1-xlarge | 8192 | 8 | 1690.0 | x86_64 |
- Scenario: View Pool's Realms
- Given I have Pool Creator permissions on a pool named "mockpool"
- And the Pool has the following Realms named "Europe, United States"
- And I am on the instances page
- When I follow "mockpool"
- Then I should be on the show pool page
- When I follow "Realms"
- Then I should see "Europe"
- And I should see "United States"
+ # Scenario: View Pool's Realms
+ # Given I have Pool Creator permissions on a pool named "mockpool"
+ # And the Pool has the following Realms named "Europe, United States"
+ # And I am on the instances page
+ # When I follow "mockpool"
+ # Then I should be on the show pool page
+ # When I follow "Realms"
+ # Then I should see "Europe"
+ # And I should see "United States"
- @tag
- Scenario: View Pool's Quota Usage
- Given I have Pool Creator permissions on a pool named "mockpool"
- And the Pool has a quota with following capacities:
- | resource | capacity |
- | maximum_running_instances | 10 |
- | maximum_total_instances | 15 |
- | running_instances | 8 |
- | total_instances | 15 |
- And I am on the instances page
- When I follow "mockpool"
- Then I should be on the show pool page
- When I follow "Quota"
- Then I should see the following:
- | Running Instances | 10 | 8 |
- | Total Instances | 15 | 15 |
+ # @tag
+ # Scenario: View Pool's Quota Usage
+ # Given I have Pool Creator permissions on a pool named "mockpool"
+ # And the Pool has a quota with following capacities:
+ # | resource | capacity |
+ # | maximum_running_instances | 10 |
+ # | maximum_total_instances | 15 |
+ # | running_instances | 8 |
+ # | total_instances | 15 |
+ # And I am on the instances page
+ # When I follow "mockpool"
+ # Then I should be on the show pool page
+ # When I follow "Quota"
+ # Then I should see the following:
+ # | Running Instances | 10 | 8 |
+ # | Total Instances | 15 | 15 |
Scenario: Enter invalid characters into Name field
Given I am an authorised user
And I am on the new pool page
When I fill in "pool[name]" with "@%&*())_@!#!"
And I press "Save"
- Then I should see "Name must only contain: numbers, letters, spaces, '_' and '-'"
\ No newline at end of file
+ Then I should see "Name must only contain: numbers, letters, spaces, '_' and '-'"
--
1.7.3.1
13 years, 7 months
(no subject)
by Martyn Taylor
Please ignore previous submission for this patch
13 years, 7 months
[PATCH aggregator] QuotaController renamed to QuotasController
by Jan Provazník
From: Jan Provaznik <jprovazn(a)redhat.com>
---
src/app/controllers/quota_controller.rb | 104 ------------------------------
src/app/controllers/quotas_controller.rb | 104 ++++++++++++++++++++++++++++++
src/app/views/pools/show.haml | 2 +-
src/app/views/quota/edit.haml | 13 ----
src/app/views/quota/show.haml | 21 ------
src/app/views/quotas/edit.haml | 13 ++++
src/app/views/quotas/show.haml | 21 ++++++
7 files changed, 139 insertions(+), 139 deletions(-)
delete mode 100644 src/app/controllers/quota_controller.rb
create mode 100644 src/app/controllers/quotas_controller.rb
delete mode 100644 src/app/views/quota/edit.haml
delete mode 100644 src/app/views/quota/show.haml
create mode 100644 src/app/views/quotas/edit.haml
create mode 100644 src/app/views/quotas/show.haml
diff --git a/src/app/controllers/quota_controller.rb b/src/app/controllers/quota_controller.rb
deleted file mode 100644
index 04537ac..0000000
--- a/src/app/controllers/quota_controller.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-#
-# Copyright (C) 2009 Red Hat, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA. A copy of the GNU General Public License is
-# also available at http://www.gnu.org/copyleft/gpl.html.
-
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-
-class QuotaController < ApplicationController
- before_filter :require_user
-
- def show
- @parent = get_parent_object(params)
- @parent_type = params[:parent_type]
- @quota = @parent.quota
-
- require_privilege(Privilege::QUOTA_VIEW, @parent)
- end
-
- def edit
- @parent = get_parent_object(params)
- @parent_type = params[:parent_type]
- @name = get_parent_name(@parent, @parent_type)
-
- @quota = @parent.quota
-
- require_privilege(Privilege::QUOTA_MODIFY, @parent)
- end
-
- def update
- @parent = @parent = get_parent_object(params)
- @parent_type = params[:parent_type]
- require_privilege(Privilege::QUOTA_MODIFY, @parent)
-
- @quota = @parent.quota
- @name = get_parent_name(@parent, @parent_type)
- if @quota.update_attributes(params[:quota])
- flash[:notice] = "Quota updated!"
- redirect_to :action => 'show', :id => @parent, :parent_type => @parent_type
- else
- flash[:notice] = "Could not update quota, please check you have entered valid values"
- render :action => "edit"
- end
- end
-
- def reset
- @parent = @parent = get_parent_object(params)
- @parent_type = params[:parent_type]
- require_privilege(Privilege::QUOTA_MODIFY, @parent)
-
- @quota = @parent.quota
- @quota.maximum_running_instances = Quota::NO_LIMIT
- @quota.maximum_total_instances = Quota::NO_LIMIT
-
- if @quota.save!
- flash[:notice] = "Quota updated!"
- end
- redirect_to :action => 'show', :id => @parent, :parent_type => @parent_type
- end
-
- private
- def get_parent_object(params)
- if params[:parent_type] == "pool"
- return Pool.find(params[:id])
- elsif params[:parent_type] == "cloud_account"
- return CloudAccount.find(params[:id])
- end
- #TODO Throw no match to pool or cloud account exception
- end
-
- def get_parent_name(parent, parent_type)
- if parent_type == "pool"
- return parent.name
- elsif parent_type == "cloud_account"
- return parent.username
- end
- #TODO Throw no match to pool or cloud account exception
- end
-
- def check_params_infinite_limits(params)
- params.each_pair do |key, value|
- if value == ""
- params[key] = Quota::NO_LIMIT
- end
- end
- return params
- end
-
-
-end
diff --git a/src/app/controllers/quotas_controller.rb b/src/app/controllers/quotas_controller.rb
new file mode 100644
index 0000000..e9937fb
--- /dev/null
+++ b/src/app/controllers/quotas_controller.rb
@@ -0,0 +1,104 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+
+class QuotasController < ApplicationController
+ before_filter :require_user
+
+ def show
+ @parent = get_parent_object(params)
+ @parent_type = params[:parent_type]
+ @quota = @parent.quota
+
+ require_privilege(Privilege::QUOTA_VIEW, @parent)
+ end
+
+ def edit
+ @parent = get_parent_object(params)
+ @parent_type = params[:parent_type]
+ @name = get_parent_name(@parent, @parent_type)
+
+ @quota = @parent.quota
+
+ require_privilege(Privilege::QUOTA_MODIFY, @parent)
+ end
+
+ def update
+ @parent = @parent = get_parent_object(params)
+ @parent_type = params[:parent_type]
+ require_privilege(Privilege::QUOTA_MODIFY, @parent)
+
+ @quota = @parent.quota
+ @name = get_parent_name(@parent, @parent_type)
+ if @quota.update_attributes(params[:quota])
+ flash[:notice] = "Quota updated!"
+ redirect_to :action => 'show', :id => @parent, :parent_type => @parent_type
+ else
+ flash[:notice] = "Could not update quota, please check you have entered valid values"
+ render :action => "edit"
+ end
+ end
+
+ def reset
+ @parent = @parent = get_parent_object(params)
+ @parent_type = params[:parent_type]
+ require_privilege(Privilege::QUOTA_MODIFY, @parent)
+
+ @quota = @parent.quota
+ @quota.maximum_running_instances = Quota::NO_LIMIT
+ @quota.maximum_total_instances = Quota::NO_LIMIT
+
+ if @quota.save!
+ flash[:notice] = "Quota updated!"
+ end
+ redirect_to :action => 'show', :id => @parent, :parent_type => @parent_type
+ end
+
+ private
+ def get_parent_object(params)
+ if params[:parent_type] == "pool"
+ return Pool.find(params[:id])
+ elsif params[:parent_type] == "cloud_account"
+ return CloudAccount.find(params[:id])
+ end
+ #TODO Throw no match to pool or cloud account exception
+ end
+
+ def get_parent_name(parent, parent_type)
+ if parent_type == "pool"
+ return parent.name
+ elsif parent_type == "cloud_account"
+ return parent.username
+ end
+ #TODO Throw no match to pool or cloud account exception
+ end
+
+ def check_params_infinite_limits(params)
+ params.each_pair do |key, value|
+ if value == ""
+ params[key] = Quota::NO_LIMIT
+ end
+ end
+ return params
+ end
+
+
+end
diff --git a/src/app/views/pools/show.haml b/src/app/views/pools/show.haml
index 8f066d9..229f3e2 100644
--- a/src/app/views/pools/show.haml
+++ b/src/app/views/pools/show.haml
@@ -9,4 +9,4 @@
%li= link_to "User access", {:controller => "permissions", :action => "list", :pool_id => @pool.id, :ajax => true}
%li= link_to "Hardware Profiles", {:action => "hardware_profiles", :id => @pool.id, :ajax => true}
%li= link_to "Realms", {:action => "realms", :id => @pool.id, :ajax => true}
- %li= link_to "Quota", {:controller => "quota", :action => "show", :id => @pool, :parent_type => "pool", :ajax => true}
+ %li= link_to "Quota", {:controller => "quotas", :action => "show", :id => @pool, :parent_type => "pool", :ajax => true}
diff --git a/src/app/views/quota/edit.haml b/src/app/views/quota/edit.haml
deleted file mode 100644
index 87ab25d..0000000
--- a/src/app/views/quota/edit.haml
+++ /dev/null
@@ -1,13 +0,0 @@
-.dcloud_form
- %h2
- Edit Quota for #{@parent_type + ": " + @name}
- %br/
- - form_for @quota, :url => {:controller => :quota, :action => "update", :parent_type => @parent_type}, :class => "dcloud_form" do |f|
- = hidden_field_tag 'id', @parent.id
- = hidden_field_tag 'parent_type', @parent_type
- %ul
- %li
- %label Max Running Instances
- = f.error_message_on :maximum_running_instances, 'maximum_running_instances'
- = f.text_field :maximum_running_instances
- = submit_tag "Save", :class => "submit"
diff --git a/src/app/views/quota/show.haml b/src/app/views/quota/show.haml
deleted file mode 100644
index 1c229a8..0000000
--- a/src/app/views/quota/show.haml
+++ /dev/null
@@ -1,21 +0,0 @@
-- if !@quota
- %h1
- There is no Quota on this #{@parent_type}
-- else
- %table
- %thead
- %tr
- %th{:scope => "col"} Resource
- %th{:scope => "col"} Max Capacity
- %th{:scope => "col"} Used
- %th{:scope => "col"} Available
- %tbody
- - quota_resources = @quota.quota_resources
- - quota_resources.each_value do |quota_resource|
- %tr
- %td= quota_resource.name + " " + quota_resource.unit
- %td= quota_resource.max
- %td= quota_resource.used
- %td= quota_resource.available
- = link_to "Edit", {:action => "edit", :id => @parent, :parent_type => @parent_type}, :class=>"actionlink"
- = link_to "Reset", {:action => "reset", :id => @parent, :parent_type => @parent_type}, :class=>"actionlink"
diff --git a/src/app/views/quotas/edit.haml b/src/app/views/quotas/edit.haml
new file mode 100644
index 0000000..2293b43
--- /dev/null
+++ b/src/app/views/quotas/edit.haml
@@ -0,0 +1,13 @@
+.dcloud_form
+ %h2
+ Edit Quota for #{@parent_type + ": " + @name}
+ %br/
+ - form_for @quota, :url => {:controller => :quotas, :action => "update", :parent_type => @parent_type}, :class => "dcloud_form" do |f|
+ = hidden_field_tag 'id', @parent.id
+ = hidden_field_tag 'parent_type', @parent_type
+ %ul
+ %li
+ %label Max Running Instances
+ = f.error_message_on :maximum_running_instances, 'maximum_running_instances'
+ = f.text_field :maximum_running_instances
+ = submit_tag "Save", :class => "submit"
diff --git a/src/app/views/quotas/show.haml b/src/app/views/quotas/show.haml
new file mode 100644
index 0000000..1c229a8
--- /dev/null
+++ b/src/app/views/quotas/show.haml
@@ -0,0 +1,21 @@
+- if !@quota
+ %h1
+ There is no Quota on this #{@parent_type}
+- else
+ %table
+ %thead
+ %tr
+ %th{:scope => "col"} Resource
+ %th{:scope => "col"} Max Capacity
+ %th{:scope => "col"} Used
+ %th{:scope => "col"} Available
+ %tbody
+ - quota_resources = @quota.quota_resources
+ - quota_resources.each_value do |quota_resource|
+ %tr
+ %td= quota_resource.name + " " + quota_resource.unit
+ %td= quota_resource.max
+ %td= quota_resource.used
+ %td= quota_resource.available
+ = link_to "Edit", {:action => "edit", :id => @parent, :parent_type => @parent_type}, :class=>"actionlink"
+ = link_to "Reset", {:action => "reset", :id => @parent, :parent_type => @parent_type}, :class=>"actionlink"
--
1.7.2.3
13 years, 7 months