Commit 35cae03c authored by Valery Sizov's avatar Valery Sizov Committed by Valery Sizov

fix for ldap group integration

parent f440c2e3
......@@ -183,6 +183,8 @@ class User < ActiveRecord::Base
scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members)') }
scope :subscribed_for_admin_email, -> { where(admin_email_unsubscribed_at: nil) }
scope :ldap, -> { joins(:identities).where('identities.provider LIKE ?', 'ldap%') }
scope :non_ldap, -> { joins('LEFT JOIN identities ON identities.user_id = users.id').
where('identities.provider IS NULL OR identities.provider NOT LIKE ?', 'ldap%') }
scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active }
#
......
......@@ -13,7 +13,7 @@ module API
@users = User.all
@users = @users.active if params[:active].present?
@users = @users.where('provider != ? OR provider IS NULL', 'ldap') if skip_ldap
@users = @users.non_ldap if skip_ldap
@users = @users.search(params[:search]) if params[:search].present?
@users = paginate @users
......
......@@ -109,6 +109,20 @@ describe User do
end
end
describe "scopes" do
describe "non_ldap" do
it "retuns non-ldap user" do
create :user
ldap_user = create :omniauth_user, provider: "ldapmain"
create :omniauth_user, provider: "gitlub"
users = User.non_ldap
users.count.should == 2
users.detect{ |user| user.username == ldap_user.username }.should be_nil
end
end
end
describe "Respond to" do
it { should respond_to(:is_admin?) }
it { should respond_to(:name) }
......
......@@ -37,6 +37,17 @@ describe API::API, api: true do
json_response.first.keys.should include 'can_create_project'
end
end
context "when authenticated and ldap is enabled" do
it "should return non-ldap user" do
create :omniauth_user, provider: "ldapserver1"
get api("/users", user), skip_ldap: "true"
response.status.should == 200
json_response.should be_an Array
username = user.username
json_response.first["username"].should == username
end
end
end
describe "GET /users/:id" do
......
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