From 8fed435208fed3115c740eb630c263a97b5a631d Mon Sep 17 00:00:00 2001
From: Douwe Maan <douwe@gitlab.com>
Date: Fri, 13 Mar 2015 16:40:15 +0100
Subject: [PATCH] Unblock user if they were unblocked in AD.

---
 CHANGELOG                           |  2 +-
 lib/gitlab/ldap/access.rb           |  1 +
 spec/lib/gitlab/ldap/access_spec.rb | 11 ++++++++++-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 97376c85e..3511a94ba 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -60,7 +60,7 @@ v 7.9.0 (unreleased)
   - Remove annoying notice messages when create/update merge request
   - Allow smb:// links in Markdown text.
   - Filter merge request by title or description at Merge Requests page
-  - Block user if he/she was blocked in Active Directory
+  - Block and unblock user if he/she was blocked/unblocked in Active Directory
 
 v 7.8.4
   - Fix issue_tracker_id substitution in custom issue trackers
diff --git a/lib/gitlab/ldap/access.rb b/lib/gitlab/ldap/access.rb
index 6e30724e1..960fb3849 100644
--- a/lib/gitlab/ldap/access.rb
+++ b/lib/gitlab/ldap/access.rb
@@ -40,6 +40,7 @@ module Gitlab
             user.block unless user.blocked?
             false
           else
+            user.activate if user.blocked?
             true
           end
         else
diff --git a/spec/lib/gitlab/ldap/access_spec.rb b/spec/lib/gitlab/ldap/access_spec.rb
index 39d46efcb..707a0521a 100644
--- a/spec/lib/gitlab/ldap/access_spec.rb
+++ b/spec/lib/gitlab/ldap/access_spec.rb
@@ -28,9 +28,18 @@ describe Gitlab::LDAP::Access do
       end
 
       context 'and has no disabled flag in active diretory' do
-        before { Gitlab::LDAP::Person.stub(disabled_via_active_directory?: false) }
+        before do
+          user.block
+          
+          Gitlab::LDAP::Person.stub(disabled_via_active_directory?: false)
+        end
 
         it { is_expected.to be_truthy }
+
+        it "should unblock user in GitLab" do
+          access.allowed?
+          user.should_not be_blocked
+        end
       end
 
       context 'without ActiveDirectory enabled' do
-- 
2.30.9