From: Tomas Sedovic <[email protected]>

https://bugzilla.redhat.com/show_bug.cgi?id=640301

This allows the users to edit a URL of a provider that's been previously added
to the database.

Note that the backend provider must not change, this is only for cases when
the URL entry point changes. You can't use this to switch from EC2 to
Rackspace, for example.

Since actually swapping the provider backend would require some additional
work and possibly some user intervention, it would be better as separate
feature.
---
 src/app/controllers/provider_controller.rb |   29 +++++++++++++++++++++------
 src/app/views/provider/_form.haml          |   13 ++++++-----
 src/app/views/provider/edit.haml           |    1 +
 3 files changed, 30 insertions(+), 13 deletions(-)
 create mode 100644 src/app/views/provider/edit.haml

diff --git a/src/app/controllers/provider_controller.rb 
b/src/app/controllers/provider_controller.rb
index 189c5cb..da5c9bb 100644
--- a/src/app/controllers/provider_controller.rb
+++ b/src/app/controllers/provider_controller.rb
@@ -57,7 +57,7 @@ class ProviderController < ApplicationController
 
     if params[:test_connection]
       test_connection(@provider)
-      redirect_to :action => "new", :provider => {:name => @provider.name, 
:url => @provider.url}
+      render :action => "new"
     else
       @provider.set_cloud_type!
       if @provider.save && @provider.populate_hardware_profiles
@@ -73,16 +73,29 @@ class ProviderController < ApplicationController
 
   def update
     require_privilege(Privilege::PROVIDER_MODIFY)
+    @providers = Provider.list_for_user(@current_user, 
Privilege::PROVIDER_MODIFY)
     @provider = Provider.find(:first, :conditions => {:id => 
params[:provider][:id]})
-    @provider.name = params[:provider][:name]
+    previous_cloud_type = @provider.cloud_type
 
-    if @provider.save
-      flash[:notice] = "Provider updated."
-      redirect_to :action => "show", :id => @provider
-    else
+    @provider.update_attributes(params[:provider])
+    if params[:test_connection]
+      test_connection(@provider)
       render :action => "edit"
+    else
+      @provider.set_cloud_type!
+      if previous_cloud_type != @provider.cloud_type
+        @provider.errors.add :url, "points to a different provider"
+      end
+
+      if @provider.errors.empty? and @provider.save
+        flash[:notice] = "Provider updated."
+        redirect_to :action => "show", :id => @provider
+      else
+        flash[:notice] = "Cannot update the provider."
+        render :action => "edit"
+      end
+      kick_condor
     end
-    kick_condor
   end
 
   def destroy
@@ -130,10 +143,12 @@ class ProviderController < ApplicationController
   end
 
   def test_connection(provider)
+    @provider.errors.clear
     if @provider.connect
       flash[:notice] = "Successfuly Connected to Provider"
     else
       flash[:notice] = "Failed to Connect to Provider"
+      @provider.errors.add :url
     end
   end
 
diff --git a/src/app/views/provider/_form.haml 
b/src/app/views/provider/_form.haml
index 6f03d7d..14cd292 100644
--- a/src/app/views/provider/_form.haml
+++ b/src/app/views/provider/_form.haml
@@ -1,12 +1,13 @@
 - readonly = controller.action_name == 'show' ? true : false
 - new_provider = ['new', 'create'].include? controller.action_name
+- edit_provider = ['edit', 'update'].include? controller.action_name
 = render :partial => 'providers'
 #details.grid_13
   %nav.subsubnav
     = render_navigation(:level => 4)
   - if new_provider
     - form_action = 'create'
-  - elsif controller.action_name == 'edit'
+  - elsif edit_provider
     - form_action = 'update'
   - form_for @provider, :url => {:controller => :provider, :action => 
form_action}, :class => "dcloud_form" do |f|
     %fieldset
@@ -23,12 +24,12 @@
       %div.grid_4.omega
         = f.error_message_on :url, 'URL '
         = f.error_message_on :name, 'Name '
-      = f.text_field :name, :title => t('.provider_name'), :value => 
(@provider.name if @provider), :disabled => ('disabled' if 
controller.action_name == 'show'), :class => "clear grid_4 alpha"
-      = f.text_field :url, :title => t('.provider_url'), :class => 
'emailinput', :value => (@provider.url if @provider), :disabled => ('disabled' 
unless new_provider), :class => "grid_5"
-      - if controller.action_name == 'edit':
+      = f.text_field :name, :title => t('.provider_name'), :value => 
(@provider.name if @provider), :disabled => ('disabled' if readonly), :class => 
"clear grid_4 alpha"
+      = f.text_field :url, :title => t('.provider_url'), :class => 
'emailinput', :value => (@provider.url if @provider), :disabled => ('disabled' 
if readonly), :class => "grid_5"
+      - if edit_provider:
         = f.hidden_field :id, :value => @provider.id
       .clear.prefix_4.grid_5.suffix_4.alpha.omega
-        - if !Provider.exists?(@provider)
+        - if new_provider or edit_provider
           %span
           (
           %button.linkbutton.nospace{ :type => 'submit', :value => 
t('.test_connection'), :name => 'test_connection', :id => 'test_connection' }<>
@@ -40,7 +41,7 @@
           *
         \-
         = t('.required_field')
-    - if controller.action_name == 'edit'
+    - if edit_provider
       %input{ :type => 'submit', :value => t(:save), :name => 'save_provider', 
:id => 'save_provider' }
     - elsif new_provider
       %input{ :type => 'submit', :value => t(:add), :name => 'add_provider', 
:id => 'add_provider' }
diff --git a/src/app/views/provider/edit.haml b/src/app/views/provider/edit.haml
new file mode 100644
index 0000000..c66fabf
--- /dev/null
+++ b/src/app/views/provider/edit.haml
@@ -0,0 +1 @@
+= render :partial => 'form'
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to