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
d7a4f0fc
Commit
d7a4f0fc
authored
Feb 09, 2021
by
Kerri Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track approval rule create, update, delete events
Adds triggers of CUD event tracking
parent
ae0971c5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
32 deletions
+85
-32
ee/app/services/approval_rules/create_service.rb
ee/app/services/approval_rules/create_service.rb
+3
-0
ee/app/services/approval_rules/merge_request_rule_destroy_service.rb
...ices/approval_rules/merge_request_rule_destroy_service.rb
+7
-0
ee/app/services/approval_rules/update_service.rb
ee/app/services/approval_rules/update_service.rb
+7
-0
ee/spec/services/approval_rules/create_service_spec.rb
ee/spec/services/approval_rules/create_service_spec.rb
+27
-16
ee/spec/services/approval_rules/merge_request_rule_destroy_service_spec.rb
...approval_rules/merge_request_rule_destroy_service_spec.rb
+14
-0
ee/spec/services/approval_rules/update_service_spec.rb
ee/spec/services/approval_rules/update_service_spec.rb
+27
-16
No files found.
ee/app/services/approval_rules/create_service.rb
View file @
d7a4f0fc
...
...
@@ -26,6 +26,9 @@ module ApprovalRules
def
success
track_onboarding_progress
merge_request_activity_counter
.
track_approval_rule_added_action
(
user:
current_user
)
super
end
...
...
ee/app/services/approval_rules/merge_request_rule_destroy_service.rb
View file @
d7a4f0fc
...
...
@@ -17,5 +17,12 @@ module ApprovalRules
error
(
rule
.
errors
.
messages
)
end
end
def
success
merge_request_activity_counter
.
track_approval_rule_deleted_action
(
user:
current_user
)
super
end
end
end
ee/app/services/approval_rules/update_service.rb
View file @
d7a4f0fc
...
...
@@ -22,5 +22,12 @@ module ApprovalRules
params
[
:groups
]
+=
GroupFinder
.
new
(
rule
,
current_user
).
hidden_groups
end
end
def
success
merge_request_activity_counter
.
track_approval_rule_edited_action
(
user:
current_user
)
super
end
end
end
ee/spec/services/approval_rules/create_service_spec.rb
View file @
d7a4f0fc
...
...
@@ -10,22 +10,33 @@ RSpec.describe ApprovalRules::CreateService do
let
(
:new_approvers
)
{
create_list
(
:user
,
2
)
}
let
(
:new_groups
)
{
create_list
(
:group
,
2
,
:private
)
}
it
'creates approval, excluding non-eligible users and groups'
do
result
=
described_class
.
new
(
target
,
user
,
{
name:
'security'
,
approvals_required:
1
,
user_ids:
new_approvers
.
map
(
&
:id
),
group_ids:
new_groups
.
map
(
&
:id
)
}).
execute
expect
(
result
[
:status
]).
to
eq
(
:success
)
rule
=
result
[
:rule
]
expect
(
rule
.
name
).
to
eq
(
'security'
)
expect
(
rule
.
approvals_required
).
to
eq
(
1
)
expect
(
rule
.
users
).
to
be_empty
expect
(
rule
.
groups
).
to
be_empty
context
'basic creation action'
do
let
(
:result
)
do
described_class
.
new
(
target
,
user
,
{
name:
'security'
,
approvals_required:
1
,
user_ids:
new_approvers
.
map
(
&
:id
),
group_ids:
new_groups
.
map
(
&
:id
)
}).
execute
end
it
'creates approval, excluding non-eligible users and groups'
do
expect
(
result
[
:status
]).
to
eq
(
:success
)
rule
=
result
[
:rule
]
expect
(
rule
.
name
).
to
eq
(
'security'
)
expect
(
rule
.
approvals_required
).
to
eq
(
1
)
expect
(
rule
.
users
).
to
be_empty
expect
(
rule
.
groups
).
to
be_empty
end
it
'tracks creation event via a usage counter'
do
expect
(
Gitlab
::
UsageDataCounters
::
MergeRequestActivityUniqueCounter
)
.
to
receive
(
:track_approval_rule_added_action
).
once
.
with
(
user:
user
)
result
end
end
context
'when some users and groups are eligible'
do
...
...
ee/spec/services/approval_rules/merge_request_rule_destroy_service_spec.rb
View file @
d7a4f0fc
...
...
@@ -32,6 +32,13 @@ RSpec.describe ApprovalRules::MergeRequestRuleDestroyService do
it
'returns successful status'
do
expect
(
result
[
:status
]).
to
eq
(
:success
)
end
it
'tracks delete event via a usage counter'
do
expect
(
Gitlab
::
UsageDataCounters
::
MergeRequestActivityUniqueCounter
)
.
to
receive
(
:track_approval_rule_deleted_action
).
once
.
with
(
user:
user
)
result
end
end
context
'when rule not successfully deleted'
do
...
...
@@ -42,6 +49,13 @@ RSpec.describe ApprovalRules::MergeRequestRuleDestroyService do
it
'returns error status'
do
expect
(
result
[
:status
]).
to
eq
(
:error
)
end
it
'does not track delete event via a usage counter'
do
expect
(
Gitlab
::
UsageDataCounters
::
MergeRequestActivityUniqueCounter
)
.
not_to
receive
(
:track_approval_rule_deleted_action
)
result
end
end
end
end
ee/spec/services/approval_rules/update_service_spec.rb
View file @
d7a4f0fc
...
...
@@ -11,22 +11,33 @@ RSpec.describe ApprovalRules::UpdateService do
let
(
:new_approvers
)
{
create_list
(
:user
,
2
)
}
let
(
:new_groups
)
{
create_list
(
:group
,
2
,
:private
)
}
it
'updates approval, excluding non-eligible users and groups'
do
result
=
described_class
.
new
(
approval_rule
,
user
,
{
name:
'security'
,
approvals_required:
1
,
user_ids:
new_approvers
.
map
(
&
:id
),
group_ids:
new_groups
.
map
(
&
:id
)
}).
execute
expect
(
result
[
:status
]).
to
eq
(
:success
)
rule
=
result
[
:rule
]
expect
(
rule
.
name
).
to
eq
(
'security'
)
expect
(
rule
.
approvals_required
).
to
eq
(
1
)
expect
(
rule
.
users
).
to
be_empty
expect
(
rule
.
groups
).
to
be_empty
context
'basic update action'
do
let
(
:result
)
do
described_class
.
new
(
approval_rule
,
user
,
{
name:
'security'
,
approvals_required:
1
,
user_ids:
new_approvers
.
map
(
&
:id
),
group_ids:
new_groups
.
map
(
&
:id
)
}).
execute
end
it
'updates approval, excluding non-eligible users and groups'
do
expect
(
result
[
:status
]).
to
eq
(
:success
)
rule
=
result
[
:rule
]
expect
(
rule
.
name
).
to
eq
(
'security'
)
expect
(
rule
.
approvals_required
).
to
eq
(
1
)
expect
(
rule
.
users
).
to
be_empty
expect
(
rule
.
groups
).
to
be_empty
end
it
'tracks update event via a usage counter'
do
expect
(
Gitlab
::
UsageDataCounters
::
MergeRequestActivityUniqueCounter
)
.
to
receive
(
:track_approval_rule_edited_action
).
once
.
with
(
user:
user
)
result
end
end
context
'when some users and groups are eligible'
do
...
...
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