From: Tomas Sedovic tsedovic@redhat.com
--- .../image_factory/deployables_controller.rb | 18 +++++++++++++++++- src/app/models/deployable.rb | 6 ++++++ src/app/models/deployment.rb | 5 +++++ src/config/locales/en.yml | 10 +++++++++- src/config/navigation.rb | 2 +- 5 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/src/app/controllers/image_factory/deployables_controller.rb b/src/app/controllers/image_factory/deployables_controller.rb index 5b8210c..917d0d6 100644 --- a/src/app/controllers/image_factory/deployables_controller.rb +++ b/src/app/controllers/image_factory/deployables_controller.rb @@ -50,7 +50,23 @@ class ImageFactory::DeployablesController < ApplicationController end
def multi_destroy - Deployable.destroy(params[:deployables_selected]) + destroyed = [] + failed = [] + Deployable.find(params[:deployables_selected]).each do |deployable| + if check_privilege(Privilege::MODIFY, deployable) and deployable.destroyable? + deployable.destroy + destroyed << deployable.name + else + failed << deployable.name + end + end + + unless destroyed.empty? + flash[:notice] = t('deployables.index.deleted', :count => destroyed.length, :list => destroyed.join(', ')) + end + unless failed.empty? + flash[:error] = t('deployables.index.not_deleted', :count => failed.length, :list => failed.join(', ')) + end redirect_to image_factory_deployables_url end
diff --git a/src/app/models/deployable.rb b/src/app/models/deployable.rb index a360c34..f3d954b 100644 --- a/src/app/models/deployable.rb +++ b/src/app/models/deployable.rb @@ -63,6 +63,8 @@ class Deployable < ActiveRecord::Base validates_uniqueness_of :name validates_length_of :name, :maximum => 255
+ before_destroy :destroyable? + def self.default_privilege_target_type Template end @@ -77,4 +79,8 @@ class Deployable < ActiveRecord::Base id ? Deployable.find(id) : Deployable.new end
+ def destroyable? + deployments.all? {|d| d.destroyable? } + end + end diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb index fedad45..02324f8 100644 --- a/src/app/models/deployment.rb +++ b/src/app/models/deployment.rb @@ -61,6 +61,8 @@ class Deployment < ActiveRecord::Base validates_uniqueness_of :name, :scope => :pool_id validates_length_of :name, :maximum => 1024
+ before_destroy :destroyable? + SEARCHABLE_COLUMNS = %w(name)
def object_list @@ -96,5 +98,8 @@ class Deployment < ActiveRecord::Base return get_action_list.include?(action) ? true : false end
+ def destroyable? + instances.all? {|i| i.destroyable? } + end
end diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml index 677af3b..3f8b566 100644 --- a/src/config/locales/en.yml +++ b/src/config/locales/en.yml @@ -37,7 +37,6 @@ en: audit_report: Audit / Report assistance_requests: Assistance Requests define: Define - deployables: Deployables image_imports: Image Imports basic_template: Template Builder Basic Workflow browse_packages: Browse Packages @@ -96,6 +95,15 @@ en: index: deleted: "Deleted the following Pool Families: %{list}." not_deleted: "Could not delete the following Pool Families: %{list}." + deployables: + index: + deployables: Deployables + deleted: + one: "Deployable %{list} was deleted." + other: "Deployables %{list} were deleted." + not_deleted: + one: "Deployable %{list} was not deleted. There are deployments associated with it." + other: "Deployables %{list} were not deleted. They have deployments associated with them." setting: Settings name: Name admin: diff --git a/src/config/navigation.rb b/src/config/navigation.rb index 78a7862..21e1236 100644 --- a/src/config/navigation.rb +++ b/src/config/navigation.rb @@ -9,7 +9,7 @@ SimpleNavigation::Configuration.run do |navigation| first_level.item :image_factory, t(:image_factory), image_factory_templates_path, :highlights_on => //image_factory/ do |second_level| second_level.item :templates, t(:templates), image_factory_templates_path second_level.item :assemblies, t(:assemblies), image_factory_assemblies_path - second_level.item :deployables, t(:deployables), image_factory_deployables_path + second_level.item :deployables, t('deployables.index.deployables'), image_factory_deployables_path second_level.item :image_imports, t(:image_imports), new_image_factory_image_import_path end first_level.item :administration, t(:administration), admin_users_path, :highlights_on => //admin/ do |second_level|