Commit 9eb72609 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'improve-ldap' into 'master'

Hide ldap group links if ldap is not enabled

This MR also includes a fix for next issue: prevent 500 error on ldap group links page if group has links to ldap servers that are disabled or removed from gitlab config.

Fixes #196

See merge request !264
parents 230900b9 5fd2e01d
...@@ -239,4 +239,10 @@ class ApplicationController < ActionController::Base ...@@ -239,4 +239,10 @@ class ApplicationController < ActionController::Base
redirect_to profile_path, notice: 'Please complete your profile with email address' and return redirect_to profile_path, notice: 'Please complete your profile with email address' and return
end end
end end
def require_ldap_enabled
unless Gitlab.config.ldap.enabled
render_404 and return
end
end
end end
class Groups::LdapGroupLinksController < ApplicationController class Groups::LdapGroupLinksController < ApplicationController
before_action :group before_action :group
before_action :require_ldap_enabled
before_action :authorize_admin_group! before_action :authorize_admin_group!
layout 'group' layout 'group'
......
...@@ -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
......
...@@ -7,10 +7,11 @@ ...@@ -7,10 +7,11 @@
= link_to projects_group_path(@group) do = link_to projects_group_path(@group) do
%i.fa.fa-folder %i.fa.fa-folder
Projects Projects
= nav_link(controller: :ldap_group_links) do - if ldap_enabled?
= link_to group_ldap_group_links_path(@group) do = nav_link(controller: :ldap_group_links) do
%i.icon-exchange = link_to group_ldap_group_links_path(@group) do
LDAP Groups %i.fa.fa-exchange
LDAP Groups
= nav_link(controller: :audit_events) do = nav_link(controller: :audit_events) do
= link_to group_audit_events_path(@group) do = link_to group_audit_events_path(@group) do
%i.fa.fa-file-text-o %i.fa.fa-file-text-o
......
%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
...@@ -56,9 +56,11 @@ Feature: Groups ...@@ -56,9 +56,11 @@ Feature: Groups
And I should not see the "Remove avatar" button And I should not see the "Remove avatar" button
Scenario: Add new LDAP synchronization Scenario: Add new LDAP synchronization
Given LDAP enabled
When I visit Group "Owned" LDAP settings page When I visit Group "Owned" LDAP settings page
And I add a new LDAP synchronization And I add a new LDAP synchronization
Then I see a new LDAP synchronization listed Then I see a new LDAP synchronization listed
And LDAP disabled
# Leave # Leave
......
...@@ -313,6 +313,14 @@ class Spinach::Features::Groups < Spinach::FeatureSteps ...@@ -313,6 +313,14 @@ class Spinach::Features::Groups < Spinach::FeatureSteps
milestone: milestone2_project3 milestone: milestone2_project3
end end
step 'LDAP enabled' do
Gitlab.config.ldap.stub(:enabled).and_return(true)
end
step 'LDAP disabled' do
Gitlab.config.ldap.stub(:enabled).and_return(false)
end
step 'I add a new LDAP synchronization' do step 'I add a new LDAP synchronization' do
within('form#new_ldap_group_link') do within('form#new_ldap_group_link') do
find('#ldap_group_link_cn', visible: false).set('my-group-cn') find('#ldap_group_link_cn', visible: false).set('my-group-cn')
...@@ -324,6 +332,6 @@ class Spinach::Features::Groups < Spinach::FeatureSteps ...@@ -324,6 +332,6 @@ class Spinach::Features::Groups < Spinach::FeatureSteps
step 'I see a new LDAP synchronization listed' do step 'I see a new LDAP synchronization listed' do
expect(page).not_to have_content('No synchronizations yet') expect(page).not_to have_content('No synchronizations yet')
expect(page).to have_content('my-group-cn as Developer') expect(page).to have_content('As Developer on ldap server')
end end
end end
...@@ -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