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
0
Merge Requests
0
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
iv
gitlab-ce
Commits
bc7ef8e5
Commit
bc7ef8e5
authored
Dec 29, 2015
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ldap_blocked as new state to users state machine
parent
7403df6c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
17 deletions
+39
-17
app/models/user.rb
app/models/user.rb
+11
-1
spec/models/user_spec.rb
spec/models/user_spec.rb
+28
-16
No files found.
app/models/user.rb
View file @
bc7ef8e5
...
@@ -198,16 +198,26 @@ class User < ActiveRecord::Base
...
@@ -198,16 +198,26 @@ class User < ActiveRecord::Base
transition
active: :blocked
transition
active: :blocked
end
end
event
:ldap_block
do
transition
active: :ldap_blocked
end
event
:activate
do
event
:activate
do
transition
blocked: :active
transition
blocked: :active
end
end
state
:blocked
,
:ldap_blocked
do
def
blocked?
true
end
end
end
end
mount_uploader
:avatar
,
AvatarUploader
mount_uploader
:avatar
,
AvatarUploader
# Scopes
# Scopes
scope
:admins
,
->
{
where
(
admin:
true
)
}
scope
:admins
,
->
{
where
(
admin:
true
)
}
scope
:blocked
,
->
{
with_state
(
:
blocked
)
}
scope
:blocked
,
->
{
with_state
s
(
:blocked
,
:ldap_
blocked
)
}
scope
:active
,
->
{
with_state
(
:active
)
}
scope
:active
,
->
{
with_state
(
:active
)
}
scope
:not_in_project
,
->
(
project
)
{
project
.
users
.
present?
?
where
(
"id not in (:ids)"
,
ids:
project
.
users
.
map
(
&
:id
)
)
:
all
}
scope
:not_in_project
,
->
(
project
)
{
project
.
users
.
present?
?
where
(
"id not in (:ids)"
,
ids:
project
.
users
.
map
(
&
:id
)
)
:
all
}
scope
:without_projects
,
->
{
where
(
'id NOT IN (SELECT DISTINCT(user_id) FROM members)'
)
}
scope
:without_projects
,
->
{
where
(
'id NOT IN (SELECT DISTINCT(user_id) FROM members)'
)
}
...
...
spec/models/user_spec.rb
View file @
bc7ef8e5
...
@@ -569,30 +569,42 @@ describe User, models: true do
...
@@ -569,30 +569,42 @@ describe User, models: true do
end
end
end
end
context
'ldap synchronized user'
do
describe
:ldap_user?
do
describe
:ldap_user?
do
it
"is true if provider name starts with ldap"
do
it
'is true if provider name starts with ldap'
do
user
=
create
(
:omniauth_user
,
provider:
'ldapmain'
)
user
=
create
(
:omniauth_user
,
provider:
'ldapmain'
)
expect
(
user
.
ldap_user?
).
to
be_truthy
expect
(
user
.
ldap_user?
).
to
be_truthy
end
end
it
"is false for other providers"
do
it
'is false for other providers'
do
user
=
create
(
:omniauth_user
,
provider:
'other-provider'
)
user
=
create
(
:omniauth_user
,
provider:
'other-provider'
)
expect
(
user
.
ldap_user?
).
to
be_falsey
expect
(
user
.
ldap_user?
).
to
be_falsey
end
end
it
"is false if no extern_uid is provided"
do
it
'is false if no extern_uid is provided'
do
user
=
create
(
:omniauth_user
,
extern_uid:
nil
)
user
=
create
(
:omniauth_user
,
extern_uid:
nil
)
expect
(
user
.
ldap_user?
).
to
be_falsey
expect
(
user
.
ldap_user?
).
to
be_falsey
end
end
end
end
describe
:ldap_identity
do
describe
:ldap_identity
do
it
"returns ldap identity"
do
it
'returns ldap identity'
do
user
=
create
:omniauth_user
user
=
create
:omniauth_user
expect
(
user
.
ldap_identity
.
provider
).
not_to
be_empty
expect
(
user
.
ldap_identity
.
provider
).
not_to
be_empty
end
end
end
end
describe
'#ldap_block'
do
let
(
:user
)
{
create
(
:omniauth_user
,
provider:
'ldapmain'
,
name:
'John Smith'
)
}
it
'blocks user flaging the action caming from ldap'
do
user
.
ldap_block
expect
(
user
.
blocked?
).
to
be_truthy
expect
(
user
.
ldap_blocked?
).
to
be_truthy
end
end
end
describe
'#full_website_url'
do
describe
'#full_website_url'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
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