Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
b2b9d63f
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,发现更多精彩内容 >>
提交
b2b9d63f
编写于
8月 23, 2017
作者:
R
Rubén Dávila
提交者:
Mike Greiling
8月 26, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add validation to check visibility level of sub groups.
上级
d413f8e4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
4 deletion
+60
-4
app/models/group.rb
app/models/group.rb
+16
-4
spec/models/group_spec.rb
spec/models/group_spec.rb
+44
-0
未找到文件。
app/models/group.rb
浏览文件 @
b2b9d63f
...
...
@@ -26,6 +26,7 @@ class Group < Namespace
validate
:avatar_type
,
if:
->
(
user
)
{
user
.
avatar
.
present?
&&
user
.
avatar_changed?
}
validate
:visibility_level_allowed_by_projects
validate
:visibility_level_allowed_by_sub_groups
,
if: :visibility_level_changed?
validate
:visibility_level_allowed_by_parent
validates
:avatar
,
file_size:
{
maximum:
200
.
kilobytes
.
to_i
}
...
...
@@ -112,14 +113,25 @@ class Group < Namespace
end
def
visibility_level_allowed_by_projects
allowed_by_projects
=
self
.
projects
.
where
(
'visibility_level > ?'
,
self
.
visibility_level
).
none?
check_visibility_level_for
(
:projects
)
end
def
visibility_level_allowed_by_sub_groups
check_visibility_level_for
(
:children
)
end
unless
allowed_by_projects
def
check_visibility_level_for
(
children_type
)
base_query
=
public_send
(
children_type
)
children_have_higher_visibility
=
base_query
.
where
(
'visibility_level > ?'
,
visibility_level
).
exists?
if
children_have_higher_visibility
children_label
=
children_type
==
:projects
?
'projects'
:
'sub groups'
level_name
=
Gitlab
::
VisibilityLevel
.
level_name
(
visibility_level
).
downcase
self
.
errors
.
add
(
:visibility_level
,
"
#{
level_name
}
is not allowed since there are projects with higher visibility."
)
self
.
errors
.
add
(
:visibility_level
,
"
#{
level_name
}
is not allowed since there are
#{
children_label
}
with higher visibility."
)
end
allowed_by_projects
children_have_higher_visibility
end
def
avatar_url
(
**
args
)
...
...
spec/models/group_spec.rb
浏览文件 @
b2b9d63f
...
...
@@ -117,6 +117,50 @@ describe Group do
end
end
end
describe
'#visibility_level_allowed_by_projects'
do
let!
(
:internal_group
)
{
create
(
:group
,
:internal
)
}
let!
(
:internal_project
)
{
create
(
:project
,
:internal
,
group:
internal_group
)
}
context
'when group has a lower visibility'
do
it
'is invalid'
do
internal_group
.
visibility_level
=
Gitlab
::
VisibilityLevel
::
PRIVATE
expect
(
internal_group
).
to
be_invalid
expect
(
internal_group
.
errors
[
:visibility_level
]).
to
include
(
'private is not allowed since there are projects with higher visibility.'
)
end
end
context
'when group has a higher visibility'
do
it
'is valid'
do
internal_group
.
visibility_level
=
Gitlab
::
VisibilityLevel
::
PUBLIC
expect
(
internal_group
).
to
be_valid
end
end
end
describe
'#visibility_level_allowed_by_sub_groups'
do
let!
(
:internal_group
)
{
create
(
:group
,
:internal
)
}
let!
(
:internal_sub_group
)
{
create
(
:group
,
:internal
,
parent:
internal_group
)
}
context
'when parent group has a lower visibility'
do
it
'is invalid'
do
internal_group
.
visibility_level
=
Gitlab
::
VisibilityLevel
::
PRIVATE
expect
(
internal_group
).
to
be_invalid
expect
(
internal_group
.
errors
[
:visibility_level
]).
to
include
(
'private is not allowed since there are sub groups with higher visibility.'
)
end
end
context
'when parent group has a higher visibility'
do
it
'is valid'
do
internal_group
.
visibility_level
=
Gitlab
::
VisibilityLevel
::
PUBLIC
expect
(
internal_group
).
to
be_valid
end
end
end
end
describe
'.visible_to_user'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录