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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
78509cee
Commit
78509cee
authored
Mar 09, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
68ad0116
6908c5f7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
141 additions
and
13 deletions
+141
-13
app/models/application_setting.rb
app/models/application_setting.rb
+1
-1
app/models/email.rb
app/models/email.rb
+1
-1
app/models/member.rb
app/models/member.rb
+1
-1
app/models/user.rb
app/models/user.rb
+3
-3
app/validators/devise_email_validator.rb
app/validators/devise_email_validator.rb
+36
-0
app/validators/email_validator.rb
app/validators/email_validator.rb
+0
-7
changelogs/unreleased/24971-align-emailvalidator-to-validate_email-gem-implementation.yml
...n-emailvalidator-to-validate_email-gem-implementation.yml
+5
-0
spec/validators/devise_email_validator_spec.rb
spec/validators/devise_email_validator_spec.rb
+94
-0
No files found.
app/models/application_setting.rb
View file @
78509cee
...
...
@@ -69,7 +69,7 @@ class ApplicationSetting < ActiveRecord::Base
url:
true
validates
:admin_notification_email
,
email:
true
,
devise_
email:
true
,
allow_blank:
true
validates
:two_factor_grace_period
,
...
...
app/models/email.rb
View file @
78509cee
...
...
@@ -7,7 +7,7 @@ class Email < ActiveRecord::Base
belongs_to
:user
validates
:user_id
,
presence:
true
validates
:email
,
presence:
true
,
uniqueness:
true
,
email:
true
validates
:email
,
presence:
true
,
uniqueness:
true
,
devise_
email:
true
validate
:unique_email
,
if:
->
(
email
)
{
email
.
email_changed?
}
scope
:confirmed
,
->
{
where
.
not
(
confirmed_at:
nil
)
}
...
...
app/models/member.rb
View file @
78509cee
...
...
@@ -28,7 +28,7 @@ class Member < ActiveRecord::Base
presence:
{
if: :invite?
},
email:
{
devise_
email:
{
allow_nil:
true
},
uniqueness:
{
...
...
app/models/user.rb
View file @
78509cee
...
...
@@ -162,9 +162,9 @@ class User < ApplicationRecord
validates
:name
,
presence:
true
validates
:email
,
confirmation:
true
validates
:notification_email
,
presence:
true
validates
:notification_email
,
email:
true
,
if:
->
(
user
)
{
user
.
notification_email
!=
user
.
email
}
validates
:public_email
,
presence:
true
,
uniqueness:
true
,
email:
true
,
allow_blank:
true
validates
:commit_email
,
email:
true
,
allow_nil:
true
,
if:
->
(
user
)
{
user
.
commit_email
!=
user
.
email
}
validates
:notification_email
,
devise_
email:
true
,
if:
->
(
user
)
{
user
.
notification_email
!=
user
.
email
}
validates
:public_email
,
presence:
true
,
uniqueness:
true
,
devise_
email:
true
,
allow_blank:
true
validates
:commit_email
,
devise_
email:
true
,
allow_nil:
true
,
if:
->
(
user
)
{
user
.
commit_email
!=
user
.
email
}
validates
:bio
,
length:
{
maximum:
255
},
allow_blank:
true
validates
:projects_limit
,
presence:
true
,
...
...
app/validators/devise_email_validator.rb
0 → 100644
View file @
78509cee
# frozen_string_literal: true
# DeviseEmailValidator
#
# Custom validator for email formats. It asserts that there are no
# @ symbols or whitespaces in either the localpart or the domain, and that
# there is a single @ symbol separating the localpart and the domain.
#
# The available options are:
# - regexp: Email regular expression used to validate email formats as instance of Regexp class.
# If provided value has different type then a new Rexexp class instance is created using the value.
# Default: +Devise.email_regexp+
#
# Example:
# class User < ActiveRecord::Base
# validates :personal_email, devise_email: true
#
# validates :public_email, devise_email: { regexp: Devise.email_regexp }
# end
class
DeviseEmailValidator
<
ActiveModel
::
EachValidator
DEFAULT_OPTIONS
=
{
regexp:
Devise
.
email_regexp
}.
freeze
def
initialize
(
options
)
options
.
reverse_merge!
(
DEFAULT_OPTIONS
)
raise
ArgumentError
,
"Expected 'regexp' argument of type class Regexp"
unless
options
[
:regexp
].
is_a?
(
Regexp
)
super
(
options
)
end
def
validate_each
(
record
,
attribute
,
value
)
record
.
errors
.
add
(
attribute
,
:invalid
)
unless
value
=~
options
[
:regexp
]
end
end
app/validators/email_validator.rb
deleted
100644 → 0
View file @
68ad0116
# frozen_string_literal: true
class
EmailValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
record
.
errors
.
add
(
attribute
,
:invalid
)
unless
value
=~
Devise
.
email_regexp
end
end
changelogs/unreleased/24971-align-emailvalidator-to-validate_email-gem-implementation.yml
0 → 100644
View file @
78509cee
---
title
:
Align EmailValidator to validate_email gem implementation
merge_request
:
24971
author
:
Horatiu Eugen Vlad
type
:
fixed
spec/validators/devise_email_validator_spec.rb
0 → 100644
View file @
78509cee
# frozen_string_literal: true
require
'spec_helper'
describe
DeviseEmailValidator
do
let!
(
:user
)
{
build
(
:user
,
public_email:
'test@example.com'
)
}
subject
{
validator
.
validate
(
user
)
}
describe
'validations'
do
context
'by default'
do
let
(
:validator
)
{
described_class
.
new
(
attributes:
[
:public_email
])
}
it
'allows when email is valid'
do
subject
expect
(
user
.
errors
).
to
be_empty
end
it
'returns error when email is invalid'
do
user
.
public_email
=
'invalid'
subject
expect
(
user
.
errors
).
to
be_present
expect
(
user
.
errors
.
first
[
1
]).
to
eq
'is invalid'
end
it
'returns error when email is nil'
do
user
.
public_email
=
nil
subject
expect
(
user
.
errors
).
to
be_present
end
it
'returns error when email is blank'
do
user
.
public_email
=
''
subject
expect
(
user
.
errors
).
to
be_present
expect
(
user
.
errors
.
first
[
1
]).
to
eq
'is invalid'
end
end
end
context
'when regexp is set as Regexp'
do
let
(
:validator
)
{
described_class
.
new
(
attributes:
[
:public_email
],
regexp:
/[0-9]/
)
}
it
'allows when value match'
do
user
.
public_email
=
'1'
subject
expect
(
user
.
errors
).
to
be_empty
end
it
'returns error when value does not match'
do
subject
expect
(
user
.
errors
).
to
be_present
end
end
context
'when regexp is set as String'
do
it
'raise argument error'
do
expect
{
described_class
.
new
(
{
regexp:
'something'
}
)
}.
to
raise_error
ArgumentError
end
end
context
'when allow_nil is set to true'
do
let
(
:validator
)
{
described_class
.
new
(
attributes:
[
:public_email
],
allow_nil:
true
)
}
it
'allows when email is nil'
do
user
.
public_email
=
nil
subject
expect
(
user
.
errors
).
to
be_empty
end
end
context
'when allow_blank is set to true'
do
let
(
:validator
)
{
described_class
.
new
(
attributes:
[
:public_email
],
allow_blank:
true
)
}
it
'allows when email is blank'
do
user
.
public_email
=
''
subject
expect
(
user
.
errors
).
to
be_empty
end
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