Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
031122eb
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
031122eb
编写于
3月 30, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add container repository create service with specs
上级
4407d3cf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
111 addition
and
0 deletion
+111
-0
app/models/container_repository.rb
app/models/container_repository.rb
+4
-0
app/services/container_registry/create_repository_service.rb
app/services/container_registry/create_repository_service.rb
+33
-0
spec/services/container_registry/create_repository_service_spec.rb
...ices/container_registry/create_repository_service_spec.rb
+74
-0
未找到文件。
app/models/container_repository.rb
浏览文件 @
031122eb
...
...
@@ -58,4 +58,8 @@ class ContainerRepository < ActiveRecord::Base
client
.
delete_repository_tag
(
self
.
path
,
digest
)
end
end
def
self
.
create_from_path
(
path
)
self
.
create
(
project:
path
.
repository_project
,
name:
path
.
repository_name
)
end
end
app/services/container_registry/create_repository_service.rb
0 → 100644
浏览文件 @
031122eb
module
ContainerRegistry
##
# Service for creating a container repository.
#
# It is usually executed before registry authenticator returns
# a token for given request.
#
class
CreateRepositoryService
<
BaseService
def
execute
(
path
)
@path
=
path
return
if
path
.
has_repository?
unless
user_can_create?
||
legacy_trigger_can_create?
raise
Gitlab
::
Access
::
AccessDeniedError
end
ContainerRepository
.
create_from_path
(
path
)
end
private
def
user_can_create?
can?
(
@current_user
,
:create_container_image
,
@path
.
repository_project
)
end
## TODO, remove it after removing legacy triggers.
#
def
legacy_trigger_can_create?
@current_user
.
nil?
&&
@project
==
@path
.
repository_project
end
end
end
spec/services/container_registry/create_repository_service_spec.rb
0 → 100644
浏览文件 @
031122eb
require
'spec_helper'
describe
ContainerRegistry
::
CreateRepositoryService
,
'#execute'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:path
)
do
ContainerRegistry
::
Path
.
new
(
"
#{
project
.
full_path
}
/my/image"
)
end
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
before
do
stub_container_registry_config
(
enabled:
true
)
end
context
'when container repository already exists'
do
before
do
create
(
:container_repository
,
project:
project
,
name:
'my/image'
)
end
it
'does not create container repository again'
do
expect
{
service
.
execute
(
path
)
}
.
to
raise_error
(
Gitlab
::
Access
::
AccessDeniedError
)
.
and
change
{
ContainerRepository
.
count
}.
by
(
0
)
end
end
context
'when repository is created by an user'
do
context
'when user has no ability to create a repository'
do
it
'does not create a new container repository'
do
expect
{
service
.
execute
(
path
)
}
.
to
raise_error
(
Gitlab
::
Access
::
AccessDeniedError
)
.
and
change
{
ContainerRepository
.
count
}.
by
(
0
)
end
end
context
'when user has ability do create a repository'
do
before
do
project
.
add_developer
(
user
)
end
it
'creates a new container repository'
do
expect
{
service
.
execute
(
path
)
}
.
to
change
{
project
.
container_repositories
.
count
}.
by
(
1
)
end
end
end
context
'when repository is created by a legacy pipeline trigger'
do
let
(
:user
)
{
nil
}
context
'when repository path matches authenticated project'
do
it
'creates a new container repository'
do
expect
{
service
.
execute
(
path
)
}
.
to
change
{
project
.
container_repositories
.
count
}.
by
(
1
)
end
end
context
'when repository path does not match authenticated project'
do
let
(
:private_project
)
{
create
(
:empty_project
,
:private
)
}
let
(
:path
)
do
ContainerRegistry
::
Path
.
new
(
"
#{
private_project
.
full_path
}
/my/image"
)
end
it
'does not create a new container repository'
do
expect
{
service
.
execute
(
path
)
}
.
to
raise_error
(
Gitlab
::
Access
::
AccessDeniedError
)
.
and
change
{
ContainerRepository
.
count
}.
by
(
0
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录