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
Boxiang Sun
gitlab-ce
Commits
6dd4ae0d
Commit
6dd4ae0d
authored
Oct 11, 2018
by
JB Vasseur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support GET /applications and DELETE /applications/:id endpoints #52559
parent
3421f1d1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
2 deletions
+104
-2
doc/api/applications.md
doc/api/applications.md
+49
-2
lib/api/applications.rb
lib/api/applications.rb
+17
-0
spec/requests/api/applications_spec.rb
spec/requests/api/applications_spec.rb
+38
-0
No files found.
doc/api/applications.md
View file @
6dd4ae0d
...
...
@@ -4,12 +4,12 @@
[
ce-8160
]:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8160
Only admin user can use the Applications API.
## Create a application
Create a application by posting a JSON payload.
User must be admin to do that.
Returns
`200`
if the request succeeds.
```
...
...
@@ -30,8 +30,55 @@ Example response:
```
json
{
"id"
:
1
,
"application_id"
:
"5832fc6e14300a0d962240a8144466eef4ee93ef0d218477e55f11cf12fc3737"
,
"application_name"
:
"MyApplication"
,
"secret"
:
"ee1dd64b6adc89cf7e2c23099301ccc2c61b441064e9324d963c46902a85ec34"
,
"callback_url"
:
"http://redirect.uri"
}
```
## List all applications
List all registered applications.
```
GET /applications
```
```
bash
curl
--request
GET
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/applications
```
Example response:
```
json
[
{
"id"
:
1
,
"application_id"
:
"5832fc6e14300a0d962240a8144466eef4ee93ef0d218477e55f11cf12fc3737"
,
"application_name"
:
"MyApplication"
,
"callback_url"
:
"http://redirect.uri"
}
]
```
> Note: the `secret` value will not be exposed by this API.
## Delete an application
Delete a specific application.
Returns
`204`
if the request succeeds.
```
DELETE /applications/:id
```
Parameters:
-
`id`
(required) - The id of the application (not the application_id)
```
bash
curl
--request
DELETE
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/applications/:id
```
lib/api/applications.rb
View file @
6dd4ae0d
...
...
@@ -24,6 +24,23 @@ module API
render_validation_error!
application
end
end
desc
'Get applications'
do
success
Entities
::
ApplicationWithSecret
end
get
do
applications
=
Doorkeeper
::
Application
.
all
present
applications
,
with:
Entities
::
Application
end
# rubocop: disable CodeReuse/ActiveRecord
desc
'Delete an application'
delete
':id'
do
Doorkeeper
::
Application
.
find_by
(
id:
params
[
:id
]).
destroy
status
204
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
spec/requests/api/applications_spec.rb
View file @
6dd4ae0d
...
...
@@ -5,6 +5,7 @@ describe API::Applications, :api do
let
(
:admin_user
)
{
create
(
:user
,
admin:
true
)
}
let
(
:user
)
{
create
(
:user
,
admin:
false
)
}
let
(
:application
)
{
create
(
:application
,
name:
'application_name'
,
redirect_uri:
'http://application.url'
,
scopes:
''
)
}
describe
'POST /applications'
do
context
'authenticated and authorized user'
do
...
...
@@ -83,4 +84,41 @@ describe API::Applications, :api do
end
end
end
describe
'GET /applications'
do
context
'authenticated and authorized user'
do
it
'can list application'
do
get
api
(
'/applications'
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
be_a
(
Array
)
end
end
context
'non-authenticated user'
do
it
'cannot list application'
do
get
api
(
'/applications'
)
expect
(
response
).
to
have_http_status
401
end
end
end
describe
'DELETE /applications/:id'
do
context
'authenticated and authorized user'
do
it
'can delete an application'
do
delete
api
(
"/applications/
#{
application
.
id
}
"
)
expect
(
response
).
to
have_gitlab_http_status
(
204
)
end
end
context
'non-authenticated user'
do
it
'cannot delete an application'
do
delete
api
(
"/applications/
#{
application
.
id
}
"
)
expect
(
response
).
to
have_http_status
401
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