From: martyntaylor mtaylor@redhat.com
--- src/app/controllers/pool_controller.rb | 39 +++++++++++++++++++++++++++++-- src/app/views/pool/quota.html.erb | 2 + src/config/environment.rb | 3 +- 3 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/src/app/controllers/pool_controller.rb b/src/app/controllers/pool_controller.rb index 632d0cb..204eb80 100644 --- a/src/app/controllers/pool_controller.rb +++ b/src/app/controllers/pool_controller.rb @@ -151,13 +151,15 @@ class PoolController < ApplicationController
def new_quota @pool = Pool.find(params[:id]) - require_privilege(Privilege::POOL_MODIFY, @pool) + require_privilege(Privilege::QUOTA_MODIFY, @pool) end
def create_quota + #TODO Should be in Transaction + @pool = Pool.find(params[:pool][:id]) + if !Quota.exists?(@pool.quota_id) - @pool = Pool.find(params[:pool][:id]) - require_privilege(Privilege::POOL_MODIFY, @pool) + require_privilege(Privilege::QUOTA_MODIFY, @pool)
@quota = Quota.new(params[:quota]) @quota.save! @@ -165,10 +167,41 @@ class PoolController < ApplicationController @pool.quota_id = @quota @pool.save!
+ flash[:notice] = "Quota Created!" redirect_to :action => 'quota', :id => @pool else errors.add("quota_id", "There already exists a quota for this pool") + render :action => :new_quota + end + end + + def edit_quota + @pool = Pool.find(params[:id]) + @quota = Quota.find(@pool.quota_id) + require_privilege(Privilege::QUOTA_MODIFY, @pool) + end + + def update_quota + @pool = Pool.find(params[:pool][:id]) + require_privilege(Privilege::QUOTA_MODIFY, @pool) + + #TODO Should check to make sure that the new quota values greater than the current usage + @quota = Quota.find(@pool.quota_id) + if @quota.update_attributes(params[:quota]) + flash[:notice] = "Quota updated!" + redirect_to :controller => 'pool', :action => 'quota', :id => @pool + else + render :action => :edit_quota end end
+ def delete_quota + @pool = Pool.find(params[:id]) + @quota = Quota.find(@pool.quota_id) + require_privilege(Privilege::QUOTA_MODIFY, @pool) + if @quota.delete + flash[:notice] = "Quota Deleted!" + redirect_to :controller => 'pool', :action => 'quota', :id => @pool + end + end end \ No newline at end of file diff --git a/src/app/views/pool/quota.html.erb b/src/app/views/pool/quota.html.erb index 09b227e..8320fd1 100644 --- a/src/app/views/pool/quota.html.erb +++ b/src/app/views/pool/quota.html.erb @@ -53,4 +53,6 @@ </tr> </tbody> </table> + <%= link_to "Edit", {:controller => "pool", :action => "edit_quota", :id => @pool}, :class=>"actionlink"%> + <%= link_to "Delete", {:controller => "pool", :action => "delete_quota", :id => @pool}, :class=>"actionlink"%> <% end %> \ No newline at end of file diff --git a/src/config/environment.rb b/src/config/environment.rb index 9f0fa4f..eefd3a4 100644 --- a/src/config/environment.rb +++ b/src/config/environment.rb @@ -43,7 +43,7 @@ Rails::Initializer.run do |config| config.gem "gettext", :lib => "gettext_rails" config.gem "gettext", :lib => "gettext_activerecord" config.gem "authlogic" - config.gem "deltacloud-cliesrc/config/environment.rbnt", :lib => "deltacloud" + config.gem "deltacloud-client", :lib => "deltacloud" config.gem "haml" config.gem "will_paginate"
@@ -77,4 +77,5 @@ Rails::Initializer.run do |config| # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] # config.i18n.default_locale = :de
+ end