Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
6895e1ad
提交
6895e1ad
编辑于
3 years ago
作者:
Lee Tickett
提交者:
Kerri Miller
3 years ago
浏览文件
操作
下载
补丁
差异文件
Enforce unique contact email for group hierarchy
Changelog: added
上级
93ccfa72
No related branches found
No related tags found
无相关合并请求
变更
3
隐藏空白变更内容
行内
左右并排
显示
3 个更改的文件
app/models/customer_relations/contact.rb
+11
-0
11 个添加, 0 个删除
app/models/customer_relations/contact.rb
locale/gitlab.pot
+3
-0
3 个添加, 0 个删除
locale/gitlab.pot
spec/models/customer_relations/contact_spec.rb
+32
-0
32 个添加, 0 个删除
spec/models/customer_relations/contact_spec.rb
有
46 个添加
和
0 个删除
app/models/customer_relations/contact.rb
+
11
−
0
浏览文件 @
6895e1ad
...
...
@@ -24,6 +24,7 @@ class CustomerRelations::Contact < ApplicationRecord
validates
:email
,
length:
{
maximum:
255
}
validates
:description
,
length:
{
maximum:
1024
}
validate
:validate_email_format
validate
:unique_email_for_group_hierarchy
def
self
.
find_ids_by_emails
(
group_id
,
emails
)
raise
ArgumentError
,
"Cannot lookup more than
#{
MAX_PLUCK
}
emails"
if
emails
.
length
>
MAX_PLUCK
...
...
@@ -39,4 +40,14 @@ def validate_email_format
self
.
errors
.
add
(
:email
,
I18n
.
t
(
:invalid
,
scope:
'valid_email.validations.email'
))
unless
ValidateEmail
.
valid?
(
self
.
email
)
end
def
unique_email_for_group_hierarchy
return
unless
group
return
unless
email
duplicate_email_exists
=
CustomerRelations
::
Contact
.
where
(
group_id:
group
.
self_and_hierarchy
.
pluck
(
:id
),
email:
email
)
.
where
.
not
(
id:
id
).
exists?
self
.
errors
.
add
(
:email
,
_
(
'contact with same email already exists in group hierarchy'
))
if
duplicate_email_exists
end
end
此差异已折叠。
点击以展开。
locale/gitlab.pot
+
3
−
0
浏览文件 @
6895e1ad
...
...
@@ -41910,6 +41910,9 @@ msgstr ""
msgid "compliance violation has already been recorded"
msgstr ""
msgid "contact with same email already exists in group hierarchy"
msgstr ""
msgid "container_name can contain only lowercase letters, digits, '-', and '.' and must start and end with an alphanumeric character"
msgstr ""
...
...
此差异已折叠。
点击以展开。
spec/models/customer_relations/contact_spec.rb
+
32
−
0
浏览文件 @
6895e1ad
...
...
@@ -26,6 +26,38 @@
it_behaves_like
'an object with RFC3696 compliant email-formatted attributes'
,
:email
end
describe
'#unique_email_for_group_hierarchy'
do
let_it_be
(
:parent
)
{
create
(
:group
)
}
let_it_be
(
:group
)
{
create
(
:group
,
parent:
parent
)
}
let_it_be
(
:subgroup
)
{
create
(
:group
,
parent:
group
)
}
let_it_be
(
:existing_contact
)
{
create
(
:contact
,
group:
group
)
}
context
'with unique email for group hierarchy'
do
subject
{
build
(
:contact
,
group:
group
)
}
it
{
is_expected
.
to
be_valid
}
end
context
'with duplicate email in group'
do
subject
{
build
(
:contact
,
email:
existing_contact
.
email
,
group:
group
)
}
it
{
is_expected
.
to
be_invalid
}
end
context
'with duplicate email in parent group'
do
subject
{
build
(
:contact
,
email:
existing_contact
.
email
,
group:
subgroup
)
}
it
{
is_expected
.
to
be_invalid
}
end
context
'with duplicate email in subgroup'
do
subject
{
build
(
:contact
,
email:
existing_contact
.
email
,
group:
parent
)
}
it
{
is_expected
.
to
be_invalid
}
end
end
describe
'#before_validation'
do
it
'strips leading and trailing whitespace'
do
contact
=
described_class
.
new
(
first_name:
' First '
,
last_name:
' Last '
,
phone:
' 123456 '
)
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录