From a0b152219047b739987d522ef13d7aa56b1d9ae6 Mon Sep 17 00:00:00 2001 From: Douglas Gabriel Date: Mon, 8 Jan 2018 17:20:27 -0300 Subject: [PATCH] Showing alert for physical providers with invalid credentials --- app/controllers/ems_physical_infra_controller.rb | 11 +++++++++++ .../controllers/ems_physical_infra_controller_spec.rb | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/app/controllers/ems_physical_infra_controller.rb b/app/controllers/ems_physical_infra_controller.rb index 7953b8f87081..22f4eb871f88 100644 --- a/app/controllers/ems_physical_infra_controller.rb +++ b/app/controllers/ems_physical_infra_controller.rb @@ -7,6 +7,7 @@ class EmsPhysicalInfraController < ApplicationController before_action :check_privileges before_action :get_session_data + before_action :check_providers_credentials after_action :cleanup_action after_action :set_session_data @@ -18,6 +19,16 @@ def self.table_name @table_name ||= "ems_physical_infra" end + # Check if there are providers with invalid credentials + # if it's true, adds an alert message to user + def check_providers_credentials + model.find_each do |provider| + if provider.authentication_status.casecmp("invalid").zero? + add_flash(_("The provider \"%s\" is with invalid credentials") % {:name => provider.name}, :error) + end + end + end + def ems_path(*args) ems_physical_infra_path(*args) end diff --git a/spec/controllers/ems_physical_infra_controller_spec.rb b/spec/controllers/ems_physical_infra_controller_spec.rb index 0a984263f42f..22d4525c0427 100644 --- a/spec/controllers/ems_physical_infra_controller_spec.rb +++ b/spec/controllers/ems_physical_infra_controller_spec.rb @@ -84,9 +84,16 @@ before(:each) do stub_user(:features => :all) FactoryGirl.create(:ems_vmware) + @provider = FactoryGirl.create(:ems_physical_infra, :with_invalid_authentication) get :show_list end it { expect(response.status).to eq(200) } + + context "show provider with invalid credentials" do + it "shows an alert to user" do + expect(assigns(:flash_array).first[:message]).to include("The provider \"#{@provider.name}\" is with invalid credentials") + end + end end describe "breadcrumbs path on a 'show' page of an Physical Infrastructure Provider accessed from Dashboard maintab" do