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
Tatuya Kamada
gitlab-ce
Commits
b3a75111
Commit
b3a75111
authored
Apr 28, 2015
by
Steve Norman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow user to be blocked and unblocked via the API
parent
49749169
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
110 additions
and
0 deletions
+110
-0
CHANGELOG
CHANGELOG
+1
-0
doc/api/users.md
doc/api/users.md
+28
-0
lib/api/users.rb
lib/api/users.rb
+30
-0
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+51
-0
No files found.
CHANGELOG
View file @
b3a75111
...
@@ -35,6 +35,7 @@ v 7.13.0 (unreleased)
...
@@ -35,6 +35,7 @@ v 7.13.0 (unreleased)
- Faster automerge check and merge itself when source and target branches are in same repository
- Faster automerge check and merge itself when source and target branches are in same repository
- Correctly show anonymous authorized applications under Profile > Applications.
- Correctly show anonymous authorized applications under Profile > Applications.
- Query Optimization in MySQL.
- Query Optimization in MySQL.
- Allow users to be blocked and unblocked via the API
v 7.12.1
v 7.12.1
- Fix error when deleting a user who has projects (Stan Hu)
- Fix error when deleting a user who has projects (Stan Hu)
...
...
doc/api/users.md
View file @
b3a75111
...
@@ -396,3 +396,31 @@ Parameters:
...
@@ -396,3 +396,31 @@ Parameters:
-
`id`
(required) - SSH key ID
-
`id`
(required) - SSH key ID
Will return
`200 OK`
on success, or
`404 Not found`
if either user or key cannot be found.
Will return
`200 OK`
on success, or
`404 Not found`
if either user or key cannot be found.
## Block user
Blocks the specified user. Available only for admin.
```
PUT /users/:uid/block
```
Parameters:
-
`uid`
(required) - id of specified user
Will return
`200 OK`
on success, or
`404 User Not Found`
is user cannot be found.
## Unblock user
Unblocks the specified user. Available only for admin.
```
PUT /users/:uid/unblock
```
Parameters:
-
`uid`
(required) - id of specified user
Will return
`200 OK`
on success, or
`404 User Not Found`
is user cannot be found.
lib/api/users.rb
View file @
b3a75111
...
@@ -199,6 +199,36 @@ module API
...
@@ -199,6 +199,36 @@ module API
not_found!
(
'User'
)
not_found!
(
'User'
)
end
end
end
end
# Block user. Available only for admin
#
# Example Request:
# PUT /users/:id/block
put
':id/block'
do
authenticated_as_admin!
user
=
User
.
find_by
(
id:
params
[
:id
])
if
user
user
.
block
else
not_found!
(
'User'
)
end
end
# Unblock user. Available only for admin
#
# Example Request:
# PUT /users/:id/unblock
put
':id/unblock'
do
authenticated_as_admin!
user
=
User
.
find_by
(
id:
params
[
:id
])
if
user
user
.
activate
else
not_found!
(
'User'
)
end
end
end
end
resource
:user
do
resource
:user
do
...
...
spec/requests/api/users_spec.rb
View file @
b3a75111
...
@@ -527,4 +527,55 @@ describe API::API, api: true do
...
@@ -527,4 +527,55 @@ describe API::API, api: true do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
end
end
describe
'PUT /user/:id/block'
do
before
{
admin
}
it
'should block existing user'
do
put
api
(
"/users/
#{
user
.
id
}
/block"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
user
.
reload
.
state
).
to
eq
(
'blocked'
)
end
it
'should not be available for non admin users'
do
put
api
(
"/users/
#{
user
.
id
}
/block"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
user
.
reload
.
state
).
to
eq
(
'active'
)
end
it
'should return a 404 error if user id not found'
do
put
api
(
'/users/9999/block'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
end
describe
'PUT /user/:id/unblock'
do
before
{
admin
}
it
'should unblock existing user'
do
put
api
(
"/users/
#{
user
.
id
}
/unblock"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
user
.
reload
.
state
).
to
eq
(
'active'
)
end
it
'should unblock a blocked user'
do
put
api
(
"/users/
#{
user
.
id
}
/block"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
user
.
reload
.
state
).
to
eq
(
'blocked'
)
put
api
(
"/users/
#{
user
.
id
}
/unblock"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
user
.
reload
.
state
).
to
eq
(
'active'
)
end
it
'should not be available for non admin users'
do
put
api
(
"/users/
#{
user
.
id
}
/unblock"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
user
.
reload
.
state
).
to
eq
(
'active'
)
end
it
'should return a 404 error if user id not found'
do
put
api
(
'/users/9999/block'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
end
end
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