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
26af0e2d
Commit
26af0e2d
authored
6 years ago
by
Francisco Javier López
Committed by
Douwe Maan
6 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed user synced attributes metadata after removing current provider
parent
16ca6914
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
2 deletions
+68
-2
app/models/identity.rb
app/models/identity.rb
+9
-0
changelogs/unreleased/fj-37528-error-after-disabling-ldap.yml
...gelogs/unreleased/fj-37528-error-after-disabling-ldap.yml
+6
-0
lib/gitlab/ldap/config.rb
lib/gitlab/ldap/config.rb
+1
-1
lib/gitlab/o_auth/user.rb
lib/gitlab/o_auth/user.rb
+7
-1
spec/lib/gitlab/ldap/config_spec.rb
spec/lib/gitlab/ldap/config_spec.rb
+8
-0
spec/lib/gitlab/o_auth/user_spec.rb
spec/lib/gitlab/o_auth/user_spec.rb
+4
-0
spec/models/identity_spec.rb
spec/models/identity_spec.rb
+33
-0
No files found.
app/models/identity.rb
View file @
26af0e2d
...
@@ -9,6 +9,7 @@ class Identity < ActiveRecord::Base
...
@@ -9,6 +9,7 @@ class Identity < ActiveRecord::Base
validates
:user_id
,
uniqueness:
{
scope: :provider
}
validates
:user_id
,
uniqueness:
{
scope: :provider
}
before_save
:ensure_normalized_extern_uid
,
if: :extern_uid_changed?
before_save
:ensure_normalized_extern_uid
,
if: :extern_uid_changed?
after_destroy
:clear_user_synced_attributes
,
if: :user_synced_attributes_metadata_from_provider?
scope
:with_provider
,
->
(
provider
)
{
where
(
provider:
provider
)
}
scope
:with_provider
,
->
(
provider
)
{
where
(
provider:
provider
)
}
scope
:with_extern_uid
,
->
(
provider
,
extern_uid
)
do
scope
:with_extern_uid
,
->
(
provider
,
extern_uid
)
do
...
@@ -34,4 +35,12 @@ class Identity < ActiveRecord::Base
...
@@ -34,4 +35,12 @@ class Identity < ActiveRecord::Base
self
.
extern_uid
=
Identity
.
normalize_uid
(
self
.
provider
,
self
.
extern_uid
)
self
.
extern_uid
=
Identity
.
normalize_uid
(
self
.
provider
,
self
.
extern_uid
)
end
end
def
user_synced_attributes_metadata_from_provider?
user
.
user_synced_attributes_metadata
&
.
provider
==
provider
end
def
clear_user_synced_attributes
user
.
user_synced_attributes_metadata
&
.
destroy
end
end
end
This diff is collapsed.
Click to expand it.
changelogs/unreleased/fj-37528-error-after-disabling-ldap.yml
0 → 100644
View file @
26af0e2d
---
title
:
Fixed error 500 when removing an identity with synced attributes and visiting
the profile page
merge_request
:
17054
author
:
type
:
fixed
This diff is collapsed.
Click to expand it.
lib/gitlab/ldap/config.rb
View file @
26af0e2d
...
@@ -15,7 +15,7 @@ module Gitlab
...
@@ -15,7 +15,7 @@ module Gitlab
end
end
def
self
.
servers
def
self
.
servers
Gitlab
.
config
.
ldap
.
servers
.
values
Gitlab
.
config
.
ldap
[
'servers'
]
&
.
values
||
[]
end
end
def
self
.
available_servers
def
self
.
available_servers
...
...
This diff is collapsed.
Click to expand it.
lib/gitlab/o_auth/user.rb
View file @
26af0e2d
...
@@ -198,9 +198,11 @@ module Gitlab
...
@@ -198,9 +198,11 @@ module Gitlab
end
end
def
update_profile
def
update_profile
clear_user_synced_attributes_metadata
return
unless
sync_profile_from_provider?
||
creating_linked_ldap_user?
return
unless
sync_profile_from_provider?
||
creating_linked_ldap_user?
metadata
=
gl_user
.
user_synced_attributes_metadata
||
gl_user
.
build_user_synced_attributes_metadata
metadata
=
gl_user
.
build_user_synced_attributes_metadata
if
sync_profile_from_provider?
if
sync_profile_from_provider?
UserSyncedAttributesMetadata
::
SYNCABLE_ATTRIBUTES
.
each
do
|
key
|
UserSyncedAttributesMetadata
::
SYNCABLE_ATTRIBUTES
.
each
do
|
key
|
...
@@ -221,6 +223,10 @@ module Gitlab
...
@@ -221,6 +223,10 @@ module Gitlab
end
end
end
end
def
clear_user_synced_attributes_metadata
gl_user
.
user_synced_attributes_metadata
&
.
destroy
end
def
log
def
log
Gitlab
::
AppLogger
Gitlab
::
AppLogger
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/ldap/config_spec.rb
View file @
26af0e2d
...
@@ -5,6 +5,14 @@ describe Gitlab::LDAP::Config do
...
@@ -5,6 +5,14 @@ describe Gitlab::LDAP::Config do
let
(
:config
)
{
described_class
.
new
(
'ldapmain'
)
}
let
(
:config
)
{
described_class
.
new
(
'ldapmain'
)
}
describe
'.servers'
do
it
'returns empty array if no server information is available'
do
allow
(
Gitlab
.
config
).
to
receive
(
:ldap
).
and_return
(
'enabled'
=>
false
)
expect
(
described_class
.
servers
).
to
eq
[]
end
end
describe
'#initialize'
do
describe
'#initialize'
do
it
'requires a provider'
do
it
'requires a provider'
do
expect
{
described_class
.
new
}.
to
raise_error
ArgumentError
expect
{
described_class
.
new
}.
to
raise_error
ArgumentError
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/o_auth/user_spec.rb
View file @
26af0e2d
...
@@ -724,6 +724,10 @@ describe Gitlab::OAuth::User do
...
@@ -724,6 +724,10 @@ describe Gitlab::OAuth::User do
it
"does not update the user location"
do
it
"does not update the user location"
do
expect
(
gl_user
.
location
).
not_to
eq
(
info_hash
[
:address
][
:country
])
expect
(
gl_user
.
location
).
not_to
eq
(
info_hash
[
:address
][
:country
])
end
end
it
'does not create associated user synced attributes metadata'
do
expect
(
gl_user
.
user_synced_attributes_metadata
).
to
be_nil
end
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/models/identity_spec.rb
View file @
26af0e2d
...
@@ -70,5 +70,38 @@ describe Identity do
...
@@ -70,5 +70,38 @@ describe Identity do
end
end
end
end
end
end
context
'after_destroy'
do
let!
(
:user
)
{
create
(
:user
)
}
let
(
:ldap_identity
)
{
create
(
:identity
,
provider:
'ldapmain'
,
extern_uid:
'uid=john smith,ou=people,dc=example,dc=com'
,
user:
user
)
}
let
(
:ldap_user_synced_attributes
)
{
{
provider:
'ldapmain'
,
name_synced:
true
,
email_synced:
true
}
}
let
(
:other_provider_user_synced_attributes
)
{
{
provider:
'other'
,
name_synced:
true
,
email_synced:
true
}
}
describe
'if user synced attributes metadada provider'
do
context
'matches the identity provider '
do
it
'removes the user synced attributes'
do
user
.
create_user_synced_attributes_metadata
(
ldap_user_synced_attributes
)
expect
(
user
.
user_synced_attributes_metadata
.
provider
).
to
eq
'ldapmain'
ldap_identity
.
destroy
expect
(
user
.
reload
.
user_synced_attributes_metadata
).
to
be_nil
end
end
context
'does not matche the identity provider'
do
it
'does not remove the user synced attributes'
do
user
.
create_user_synced_attributes_metadata
(
other_provider_user_synced_attributes
)
expect
(
user
.
user_synced_attributes_metadata
.
provider
).
to
eq
'other'
ldap_identity
.
destroy
expect
(
user
.
reload
.
user_synced_attributes_metadata
.
provider
).
to
eq
'other'
end
end
end
end
end
end
end
end
This diff is collapsed.
Click to expand it.
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