BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
6061c9fa
Commit
6061c9fa
authored
Oct 21, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send only to users have :read_build access, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6342#note_17193335
parent
1cdad622
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
55 deletions
+94
-55
build_policy.rb
app/policies/ci/build_policy.rb
+1
-1
pipeline_policy.rb
app/policies/ci/pipeline_policy.rb
+4
-0
notification_service.rb
app/services/notification_service.rb
+8
-3
pipeline_notification_worker_spec.rb
spec/workers/pipeline_notification_worker_spec.rb
+81
-51
No files found.
app/policies/ci/build_policy.rb
View file @
6061c9fa
...
...
@@ -5,7 +5,7 @@ module Ci
# If we can't read build we should also not have that
# ability when looking at this in context of commit_status
%w
(read create update admin)
.
each
do
|
rule
|
%w
[read create update admin]
.
each
do
|
rule
|
cannot!
:"
#{
rule
}
_commit_status"
unless
can?
:"
#{
rule
}
_build"
end
end
...
...
app/policies/ci/pipeline_policy.rb
0 → 100644
View file @
6061c9fa
module
Ci
class
PipelinePolicy
<
BuildPolicy
end
end
app/services/notification_service.rb
View file @
6061c9fa
...
...
@@ -489,9 +489,14 @@ class NotificationService
end
def
reject_users_without_access
(
recipients
,
target
)
return
recipients
unless
target
.
is_a?
(
Issuable
)
ability
=
:"read_
#{
target
.
to_ability_name
}
"
ability
=
case
target
when
Issuable
:"read_
#{
target
.
to_ability_name
}
"
when
Ci
::
Pipeline
:read_build
# We have build trace in pipeline emails
end
return
recipients
unless
ability
recipients
.
select
do
|
user
|
user
.
can?
(
ability
,
target
)
...
...
spec/workers/pipeline_notification_worker_spec.rb
View file @
6061c9fa
...
...
@@ -17,84 +17,114 @@ describe PipelineNotificationWorker do
describe
'#execute'
do
before
do
reset_delivered_emails!
pipeline
.
project
.
team
<<
[
watc
her
,
Gitlab
::
Access
::
DEVELOPER
]
pipeline
.
project
.
team
<<
[
pus
her
,
Gitlab
::
Access
::
DEVELOPER
]
end
shared_examples
'sending emails'
do
it
'sends emails'
do
perform_enqueued_jobs
do
subject
.
perform
(
pipeline
.
id
)
end
context
'when watcher has developer access'
do
before
do
pipeline
.
project
.
team
<<
[
watcher
,
Gitlab
::
Access
::
DEVELOPER
]
end
emails
=
ActionMailer
::
Base
.
deliveries
actual
=
emails
.
flat_map
(
&
:bcc
).
sort
expected_receivers
=
[
pusher
,
watcher
].
map
(
&
:email
).
uniq
.
sort
shared_examples
'sending emails'
do
it
'sends emails'
do
perform_enqueued_jobs
do
subject
.
perform
(
pipeline
.
id
)
end
expect
(
actual
).
to
eq
(
expected_receivers
)
expect
(
emails
.
size
).
to
eq
(
1
)
expect
(
emails
.
last
.
subject
).
to
include
(
email_subject
)
end
end
emails
=
ActionMailer
::
Base
.
deliveries
actual
=
emails
.
flat_map
(
&
:bcc
).
sort
expected_receivers
=
receivers
.
map
(
&
:email
).
uniq
.
sort
context
'with success pipeline'
do
let
(
:status
)
{
'success'
}
let
(
:email_subject
)
{
"Pipeline #
#{
pipeline
.
id
}
has succeeded"
}
expect
(
actual
).
to
eq
(
expected_receivers
)
expect
(
emails
.
size
).
to
eq
(
1
)
expect
(
emails
.
last
.
subject
).
to
include
(
email_subject
)
end
end
it_behaves_like
'sending emails'
context
'with success pipeline'
do
let
(
:status
)
{
'success'
}
let
(
:email_subject
)
{
"Pipeline #
#{
pipeline
.
id
}
has succeeded"
}
let
(
:receivers
)
{
[
pusher
,
watcher
]
}
context
'with pipeline from someone else'
do
let
(
:pusher
)
{
create
(
:user
)
}
it_behaves_like
'sending emails'
context
'with success pipeline notification on'
do
context
'with pipeline from someone else'
do
let
(
:pusher
)
{
create
(
:user
)
}
let
(
:watcher
)
{
user
}
before
do
watcher
.
global_notification_setting
.
update
(
level:
'custom'
,
success_pipeline:
true
)
context
'with success pipeline notification on'
do
before
do
watcher
.
global_notification_setting
.
update
(
level:
'custom'
,
success_pipeline:
true
)
end
it_behaves_like
'sending emails'
end
it_behaves_like
'sending emails'
end
context
'with success pipeline notification off'
do
let
(
:receivers
)
{
[
pusher
]
}
before
do
watcher
.
global_notification_setting
.
update
(
level:
'custom'
,
success_pipeline:
false
)
end
context
'with success pipeline notification off'
do
before
do
watcher
.
global_notification_setting
.
update
(
level:
'custom'
,
success_pipeline:
false
)
it_behaves_like
'sending emails'
end
end
context
'with failed pipeline'
do
let
(
:status
)
{
'failed'
}
let
(
:email_subject
)
{
"Pipeline #
#{
pipeline
.
id
}
has failed"
}
it_behaves_like
'sending emails'
context
'with pipeline from someone else'
do
let
(
:pusher
)
{
create
(
:user
)
}
let
(
:watcher
)
{
user
}
context
'with failed pipeline notification on'
do
before
do
watcher
.
global_notification_setting
.
update
(
level:
'custom'
,
failed_pipeline:
true
)
end
it_behaves_like
'sending emails'
end
context
'with failed pipeline notification off'
do
let
(
:receivers
)
{
[
pusher
]
}
before
do
watcher
.
global_notification_setting
.
update
(
level:
'custom'
,
failed_pipeline:
false
)
end
it_behaves_like
'sending emails'
end
end
end
end
end
context
'w
ith failed pipeline
'
do
context
'w
hen watcher has no read_build access
'
do
let
(
:status
)
{
'failed'
}
let
(
:email_subject
)
{
"Pipeline #
#{
pipeline
.
id
}
has failed"
}
let
(
:watcher
)
{
create
(
:user
)
}
it_behaves_like
'sending emails'
before
do
pipeline
.
project
.
team
<<
[
watcher
,
Gitlab
::
Access
::
GUEST
]
context
'with pipeline from someone else'
do
let
(
:pusher
)
{
create
(
:user
)
}
context
'with failed pipeline notification on'
do
let
(
:watcher
)
{
user
}
before
do
watcher
.
global_notification_setting
.
update
(
level:
'custom'
,
failed_pipeline:
true
)
end
watcher
.
global_notification_setting
.
update
(
level:
'custom'
,
failed_pipeline:
true
)
it_behaves_like
'sending emails'
perform_enqueued_jobs
do
subject
.
perform
(
pipeline
.
id
)
end
end
context
'with failed pipeline notification off'
do
before
do
watcher
.
global_notification_setting
.
update
(
level:
'custom'
,
failed_pipeline:
false
)
end
it_behaves_like
'sending emails'
end
it
'does not send emails'
do
should_only_email
(
pusher
,
kind: :bcc
)
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