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
Jérome Perrin
gitlab-ce
Commits
8ba9c2bd
Commit
8ba9c2bd
authored
Sep 21, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ContainerTag and ContainerRepository frontend API
parent
ee3cf5d6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
49 deletions
+96
-49
app/controllers/projects/registry/repositories_controller.rb
app/controllers/projects/registry/repositories_controller.rb
+4
-40
app/controllers/projects/registry/tags_controller.rb
app/controllers/projects/registry/tags_controller.rb
+23
-8
app/serializers/container_repositories_serializer.rb
app/serializers/container_repositories_serializer.rb
+3
-0
app/serializers/container_repository_entity.rb
app/serializers/container_repository_entity.rb
+25
-0
app/serializers/container_tag_entity.rb
app/serializers/container_tag_entity.rb
+23
-0
app/serializers/container_tags_serializer.rb
app/serializers/container_tags_serializer.rb
+17
-0
config/routes/project.rb
config/routes/project.rb
+1
-1
No files found.
app/controllers/projects/registry/repositories_controller.rb
View file @
8ba9c2bd
...
...
@@ -10,31 +10,9 @@ module Projects
respond_to
do
|
format
|
format
.
html
format
.
json
do
# Remove code below
render
json:
[
{
name:
'gitlab-org/omnibus-gitlab/foo'
,
tags_path:
'foo'
,
destroy_path:
'bar'
,
location:
'foo'
,
id:
'134'
,
destroy_path:
'bar'
},
{
name:
'gitlab-org/omnibus-gitlab'
,
tags_path:
'foo'
,
destroy_path:
'bar'
,
location:
'foo'
,
id:
'123'
,
},
{
name:
'gitlab-org/omnibus-gitlab/bar'
,
tags_path:
'foo'
,
destroy_path:
'bar'
,
location:
'foo'
,
id:
'973'
,
}
]
render
json:
ContainerRepositoriesSerializer
.
new
(
project:
project
,
current_user:
current_user
)
.
represent
(
@images
)
end
end
end
...
...
@@ -42,25 +20,11 @@ module Projects
def
destroy
if
image
.
destroy
respond_to
do
|
format
|
# TODO: @Kamil, I don't think this is used ever. Should we keep it or remove it?
format
.
html
do
redirect_to
project_container_registry_index_path
(
@project
),
status:
302
,
notice:
'Image repository has been removed successfully!'
end
format
.
json
{
head
:no_content
}
end
else
respond_to
do
|
format
|
# TODO: @Kamil, I don't think this is used ever. Should we keep it or remove it?
format
.
html
do
redirect_to
project_container_registry_index_path
(
@project
),
status:
302
,
alert:
'Failed to remove image repository!'
end
format
.
json
{
head
:no_content
}
format
.
json
{
head
:bad_request
}
end
end
end
...
...
app/controllers/projects/registry/tags_controller.rb
View file @
8ba9c2bd
...
...
@@ -3,20 +3,35 @@ module Projects
class
TagsController
<
::
Projects
::
Registry
::
ApplicationController
before_action
:authorize_update_container_image!
,
only:
[
:destroy
]
def
index
respond_to
do
|
format
|
format
.
json
do
render
json:
ContainerTagsSerializer
.
new
(
project:
@project
,
current_user:
@current_user
)
.
with_pagination
(
request
,
response
)
.
represent
(
tags
)
end
end
end
def
destroy
if
tag
.
delete
redirect_to
project_container_registry_index_path
(
@project
),
status:
302
,
notice:
'Registry tag has been removed successfully!'
else
redirect_to
project_container_registry_index_path
(
@project
),
status:
302
,
alert:
'Failed to remove registry tag!'
respond_to
do
|
format
|
format
.
json
do
if
tag
.
delete
format
.
json
{
head
:no_content
}
else
format
.
json
{
head
:bad_request
}
end
end
end
end
private
def
tags
Kaminari
::
PaginatableArray
.
new
(
image
.
tags
,
limit:
15
)
end
def
image
@image
||=
project
.
container_repositories
.
find
(
params
[
:repository_id
])
...
...
app/serializers/container_repositories_serializer.rb
0 → 100644
View file @
8ba9c2bd
class
ContainerRepositoriesSerializer
<
BaseSerializer
entity
ContainerRepositoryEntity
end
app/serializers/container_repository_entity.rb
0 → 100644
View file @
8ba9c2bd
class
ContainerRepositoryEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:id
,
:path
,
:location
expose
:tags_path
do
|
repository
|
project_registry_repository_tags_path
(
project
,
repository
,
format: :json
)
end
expose
:destroy_path
,
if:
->
(
*
)
{
can_destroy?
}
do
|
repository
|
project_container_registry_path
(
project
,
repository
,
format: :json
)
end
private
alias_method
:repository
,
:object
def
project
request
.
project
end
def
can_destroy?
can?
(
request
.
current_user
,
:update_container_image
,
project
)
end
end
app/serializers/container_tag_entity.rb
0 → 100644
View file @
8ba9c2bd
class
ContainerTagEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:name
,
:location
,
:revision
,
:total_size
,
:created_at
expose
:destroy_path
,
if:
->
(
*
)
{
can_destroy?
}
do
|
tag
|
project_registry_repository_tag_path
(
project
,
tag
.
repository
,
tag
.
name
,
format: :json
)
end
private
alias_method
:tag
,
:object
def
project
request
.
project
end
def
can_destroy?
# TODO: We check permission against @project, not tag,
# as tag is no AR object that is attached to project
can?
(
request
.
current_user
,
:update_container_image
,
project
)
end
end
app/serializers/container_tags_serializer.rb
0 → 100644
View file @
8ba9c2bd
class
ContainerTagsSerializer
<
BaseSerializer
entity
ContainerTagEntity
def
with_pagination
(
request
,
response
)
tap
{
@paginator
=
Gitlab
::
Serializer
::
Pagination
.
new
(
request
,
response
)
}
end
def
paginated?
@paginator
.
present?
end
def
represent
(
resource
,
opts
=
{})
resource
=
@paginator
.
paginate
(
resource
)
if
paginated?
super
(
resource
,
opts
)
end
end
config/routes/project.rb
View file @
8ba9c2bd
...
...
@@ -271,7 +271,7 @@ constraints(ProjectUrlConstrainer.new) do
namespace
:registry
do
resources
:repository
,
only:
[]
do
resources
:tags
,
only:
[
:destroy
],
resources
:tags
,
only:
[
:
index
,
:
destroy
],
constraints:
{
id:
Gitlab
::
Regex
.
container_registry_tag_regex
}
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