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
8ac11f4e
Commit
8ac11f4e
authored
Dec 08, 2021
by
Eugie Limpin
Committed by
Aleksei Lipniagov
Dec 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send account validation email when pipeline fails
parent
b845112d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
3 deletions
+118
-3
ee/app/models/ee/user.rb
ee/app/models/ee/user.rb
+1
-1
ee/app/services/ee/notification_service.rb
ee/app/services/ee/notification_service.rb
+23
-0
ee/config/feature_flags/development/account_validation_email.yml
...ig/feature_flags/development/account_validation_email.yml
+8
-0
ee/spec/models/ee/user_spec.rb
ee/spec/models/ee/user_spec.rb
+2
-2
ee/spec/services/ee/notification_service_spec.rb
ee/spec/services/ee/notification_service_spec.rb
+84
-0
No files found.
ee/app/models/ee/user.rb
View file @
8ac11f4e
...
@@ -461,7 +461,7 @@ module EE
...
@@ -461,7 +461,7 @@ module EE
end
end
def
requires_credit_card?
(
project
)
def
requires_credit_card?
(
project
)
return
false
unless
::
Gitlab
.
com?
return
false
unless
::
Gitlab
.
dev_env_or_
com?
return
false
unless
created_after_credit_card_release_day?
(
project
)
return
false
unless
created_after_credit_card_release_day?
(
project
)
root_namespace
=
project
.
root_namespace
root_namespace
=
project
.
root_namespace
...
...
ee/app/services/ee/notification_service.rb
View file @
8ac11f4e
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
module
EE
module
EE
module
NotificationService
module
NotificationService
include
::
Gitlab
::
Utils
::
UsageData
include
::
Gitlab
::
Utils
::
UsageData
extend
::
Gitlab
::
Utils
::
Override
# When we add approvers to a merge request we should send an email to:
# When we add approvers to a merge request we should send an email to:
#
#
...
@@ -91,6 +92,13 @@ module EE
...
@@ -91,6 +92,13 @@ module EE
end
end
end
end
override
:pipeline_finished
def
pipeline_finished
(
pipeline
,
ref_status:
nil
,
recipients:
nil
)
super
send_account_validation_email
(
pipeline
)
end
private
private
def
oncall_user_removed_recipients
(
rotation
,
removed_user
)
def
oncall_user_removed_recipients
(
rotation
,
removed_user
)
...
@@ -175,5 +183,20 @@ module EE
...
@@ -175,5 +183,20 @@ module EE
.
deliver_later
.
deliver_later
end
end
end
end
def
send_account_validation_email
(
pipeline
)
return
unless
::
Feature
.
enabled?
(
:account_validation_email
)
return
unless
::
Gitlab
.
dev_env_or_com?
return
unless
pipeline
.
failed?
return
unless
pipeline
.
user_not_verified?
user
=
pipeline
.
user
return
if
user
.
has_required_credit_card_to_run_pipelines?
(
pipeline
.
project
)
return
unless
user
.
can?
(
:receive_notifications
)
return
unless
user
.
email_opted_in?
email
=
user
.
notification_email_or_default
mailer
.
account_validation_email
(
pipeline
,
email
).
deliver_later
end
end
end
end
end
ee/config/feature_flags/development/account_validation_email.yml
0 → 100644
View file @
8ac11f4e
---
name
:
account_validation_email
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/75183
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/346884
milestone
:
'
14.6'
type
:
development
group
:
group::activation
default_enabled
:
false
ee/spec/models/ee/user_spec.rb
View file @
8ac11f4e
...
@@ -1812,7 +1812,7 @@ RSpec.describe User do
...
@@ -1812,7 +1812,7 @@ RSpec.describe User do
with_them
do
with_them
do
before
do
before
do
allow
(
::
Gitlab
).
to
receive
(
:com?
).
and_return
(
saas
==
:saas
)
allow
(
::
Gitlab
).
to
receive
(
:
dev_env_or_
com?
).
and_return
(
saas
==
:saas
)
user
.
created_at
=
::
Users
::
CreditCardValidation
::
RELEASE_DAY
+
days_from_release
.
days
user
.
created_at
=
::
Users
::
CreditCardValidation
::
RELEASE_DAY
+
days_from_release
.
days
allow
(
user
).
to
receive
(
:credit_card_validated_at
).
and_return
(
Time
.
current
)
if
cc_present
allow
(
user
).
to
receive
(
:credit_card_validated_at
).
and_return
(
Time
.
current
)
if
cc_present
allow
(
project
.
namespace
).
to
receive
(
:free_plan?
).
and_return
(
plan
==
:free
)
allow
(
project
.
namespace
).
to
receive
(
:free_plan?
).
and_return
(
plan
==
:free
)
...
@@ -1860,7 +1860,7 @@ RSpec.describe User do
...
@@ -1860,7 +1860,7 @@ RSpec.describe User do
with_them
do
with_them
do
before
do
before
do
allow
(
::
Gitlab
).
to
receive
(
:com?
).
and_return
(
saas
==
:saas
)
allow
(
::
Gitlab
).
to
receive
(
:
dev_env_or_
com?
).
and_return
(
saas
==
:saas
)
user
.
created_at
=
::
Users
::
CreditCardValidation
::
RELEASE_DAY
+
days_from_release
.
days
user
.
created_at
=
::
Users
::
CreditCardValidation
::
RELEASE_DAY
+
days_from_release
.
days
allow
(
user
).
to
receive
(
:credit_card_validated_at
).
and_return
(
Time
.
current
)
if
cc_present
allow
(
user
).
to
receive
(
:credit_card_validated_at
).
and_return
(
Time
.
current
)
if
cc_present
allow
(
project
.
namespace
).
to
receive
(
:free_plan?
).
and_return
(
plan
==
:free
)
allow
(
project
.
namespace
).
to
receive
(
:free_plan?
).
and_return
(
plan
==
:free
)
...
...
ee/spec/services/ee/notification_service_spec.rb
View file @
8ac11f4e
...
@@ -986,4 +986,88 @@ RSpec.describe EE::NotificationService, :mailer do
...
@@ -986,4 +986,88 @@ RSpec.describe EE::NotificationService, :mailer do
end
end
end
end
end
end
describe
'#pipeline_finished'
do
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
,
email_opted_in:
true
)
}
let
(
:has_required_credit_card_to_run_pipelines
)
{
false
}
let
(
:failure_reason
)
{
'user_not_verified'
}
let
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
project:
project
,
ref:
'master'
,
status:
'failed'
,
failure_reason:
failure_reason
,
sha:
project
.
commit
.
id
,
user:
user
)
end
subject
(
:pipeline_finished
)
{
NotificationService
.
new
.
pipeline_finished
(
pipeline
)
}
before
do
allow
(
::
Gitlab
).
to
receive
(
:dev_env_or_com?
).
and_return
(
true
)
allow
(
user
).
to
receive
(
:has_required_credit_card_to_run_pipelines?
).
and_return
(
has_required_credit_card_to_run_pipelines
)
project
.
add_maintainer
(
user
)
end
shared_examples
'does not send account activation email'
do
it
'does not send account activation email'
do
expect
(
Notify
).
not_to
receive
(
:account_validation_email
)
pipeline_finished
end
end
context
'with a failed pipeline'
do
it
'sends account activation email'
do
expect
(
Notify
).
to
receive
(
:account_validation_email
).
with
(
pipeline
,
user
.
notification_email_or_default
).
once
.
and_call_original
pipeline_finished
end
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
account_validation_email:
false
)
end
include_examples
'does not send account activation email'
end
context
'when not in dev env or gitlab.com'
do
before
do
allow
(
::
Gitlab
).
to
receive
(
:dev_env_or_com?
).
and_return
(
false
)
end
include_examples
'does not send account activation email'
end
context
'when user is not opted in to marketing emails'
do
let
(
:user
)
{
create
(
:user
,
email_opted_in:
false
)
}
include_examples
'does not send account activation email'
end
context
"when failure reason is not user_not_verified"
do
let
(
:failure_reason
)
{
'unknown_failure'
}
include_examples
'does not send account activation email'
end
context
'when user account is validated'
do
let
(
:has_required_credit_card_to_run_pipelines
)
{
true
}
include_examples
'does not send account activation email'
end
context
'when user cannot receive notifications'
do
let
(
:user
)
{
User
.
ghost
}
include_examples
'does not send account activation email'
end
end
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