From: Tomas Sedovic<tomas(a)sedovic.cz>
https://bugzilla.redhat.com/show_bug.cgi?id=750504
The UI used to allow the users to edit or delete backend HWPs.
This hides the Edit and Delete buttons from the UI for the Provider Hardware
Profiles and makes sure that they can't be deleted by issuing rogue HTTP
request, etc.
Additionally, we no longer show matching profiles for backend HWPs as that
doesn't make much sense.
We may want to show all the *frontend* profiles that match a given backend one,
but that's not part of this patch.
---
.../controllers/hardware_profiles_controller.rb | 10 ++++++++++
src/app/views/hardware_profiles/show.html.haml | 16 +++++++++-------
src/config/locales/en.yml | 3 +++
src/features/hardware_profile.feature | 13 +++++++++++++
.../step_definitions/hardware_profile_steps.rb | 10 ++++++++++
5 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/src/app/controllers/hardware_profiles_controller.rb
b/src/app/controllers/hardware_profiles_controller.rb
index 2d408bf..c15b3dc 100644
--- a/src/app/controllers/hardware_profiles_controller.rb
+++ b/src/app/controllers/hardware_profiles_controller.rb
@@ -90,6 +90,11 @@ class HardwareProfilesController< ApplicationController
def destroy
hardware_profile = HardwareProfile.find(params[:id])
require_privilege(Privilege::MODIFY, hardware_profile)
+ if hardware_profile.provider_hardware_profile?
+ flash[:warning] = t
"hardware_profiles.flash.warning.cannot_delete_backend_hwp"
+ redirect_to hardware_profile_path(hardware_profile)
+ return
+ end
if hardware_profile.destroy
flash[:notice] = t "hardware_profiles.flash.notice.deleted"
else
@@ -103,6 +108,11 @@ class HardwareProfilesController< ApplicationController
@hardware_profile = HardwareProfile.find(params[:id])
end
require_privilege(Privilege::MODIFY, @hardware_profile)
+ if @hardware_profile.provider_hardware_profile?
+ flash[:warning] = t
"hardware_profiles.flash.warning.cannot_edit_backend_hwp"
+ redirect_to hardware_profile_path(@hardware_profile)
+ return
+ end
matching_provider_hardware_profiles
end
diff --git a/src/app/views/hardware_profiles/show.html.haml
b/src/app/views/hardware_profiles/show.html.haml
index 6c0dd03..bcda4d3 100644
--- a/src/app/views/hardware_profiles/show.html.haml
+++ b/src/app/views/hardware_profiles/show.html.haml
@@ -4,15 +4,17 @@
#obj_actions.button-container
= link_to t('hardware_profiles.list.new_hardware'),
new_hardware_profile_url, :class => 'button primary', :id =>
'new_role_button'
.button-group
- = link_to t('edit'), edit_hardware_profile_path(@hardware_profile), :class
=> 'button pill', :id => 'edit_button'
- = button_to t('delete'), hardware_profile_path(@hardware_profile), :method
=> :delete, :confirm => "Are you sure you want to delete?", :class =>
'button pill danger'
+ - unless @hardware_profile.provider_hardware_profile?
+ = link_to t('edit'), edit_hardware_profile_path(@hardware_profile),
:class => 'button pill', :id => 'edit_button'
+ = button_to t('delete'), hardware_profile_path(@hardware_profile),
:method => :delete, :confirm => "Are you sure you want to delete?",
:class => 'button pill danger'
%section.admin-content-section.hardware_profile
%header
%h2=t 'properties'
.content
= render :partial => 'properties'
-%section.admin-content-section.hardware_profile
- %header
- %h2=t'hardware_profiles.show.matching_hwp'
- .content
- = render :partial => 'matching_provider_hardware_profiles'
+- unless @hardware_profile.provider_hardware_profile?
+ %section.admin-content-section.hardware_profile
+ %header
+ %h2=t'hardware_profiles.show.matching_hwp'
+ .content
+ = render :partial => 'matching_provider_hardware_profiles'
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index bbb5f98..0a83548 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -513,6 +513,9 @@ en:
error:
not_deleted: "Hardware profile was not deleted!"
more_not_deleted: Could not deleted these Hardware Profiles
+ warning:
+ cannot_edit_backend_hwp: "Cannot modify Provider Hardware Profiles"
+ cannot_delete_backend_hwp: "Cannot delete Provider Hardware Profiles"
preset_filters:
all_hardware_profiles: "All Hardware Profiles"
x86_64architecture: "x86_64 architecture"
diff --git a/src/features/hardware_profile.feature
b/src/features/hardware_profile.feature
index c7b77db..41c72b5 100644
--- a/src/features/hardware_profile.feature
+++ b/src/features/hardware_profile.feature
@@ -174,3 +174,16 @@ Feature: Manage Hardware Profiles
And I press "apply_hardware_profiles_search"
Then I should see "myhardware_profile"
And I should not see "somehardware_profile"
+
+ Scenario: Prevent modification of Backend Hardware Profiles
+ Given there are the following conductor hardware profiles:
+ | name | memory | cpu |storage | architecture |
+ | m1-small | 1740 | 2 | 160 | i386 |
+ And the Hardare Profile "m1-small" has the following Provider Hardware
Profiles:
+ | name | memory | cpu |storage | architecture |
+ | b1-small | 1740 | 2 | 160 | i386 |
+ And I am on the hardware profiles page
+ When I follow "m1-small"
+ And I follow "b1-small"
+ Then I should not see the edit button
+ And I should not see the delete button
diff --git a/src/features/step_definitions/hardware_profile_steps.rb
b/src/features/step_definitions/hardware_profile_steps.rb
index dda2220..be3c4a8 100644
--- a/src/features/step_definitions/hardware_profile_steps.rb
+++ b/src/features/step_definitions/hardware_profile_steps.rb
@@ -83,3 +83,13 @@ Then /^I should see the hardware profiles table$/ do
localized_text_present 'hardware_profiles.index.storage'
localized_text_present 'hardware_profiles.index.architecture'
end
+
+Then /^I should not see the edit button$/ do
+ page.should have_no_selector('#edit_button')
+end
+
+Then /^I should not see the delete button$/ do
+ within('#obj_actions') do
+ page.should have_no_selector('input[value=delete]')
+ end
+end
Nice catch. I noticed the "matching HWPs" problem when working on my
permissions fix last week but hadn't gotten around to confirming that
there was already a bug out on it.
ACK based on code review, but I didn't run through and test, so make
sure tests are all passing for you before pushing.
Scott