From c2b483ce9e03c65eebace6268557885c22783f75 Mon Sep 17 00:00:00 2001 From: Harpreet Kataria Date: Mon, 4 Mar 2019 09:27:41 -0500 Subject: [PATCH] Merge pull request #5255 from hstastna/Approver_user_cannot_deny_request Allow Approver user to deny the request (cherry picked from commit 72966552117085cee04f46be0f9e6b06e21273cf) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1686090 --- .../application_helper/button/miq_request.rb | 2 +- .../toolbar/miq_request_center.rb | 2 +- .../buttons/miq_request_approval_spec.rb | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper/button/miq_request.rb b/app/helpers/application_helper/button/miq_request.rb index c62d394a783..966b1a110b2 100644 --- a/app/helpers/application_helper/button/miq_request.rb +++ b/app/helpers/application_helper/button/miq_request.rb @@ -14,7 +14,7 @@ def role_allows_feature? def visible? return false if @record.resource_type == "AutomationRequest" && - !%w(miq_request_approval miq_request_deny miq_request_delete).include?(@feature) + !%w(miq_request_approval miq_request_delete).include?(@feature) true end diff --git a/app/helpers/application_helper/toolbar/miq_request_center.rb b/app/helpers/application_helper/toolbar/miq_request_center.rb index cbf33cc6e31..ca84d369740 100644 --- a/app/helpers/application_helper/toolbar/miq_request_center.rb +++ b/app/helpers/application_helper/toolbar/miq_request_center.rb @@ -48,7 +48,7 @@ class ApplicationHelper::Toolbar::MiqRequestCenter < ApplicationHelper::Toolbar: N_('Deny this Request'), nil, :klass => ApplicationHelper::Button::MiqRequestApproval, - :options => {:feature => 'miq_request_deny'}, + :options => {:feature => 'miq_request_approval'}, :url => "/stamp", :url_parms => "?typ=d"), ]) diff --git a/spec/helpers/application_helper/buttons/miq_request_approval_spec.rb b/spec/helpers/application_helper/buttons/miq_request_approval_spec.rb index 6731945cb0f..2e50dc7cd39 100644 --- a/spec/helpers/application_helper/buttons/miq_request_approval_spec.rb +++ b/spec/helpers/application_helper/buttons/miq_request_approval_spec.rb @@ -14,6 +14,7 @@ let(:request) { "SomeRequest" } let(:username) { user.name } let(:state) { "xx" } + %w(MiqProvisionRequest VmReconfigureRequest VmCloudReconfigureRequest VmMigrateRequest AutomationRequest ServiceTemplateProvisionRequest).each do |cls| context "id = miq_request_approval" do @@ -27,22 +28,28 @@ button.instance_variable_set(:@showtype, "prase") button.instance_variable_set(:@request_tab, "service") end + context "resource_type = AutomationRequest" do let(:request) { "AutomationRequest" } + it "and resource_type = AutomationRequest" do expect(button.skipped?).to be_falsey end end + context "approval_state = approved" do let(:state) { "approved" } + it "and approval_state = approved" do expect(button.skipped?).to be_truthy end end + it "and showtype = miq_provisions" do button.instance_variable_set(:@showtype, "miq_provisions") expect(button.skipped?).to be_truthy end + it "and approval_state != approved and showtype != miq_provisions" do expect(button.skipped?).to be_falsey end @@ -53,7 +60,7 @@ view_context, {}, {'record' => @record, 'showtype' => @showtype}, - {:options => {:feature => 'miq_request_deny'}} + {:options => {:feature => 'miq_request_approval'}} ) end @@ -68,28 +75,36 @@ button.instance_variable_set(:@showtype, "prase") button.instance_variable_set(:@request_tab, "service") end + context "resource_type = AutomationRequest" do let(:request) { "AutomationRequest" } + it "and resource_type = AutomationRequest" do expect(button.skipped?).to be_falsey end end + context "approval_state = approved" do let(:state) { "approved" } + it "and approval_state = approved" do expect(button.skipped?).to be_truthy end end + context "approval_state = denied" do let(:state) { "denied" } + it "and approval_state = denied" do expect(button.skipped?).to be_truthy end end + it "and showtype = miq_provisions" do button.instance_variable_set(:@showtype, "miq_provisions") expect(button.skipped?).to be_truthy end + it "and approval_state != approved|denied and showtype != miq_provisions" do expect(button.skipped?).to be_falsey end