Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
9410f215
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,发现更多精彩内容 >>
未验证
提交
9410f215
编写于
12月 26, 2016
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add nested groups support to the Groups::CreateService
Signed-off-by:
N
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
上级
7b4b3d5f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
4 deletion
+40
-4
app/services/groups/create_service.rb
app/services/groups/create_service.rb
+13
-0
spec/services/groups/create_service_spec.rb
spec/services/groups/create_service_spec.rb
+27
-4
未找到文件。
app/services/groups/create_service.rb
浏览文件 @
9410f215
...
...
@@ -12,6 +12,19 @@ module Groups
return
@group
end
parent_id
=
params
[
:parent_id
]
if
parent_id
parent
=
Group
.
find
(
parent_id
)
unless
can?
(
current_user
,
:admin_group
,
parent
)
@group
.
parent_id
=
nil
@group
.
errors
.
add
(
:parent_id
,
'manage access required to create subgroup'
)
return
@group
end
end
@group
.
name
||=
@group
.
path
.
dup
@group
.
save
@group
.
add_owner
(
current_user
)
...
...
spec/services/groups/create_service_spec.rb
浏览文件 @
9410f215
require
'spec_helper'
describe
Groups
::
CreateService
,
services:
true
do
let!
(
:user
)
{
create
(
:user
)
}
describe
Groups
::
CreateService
,
'#execute'
,
services:
true
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:group_params
)
{
{
path:
"group_path"
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
}
}
describe
"execute"
do
let!
(
:service
)
{
described_class
.
new
(
user
,
group_params
)
}
describe
'visibility level restrictions'
do
let!
(
:service
)
{
described_class
.
new
(
user
,
group_params
)
}
subject
{
service
.
execute
}
context
"create groups without restricted visibility level"
do
...
...
@@ -14,7 +15,29 @@ describe Groups::CreateService, services: true do
context
"cannot create group with restricted visibility level"
do
before
{
allow_any_instance_of
(
ApplicationSetting
).
to
receive
(
:restricted_visibility_levels
).
and_return
([
Gitlab
::
VisibilityLevel
::
PUBLIC
])
}
it
{
is_expected
.
not_to
be_persisted
}
end
end
describe
'creating subgroup'
do
let!
(
:group
)
{
create
(
:group
)
}
let!
(
:service
)
{
described_class
.
new
(
user
,
group_params
.
merge
(
parent_id:
group
.
id
))
}
subject
{
service
.
execute
}
context
'as group owner'
do
before
{
group
.
add_owner
(
user
)
}
it
{
is_expected
.
to
be_persisted
}
end
context
'as guest'
do
it
'does not save group and returns an error'
do
is_expected
.
not_to
be_persisted
expect
(
subject
.
errors
[
:parent_id
].
first
).
to
eq
(
'manage access required to create subgroup'
)
expect
(
subject
.
parent_id
).
to
be_nil
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录