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 ...@@ -14,6 +14,8 @@ class LdapGroupLink < ActiveRecord::Base
def config def config
Gitlab::LDAP::Config.new(provider) Gitlab::LDAP::Config.new(provider)
rescue Gitlab::LDAP::Config::InvalidProvider
nil
end end
# default to the first LDAP server # default to the first LDAP server
......
%li %li
= ldap_group_link.cn %h4= ldap_group_link.cn
%small.light== as #{ldap_group_link.human_access} on #{ldap_group_link.provider_label}
.pull-right .pull-right
= link_to group_ldap_group_link_path(group, ldap_group_link), method: :delete, class: 'btn btn-danger btn-small' do = 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') = 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 ...@@ -4,12 +4,16 @@ module Gitlab
class Config class Config
attr_accessor :provider, :options attr_accessor :provider, :options
class InvalidProvider < StandardError; end
def self.enabled? def self.enabled?
Gitlab.config.ldap.enabled Gitlab.config.ldap.enabled
end end
def self.servers def self.servers
Gitlab.config.ldap.servers.values Gitlab.config.ldap.servers.values
rescue Settingslogic::MissingSetting
[]
end end
def self.providers def self.providers
...@@ -21,7 +25,7 @@ module Gitlab ...@@ -21,7 +25,7 @@ module Gitlab
end end
def self.invalid_provider(provider) def self.invalid_provider(provider)
raise "Unknown provider (#{provider}). Available providers: #{providers}" raise InvalidProvider.new("Unknown provider (#{provider}). Available providers: #{providers}")
end end
def initialize(provider) def initialize(provider)
...@@ -32,6 +36,7 @@ module Gitlab ...@@ -32,6 +36,7 @@ module Gitlab
else else
self.class.invalid_provider(provider) self.class.invalid_provider(provider)
end end
@options = config_for(@provider) # Use @provider, not provider @options = config_for(@provider) # Use @provider, not provider
end end
...@@ -87,6 +92,7 @@ module Gitlab ...@@ -87,6 +92,7 @@ module Gitlab
end end
protected protected
def base_config def base_config
Gitlab.config.ldap Gitlab.config.ldap
end 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