Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
526959ab
Commit
526959ab
authored
Jul 09, 2014
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a scope to add/remove LDAP keys
For some reason I needed to add a reload statement in the specs.
parent
fe620209
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
10 deletions
+10
-10
app/models/key.rb
app/models/key.rb
+2
-0
lib/gitlab/ldap/access.rb
lib/gitlab/ldap/access.rb
+7
-10
spec/lib/gitlab/ldap/ldap_access_spec.rb
spec/lib/gitlab/ldap/ldap_access_spec.rb
+1
-0
No files found.
app/models/key.rb
View file @
526959ab
...
...
@@ -27,6 +27,8 @@ class Key < ActiveRecord::Base
validates
:key
,
presence:
true
,
length:
{
within:
0
..
5000
},
format:
{
with:
/\A(ssh|ecdsa)-.*\Z/
},
uniqueness:
true
validates
:fingerprint
,
uniqueness:
true
,
presence:
{
message:
'cannot be generated'
}
scope
:ldap
,
->
{
where
(
type:
'LDAPKey'
)
}
delegate
:name
,
:email
,
to: :user
,
prefix:
true
after_create
:add_to_shell
...
...
lib/gitlab/ldap/access.rb
View file @
526959ab
...
...
@@ -62,17 +62,14 @@ module Gitlab
# Get LDAP user entry
ldap_user
=
Gitlab
::
LDAP
::
Person
.
find_by_dn
(
user
.
extern_uid
)
ldap_user
.
ssh_keys
.
each
do
|
key
|
unless
user
.
keys
.
find_by_key
(
key
)
k
=
LDAPKey
.
new
(
title:
"LDAP -
#{
Gitlab
.
config
.
ldap
[
'sync_ssh_keys'
]
}
"
,
key:
key
)
user
.
keys
<<
k
if
k
.
save
end
user
.
keys
.
ldap
.
where
.
not
(
key:
ldap_user
.
ssh_keys
).
each
do
|
deleted_key
|
deleted_key
.
destroy
end
user
.
keys
.
to_a
.
each
do
|
k
|
if
k
.
is_a?
(
LDAPKey
)
&&
!
ldap_user
.
ssh_keys
.
include?
(
k
.
key
)
user
.
keys
.
delete
(
k
)
k
.
destroy
end
(
ldap_user
.
ssh_keys
-
user
.
keys
.
ldap
.
pluck
(
:key
)).
each
do
|
key
|
new_key
=
LDAPKey
.
new
(
title:
"LDAP -
#{
Gitlab
.
config
.
ldap
[
'sync_ssh_keys'
]
}
"
,
key:
key
)
new_key
.
user
=
user
new_key
.
save
end
end
...
...
spec/lib/gitlab/ldap/ldap_access_spec.rb
View file @
526959ab
...
...
@@ -88,6 +88,7 @@ describe Gitlab::LDAP::Access do
expect
(
user_ldap
.
keys
.
size
).
to
be
(
0
)
access
.
update_ssh_keys
(
user_ldap
)
user_ldap
.
reload
expect
(
user_ldap
.
keys
.
size
).
to
be
(
1
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment