Skip to content

Commit

Permalink
768118 - System detail pane now has "Remove System"
Browse files Browse the repository at this point in the history
  • Loading branch information
knowncitizen committed Dec 20, 2011
1 parent 188b416 commit 22b1586
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
20 changes: 19 additions & 1 deletion src/app/controllers/systems_controller.rb
Expand Up @@ -14,7 +14,7 @@ class SystemsController < ApplicationController
include AutoCompleteSearch
include SystemsHelper

before_filter :find_system, :except =>[:index, :auto_complete_search, :items, :environments, :env_items, :bulk_destroy, :new, :create]
before_filter :find_system, :except =>[:index, :auto_complete_search, :items, :environments, :env_items, :bulk_destroy, :destroy, :new, :create]
before_filter :find_systems, :only=>[:bulk_destroy]

skip_before_filter :authorize
Expand Down Expand Up @@ -51,6 +51,7 @@ def rules
:edit => read_system,
:show => read_system,
:facts => read_system,
:destroy=> delete_systems,
:bulk_destroy => delete_systems
}
end
Expand Down Expand Up @@ -241,6 +242,23 @@ def bulk_destroy
render :text=>e, :status=>500
end

def destroy
id = params[:id]
system = find_system
system.destroy
if system.destroyed?
notice _("#{system.name} Removed Successfully")
#render and do the removal in one swoop!
render :partial => "common/list_remove", :locals => {:id => id, :name=>controller_display_name} and return
end
errors "", {:list_items => system.errors.to_a}
render :text => @system.errors, :status=>:ok
rescue Exception => e
errors e
render :text=>e, :status=>500
end



private

Expand Down
2 changes: 1 addition & 1 deletion src/app/controllers/users_controller.rb
@@ -1,4 +1,4 @@
#
#
# Copyright 2011 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
Expand Down
4 changes: 4 additions & 0 deletions src/app/views/systems/_edit.html.haml
Expand Up @@ -3,6 +3,10 @@
= content_for :title do
#{@system.name}

= content_for :remove_item do
-if @system.deletable?
= link_to _("Remove System"), { :controller => "systems", :action => "destroy" }, :confirm => _('Are you sure you want to remove this system?'), :method => :delete, :class=>"remove_item", :remote=>true

= content_for :navigation do
= render_navigation(:items => systems_navigation, :expand_all => true, :level => 1)

Expand Down
2 changes: 1 addition & 1 deletion src/app/views/users/_edit.html.haml
Expand Up @@ -3,7 +3,7 @@

= content_for :remove_item do
-if @user.deletable?
= link_to _("Remove User"), { :controller => "users", :action => "destroy" }, :confirm => _('Are you sure?'), :method => :delete, :class=>"remove_item", :remote=>true
= link_to _("Remove User"), { :controller => "users", :action => "destroy" }, :confirm => _('Are you sure you want to remove this user?'), :method => :delete, :class=>"remove_item", :remote=>true

= content_for :navigation do
= render_navigation(:items=>user_navigation, :expand_all => true, :level => 1)
Expand Down
2 changes: 1 addition & 1 deletion src/config/routes.rb
Expand Up @@ -64,7 +64,7 @@
end
end

resources :systems, :except => [:destroy] do
resources :systems do
resources :system_packages, :only => {} do
collection do
put :add
Expand Down
13 changes: 13 additions & 0 deletions src/spec/controllers/systems_controller_spec.rb
Expand Up @@ -244,6 +244,19 @@
end
end

describe 'delete a single system' do
before (:each) do
@system = System.create!(:name=>"bar", :environment => @environment, :cp_type=>"system", :facts=>{"Test" => ""})
@id = @system.id
System.stub(:find).and_return @system
end
it "should delete the system" do
@system.should_receive(:destroy)
delete :destroy, {:id => @id, :system =>@system}
response.should be_success
end
end

describe 'creating a system' do
render_views

Expand Down

0 comments on commit 22b1586

Please sign in to comment.