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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
969de4c1
Commit
969de4c1
authored
Feb 25, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix EmailsOnPush to allow sending from @company.com for GitLab at gitlab.corp.company.com.
parent
5d863321
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
5 deletions
+41
-5
app/mailers/notify.rb
app/mailers/notify.rb
+16
-1
spec/mailers/notify_spec.rb
spec/mailers/notify_spec.rb
+25
-4
No files found.
app/mailers/notify.rb
View file @
969de4c1
...
@@ -34,6 +34,20 @@ class Notify < ActionMailer::Base
...
@@ -34,6 +34,20 @@ class Notify < ActionMailer::Base
)
)
end
end
# Splits "gitlab.corp.company.com" up into "gitlab.corp.company.com",
# "corp.company.com" and "company.com".
# Respects set tld length so "company.co.uk" won't match "somethingelse.uk"
def
self
.
allowed_email_domains
domain_parts
=
Gitlab
.
config
.
gitlab
.
host
.
split
(
"."
)
allowed_domains
=
[]
begin
allowed_domains
<<
domain_parts
.
join
(
"."
)
domain_parts
.
shift
end
while
domain_parts
.
length
>
ActionDispatch
::
Http
::
URL
.
tld_length
allowed_domains
end
private
private
# The default email address to send emails from
# The default email address to send emails from
...
@@ -50,7 +64,8 @@ class Notify < ActionMailer::Base
...
@@ -50,7 +64,8 @@ class Notify < ActionMailer::Base
address
=
default_sender_address
address
=
default_sender_address
address
.
display_name
=
sender
.
name
address
.
display_name
=
sender
.
name
if
send_from_user_email
&&
sender
.
email
.
end_with?
(
"@
#{
Gitlab
.
config
.
gitlab
.
host
}
"
)
sender_domain
=
sender
.
email
.
split
(
"@"
).
last
if
send_from_user_email
&&
self
.
class
.
allowed_email_domains
.
include?
(
sender_domain
)
address
.
address
=
sender
.
email
address
.
address
=
sender
.
email
end
end
...
...
spec/mailers/notify_spec.rb
View file @
969de4c1
...
@@ -607,11 +607,14 @@ describe Notify do
...
@@ -607,11 +607,14 @@ describe Notify do
let
(
:send_from_committer_email
)
{
true
}
let
(
:send_from_committer_email
)
{
true
}
context
"when the committer email domain matches"
do
before
do
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:host
).
and_return
(
"gitlab.corp.company.com"
)
end
context
"when the committer email domain is within the GitLab domain"
do
before
do
before
do
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:host
).
and_return
(
"gitlab.dev"
)
user
.
update_attribute
(
:email
,
"user@company.com"
)
user
.
update_attribute
(
:email
,
"user@
#{
Gitlab
.
config
.
gitlab
.
host
}
"
)
user
.
confirm!
user
.
confirm!
end
end
...
@@ -621,7 +624,25 @@ describe Notify do
...
@@ -621,7 +624,25 @@ describe Notify do
end
end
end
end
context
"when the committer email doesn't match"
do
context
"when the committer email domain is not completely within the GitLab domain"
do
before
do
user
.
update_attribute
(
:email
,
"user@something.company.com"
)
user
.
confirm!
end
it
"is sent from the default email"
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
expect
(
sender
.
address
).
to
eq
(
gitlab_sender
)
end
end
context
"when the committer email domain is outside the GitLab domain"
do
before
do
user
.
update_attribute
(
:email
,
"user@mpany.com"
)
user
.
confirm!
end
it
"is sent from the default email"
do
it
"is sent from the default email"
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
...
...
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