Commit 633fb8ab authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Prevent 500 error on ldap group links page

If group has links to ldap servers that are disabled or removed from
gitlab config.
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent f5d3e47e
......@@ -14,6 +14,8 @@ class LdapGroupLink < ActiveRecord::Base
def config
Gitlab::LDAP::Config.new(provider)
rescue Gitlab::LDAP::Config::InvalidProvider
nil
end
# default to the first LDAP server
......
%li
= ldap_group_link.cn
%small.light== as #{ldap_group_link.human_access} on #{ldap_group_link.provider_label}
%h4= ldap_group_link.cn
.pull-right
= link_to group_ldap_group_link_path(group, ldap_group_link), method: :delete, class: 'btn btn-danger btn-small' do
= fa_icon('unlink', text: 'unlink')
- if ldap_group_link.config
%p.light
As
%strong #{ldap_group_link.human_access}
on
%strong #{ldap_group_link.provider_label}
server
- else
%p.cred
%i.fa.fa-warning
Config for
%code #{ldap_group_link.provider}
does not present in GitLab
......@@ -4,12 +4,16 @@ module Gitlab
class Config
attr_accessor :provider, :options
class InvalidProvider < StandardError; end
def self.enabled?
Gitlab.config.ldap.enabled
end
def self.servers
Gitlab.config.ldap.servers.values
rescue Settingslogic::MissingSetting
[]
end
def self.providers
......@@ -21,7 +25,7 @@ module Gitlab
end
def self.invalid_provider(provider)
raise "Unknown provider (#{provider}). Available providers: #{providers}"
raise InvalidProvider.new("Unknown provider (#{provider}). Available providers: #{providers}")
end
def initialize(provider)
......@@ -32,6 +36,7 @@ module Gitlab
else
self.class.invalid_provider(provider)
end
@options = config_for(@provider) # Use @provider, not provider
end
......@@ -87,6 +92,7 @@ module Gitlab
end
protected
def base_config
Gitlab.config.ldap
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment