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
4ea4ec48
Commit
4ea4ec48
authored
Aug 24, 2021
by
Serena Fang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for valid state in service
Also fix spec names
parent
b4b91b2c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
21 deletions
+20
-21
app/services/users/ban_service.rb
app/services/users/ban_service.rb
+4
-0
app/services/users/banned_user_base_service.rb
app/services/users/banned_user_base_service.rb
+1
-10
app/services/users/unban_service.rb
app/services/users/unban_service.rb
+4
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+9
-9
spec/services/users/ban_service_spec.rb
spec/services/users/ban_service_spec.rb
+1
-1
spec/services/users/unban_service_spec.rb
spec/services/users/unban_service_spec.rb
+1
-1
No files found.
app/services/users/ban_service.rb
View file @
4ea4ec48
...
...
@@ -8,6 +8,10 @@ module Users
user
.
ban
end
def
valid_state?
(
user
)
user
.
active?
end
def
action
:ban
end
...
...
app/services/users/banned_user_base_service.rb
View file @
4ea4ec48
...
...
@@ -8,7 +8,7 @@ module Users
def
execute
(
user
)
return
permission_error
unless
allowed?
return
state_error
(
user
)
unless
valid_state
(
user
)
return
state_error
(
user
)
unless
valid_state
?
(
user
)
if
update_user
(
user
)
log_event
(
user
)
...
...
@@ -23,15 +23,6 @@ module Users
attr_reader
:current_user
def
valid_state
(
user
)
case
action
when
:ban
user
.
active?
when
:unban
user
.
banned?
end
end
def
state_error
(
user
)
error
(
_
(
"You cannot %{action} %{state} users."
%
{
action:
action
.
to_s
,
state:
user
.
state
}),
:forbidden
)
end
...
...
app/services/users/unban_service.rb
View file @
4ea4ec48
...
...
@@ -8,6 +8,10 @@ module Users
user
.
unban
end
def
valid_state?
(
user
)
user
.
banned?
end
def
action
:unban
end
...
...
spec/requests/api/users_spec.rb
View file @
4ea4ec48
...
...
@@ -3018,10 +3018,10 @@ RSpec.describe API::Users do
end
end
context
'with a non exist
a
nt user'
do
context
'with a non exist
e
nt user'
do
let
(
:user_id
)
{
non_existing_record_id
}
it
'does not ban non exist
a
nt users'
do
it
'does not ban non exist
e
nt users'
do
ban_user
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
...
...
@@ -3055,7 +3055,7 @@ RSpec.describe API::Users do
context
'with a banned user'
do
let
(
:user_id
)
{
banned_user
.
id
}
it
'
bans an active
user'
do
it
'
activates a banned
user'
do
unban_user
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
...
...
@@ -3066,7 +3066,7 @@ RSpec.describe API::Users do
context
'with an ldap_blocked user'
do
let
(
:user_id
)
{
ldap_blocked_user
.
id
}
it
'does not ban ldap_blocked users'
do
it
'does not
un
ban ldap_blocked users'
do
unban_user
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
...
...
@@ -3078,7 +3078,7 @@ RSpec.describe API::Users do
context
'with a deactivated user'
do
let
(
:user_id
)
{
deactivated_user
.
id
}
it
'does not ban deactivated users'
do
it
'does not
un
ban deactivated users'
do
unban_user
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
...
...
@@ -3090,7 +3090,7 @@ RSpec.describe API::Users do
context
'with an active user'
do
let
(
:user_id
)
{
user
.
id
}
it
'does not ban active users'
do
it
'does not
un
ban active users'
do
unban_user
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
...
...
@@ -3099,10 +3099,10 @@ RSpec.describe API::Users do
end
end
context
'with a non exist
a
nt user'
do
context
'with a non exist
e
nt user'
do
let
(
:user_id
)
{
non_existing_record_id
}
it
'does not
ban non exista
nt users'
do
it
'does not
unban non existe
nt users'
do
unban_user
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
...
...
@@ -3113,7 +3113,7 @@ RSpec.describe API::Users do
context
'with an invalid id user'
do
let
(
:user_id
)
{
'ASDF'
}
it
'does not ban invalid id users'
do
it
'does not
un
ban invalid id users'
do
unban_user
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
...
...
spec/services/users/ban_service_spec.rb
View file @
4ea4ec48
...
...
@@ -50,7 +50,7 @@ RSpec.describe Users::BanService do
response
=
ban_user
expect
(
response
[
:status
]).
to
eq
(
:error
)
expect
(
response
[
:message
]).
to
match
(
'You cannot ban
a blocked user
.'
)
expect
(
response
[
:message
]).
to
match
(
'You cannot ban
blocked users
.'
)
end
it_behaves_like
'does not modify the BannedUser record or user state'
...
...
spec/services/users/unban_service_spec.rb
View file @
4ea4ec48
...
...
@@ -50,7 +50,7 @@ RSpec.describe Users::UnbanService do
response
=
unban_user
expect
(
response
[
:status
]).
to
eq
(
:error
)
expect
(
response
[
:message
]).
to
match
(
'You cannot unban a
active user
.'
)
expect
(
response
[
:message
]).
to
match
(
'You cannot unban a
ctive users
.'
)
end
it_behaves_like
'does not modify the BannedUser record or user state'
...
...
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