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
f7f4c7e1
Commit
f7f4c7e1
authored
Jun 13, 2019
by
Patrick Bajao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ProjectAliases API endpoints
This endpoints are only accessible by an admin.
parent
203fe05a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
268 additions
and
0 deletions
+268
-0
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+2
-0
ee/lib/api/project_aliases.rb
ee/lib/api/project_aliases.rb
+55
-0
ee/lib/ee/api/endpoints.rb
ee/lib/ee/api/endpoints.rb
+1
-0
ee/lib/ee/api/entities.rb
ee/lib/ee/api/entities.rb
+4
-0
ee/spec/fixtures/api/schemas/public_api/v4/project_alias.json
...pec/fixtures/api/schemas/public_api/v4/project_alias.json
+17
-0
ee/spec/fixtures/api/schemas/public_api/v4/project_aliases.json
...c/fixtures/api/schemas/public_api/v4/project_aliases.json
+4
-0
ee/spec/models/project_spec.rb
ee/spec/models/project_spec.rb
+1
-0
ee/spec/requests/api/project_aliases_spec.rb
ee/spec/requests/api/project_aliases_spec.rb
+184
-0
No files found.
ee/app/models/ee/project.rb
View file @
f7f4c7e1
...
...
@@ -76,6 +76,8 @@ module EE
has_many
:operations_feature_flags
,
class_name:
'Operations::FeatureFlag'
has_one
:operations_feature_flags_client
,
class_name:
'Operations::FeatureFlagsClient'
has_many
:project_aliases
scope
:with_shared_runners_limit_enabled
,
->
{
with_shared_runners
.
non_public_only
}
scope
:mirror
,
->
{
where
(
mirror:
true
)
}
...
...
ee/lib/api/project_aliases.rb
0 → 100644
View file @
f7f4c7e1
# frozen_string_literal: true
module
API
class
ProjectAliases
<
Grape
::
API
before
{
authenticated_as_admin!
}
helpers
do
def
project_alias
ProjectAlias
.
find_by_name!
(
params
[
:name
])
end
def
project
find_project!
(
params
[
:project_id
])
end
end
resource
:project_aliases
do
desc
'Get a list of all project aliases'
do
success
EE
::
API
::
Entities
::
ProjectAlias
end
get
do
present
ProjectAlias
.
all
,
with:
EE
::
API
::
Entities
::
ProjectAlias
end
desc
'Get info of specific project alias by name'
do
success
EE
::
API
::
Entities
::
ProjectAlias
end
get
':name'
do
present
project_alias
,
with:
EE
::
API
::
Entities
::
ProjectAlias
end
desc
'Create a project alias'
params
do
requires
:project_id
,
type:
String
,
desc:
'The ID or URL-encoded path of the project'
requires
:name
,
type:
String
,
desc:
'The alias of the project'
end
post
do
project_alias
=
project
.
project_aliases
.
create
(
name:
params
[
:name
])
if
project_alias
.
valid?
present
project_alias
,
with:
EE
::
API
::
Entities
::
ProjectAlias
else
render_validation_error!
(
project_alias
)
end
end
desc
'Delete a project alias by name'
delete
':name'
do
project_alias
.
destroy
status
204
end
end
end
end
ee/lib/ee/api/endpoints.rb
View file @
f7f4c7e1
...
...
@@ -31,6 +31,7 @@ module EE
mount
::
API
::
ProjectApprovals
mount
::
API
::
Vulnerabilities
mount
::
API
::
MergeRequestApprovals
mount
::
API
::
ProjectAliases
version
'v3'
,
using: :path
do
# Although the following endpoints are kept behind V3 namespace,
...
...
ee/lib/ee/api/entities.rb
View file @
f7f4c7e1
...
...
@@ -729,6 +729,10 @@ module EE
class
ManagedLicense
<
Grape
::
Entity
expose
:id
,
:name
,
:approval_status
end
class
ProjectAlias
<
Grape
::
Entity
expose
:id
,
:project_id
,
:name
end
end
end
end
ee/spec/fixtures/api/schemas/public_api/v4/project_alias.json
0 → 100644
View file @
f7f4c7e1
{
"type"
:
"object"
,
"allOf"
:
[
{
"required"
:
[
"id"
,
"project_id"
,
"name"
],
"properties"
:
{
"id"
:
{
"type"
:
"integer"
},
"project_id"
:
{
"type"
:
"integer"
},
"name"
:
{
"type"
:
"string"
}
}
}
]
}
ee/spec/fixtures/api/schemas/public_api/v4/project_aliases.json
0 → 100644
View file @
f7f4c7e1
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"./project_alias.json"
}
}
ee/spec/models/project_spec.rb
View file @
f7f4c7e1
...
...
@@ -34,6 +34,7 @@ describe Project do
it
{
is_expected
.
to
have_many
(
:package_files
).
class_name
(
'Packages::PackageFile'
)
}
it
{
is_expected
.
to
have_one
(
:github_service
)
}
it
{
is_expected
.
to
have_many
(
:project_aliases
)
}
end
context
'scopes'
do
...
...
ee/spec/requests/api/project_aliases_spec.rb
0 → 100644
View file @
f7f4c7e1
require
'spec_helper'
describe
API
::
ProjectAliases
,
api:
true
do
set
(
:user
)
{
create
(
:user
)
}
set
(
:admin
)
{
create
(
:admin
)
}
describe
'GET /project_aliases'
do
context
'anonymous user'
do
before
do
get
api
(
'/project_aliases'
)
end
it
'returns 401'
do
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
context
'regular user'
do
before
do
get
api
(
'/project_aliases'
,
user
)
end
it
'returns 403'
do
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'admin'
do
let!
(
:project_alias_1
)
{
create
(
:project_alias
)
}
let!
(
:project_alias_2
)
{
create
(
:project_alias
)
}
before
do
get
api
(
'/project_aliases'
,
admin
)
end
it
'returns the project aliases list'
do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/project_aliases'
,
dir:
'ee'
)
end
end
end
describe
'GET /project_aliases/:name'
do
let
(
:project_alias
)
{
create
(
:project_alias
)
}
context
'anonymous user'
do
before
do
get
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
)
end
it
'returns 401'
do
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
context
'regular user'
do
before
do
get
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
,
user
)
end
it
'returns 403'
do
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'admin'
do
context
'existing project alias'
do
before
do
get
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
,
admin
)
end
it
'returns the project alias'
do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/project_alias'
,
dir:
'ee'
)
end
end
context
'non-existent project alias'
do
before
do
get
api
(
"/project_aliases/some-project"
,
admin
)
end
it
'returns 404'
do
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
end
describe
'POST /project_aliases'
do
let
(
:project
)
{
create
(
:project
)
}
context
'anonymous user'
do
before
do
post
api
(
"/project_aliases"
)
end
it
'returns 401'
do
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
context
'regular user'
do
before
do
post
api
(
"/project_aliases"
,
user
)
end
it
'returns 403'
do
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'admin'
do
context
'existing project alias'
do
let
(
:project_alias
)
{
create
(
:project_alias
)
}
before
do
post
api
(
"/project_aliases"
,
admin
),
params:
{
project_id:
project
.
id
,
name:
project_alias
.
name
}
end
it
'returns 400'
do
expect
(
response
).
to
have_gitlab_http_status
(
400
)
end
end
context
'non-existent project alias'
do
before
do
post
api
(
"/project_aliases"
,
admin
),
params:
{
project_id:
project
.
id
,
name:
'some-project'
}
end
it
'returns 200'
do
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
response
).
to
match_response_schema
(
'public_api/v4/project_alias'
,
dir:
'ee'
)
end
end
end
end
describe
'DELETE /project_aliases/:name'
do
let
(
:project_alias
)
{
create
(
:project_alias
)
}
context
'anonymous user'
do
before
do
delete
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
)
end
it
'returns 401'
do
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
end
context
'regular user'
do
before
do
delete
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
,
user
)
end
it
'returns 403'
do
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
context
'admin'
do
context
'existing project alias'
do
before
do
delete
api
(
"/project_aliases/
#{
project_alias
.
name
}
"
,
admin
)
end
it
'returns 204'
do
expect
(
response
).
to
have_gitlab_http_status
(
204
)
end
end
context
'non-existent project alias'
do
before
do
delete
api
(
"/project_aliases/some-project"
,
admin
)
end
it
'returns 404'
do
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
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