Working on issue #981 - Fixed bug: LDAP integration admin interface shows error if functionality is enabled but not configured yet.

This commit is contained in:
Thorsten Eckel 2017-05-10 09:51:19 +02:00
parent 6c2ae15c8d
commit bb230519be
2 changed files with 17 additions and 9 deletions

View file

@ -6,8 +6,9 @@ require 'ldap/group'
module Import module Import
class Ldap < Import::Base class Ldap < Import::Base
# Checks if the integration is activated. Otherwise it won't get queued # Checks if the integration is activated and configured.
# since it will display an error which is confusing and wrong. # Otherwise it won't get queued since it will display
# an error which is confusing and wrong.
# #
# @example # @example
# Import::LDAP.queueable? # Import::LDAP.queueable?
@ -15,7 +16,7 @@ module Import
# #
# return [Boolean] # return [Boolean]
def self.queueable? def self.queueable?
Setting.get('ldap_integration') Setting.get('ldap_integration') && Setting.get('ldap_config').present?
end end
# Starts a live or dry run LDAP import. # Starts a live or dry run LDAP import.

View file

@ -6,13 +6,21 @@ RSpec.describe Import::Ldap do
describe '#queueable?' do describe '#queueable?' do
it 'is queueable if ldap integration is activated' do it 'is queueable if LDAP integration is activated and configured' do
expect(Setting).to receive(:get).with('ldap_integration').and_return(true) allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
allow(Setting).to receive(:get).with('ldap_config').and_return({ host: 'some' })
expect(described_class.queueable?).to be true expect(described_class.queueable?).to be true
end end
it "isn't queueable if ldap integration is deactivated" do it "isn't queueable if LDAP integration is deactivated" do
expect(Setting).to receive(:get).with('ldap_integration').and_return(false) allow(Setting).to receive(:get).with('ldap_integration').and_return(false)
allow(Setting).to receive(:get).with('ldap_config').and_return({ host: 'some' })
expect(described_class.queueable?).to be false
end
it "isn't queueable if LDAP configuration is missing" do
allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
allow(Setting).to receive(:get).with('ldap_config').and_return({})
expect(described_class.queueable?).to be false expect(described_class.queueable?).to be false
end end
end end
@ -20,11 +28,10 @@ RSpec.describe Import::Ldap do
describe '.start' do describe '.start' do
it 'starts LDAP import resource factories' do it 'starts LDAP import resource factories' do
import_job = create(:import_job) import_job = create(:import_job)
instance = described_class.new(import_job) instance = described_class.new(import_job)
expect(Setting).to receive(:get).with('ldap_integration').and_return(true) allow(Setting).to receive(:get).with('ldap_integration').and_return(true)
expect(Import::Ldap::UserFactory).to receive(:import) expect(Import::Ldap::UserFactory).to receive(:import)
instance.start instance.start