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
de68403b
Commit
de68403b
authored
Aug 24, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track edit action by snippet editor for usage data
parent
43e236b0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
0 deletions
+61
-0
app/graphql/mutations/snippets/create.rb
app/graphql/mutations/snippets/create.rb
+5
-0
app/graphql/mutations/snippets/update.rb
app/graphql/mutations/snippets/update.rb
+5
-0
changelogs/unreleased/232841-fj-track-snippet-edit-events.yml
...gelogs/unreleased/232841-fj-track-snippet-edit-events.yml
+5
-0
spec/requests/api/graphql/mutations/snippets/create_spec.rb
spec/requests/api/graphql/mutations/snippets/create_spec.rb
+4
-0
spec/requests/api/graphql/mutations/snippets/update_spec.rb
spec/requests/api/graphql/mutations/snippets/update_spec.rb
+3
-0
spec/support/shared_examples/requests/api/graphql/mutations/snippets_shared_examples.rb
...equests/api/graphql/mutations/snippets_shared_examples.rb
+39
-0
No files found.
app/graphql/mutations/snippets/create.rb
View file @
de68403b
...
...
@@ -51,6 +51,11 @@ module Mutations
snippet
=
service_response
.
payload
[
:snippet
]
# Only when the user is not an api user and the operation was successful
if
!
api_user?
&&
service_response
.
success?
::
Gitlab
::
UsageDataCounters
::
EditorUniqueCounter
.
track_snippet_editor_edit_action
(
author:
current_user
)
end
{
snippet:
service_response
.
success?
?
snippet
:
nil
,
errors:
errors_on_object
(
snippet
)
...
...
app/graphql/mutations/snippets/update.rb
View file @
de68403b
...
...
@@ -34,6 +34,11 @@ module Mutations
update_params
(
args
)).
execute
(
snippet
)
snippet
=
result
.
payload
[
:snippet
]
# Only when the user is not an api user and the operation was successful
if
!
api_user?
&&
result
.
success?
::
Gitlab
::
UsageDataCounters
::
EditorUniqueCounter
.
track_snippet_editor_edit_action
(
author:
current_user
)
end
{
snippet:
result
.
success?
?
snippet
:
snippet
.
reset
,
errors:
errors_on_object
(
snippet
)
...
...
changelogs/unreleased/232841-fj-track-snippet-edit-events.yml
0 → 100644
View file @
de68403b
---
title
:
Track snippet editor actions
merge_request
:
40277
author
:
type
:
changed
spec/requests/api/graphql/mutations/snippets/create_spec.rb
View file @
de68403b
...
...
@@ -99,6 +99,8 @@ RSpec.describe 'Creating a Snippet' do
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
'Snippet actions have invalid data'
]
it_behaves_like
'does not create snippet'
end
it_behaves_like
'snippet edit usage data counters'
end
context
'with PersonalSnippet'
do
...
...
@@ -129,6 +131,8 @@ RSpec.describe 'Creating a Snippet' do
it_behaves_like
'a mutation that returns top-level errors'
,
errors:
[
Gitlab
::
Graphql
::
Authorize
::
AuthorizeResource
::
RESOURCE_ACCESS_ERROR
]
end
it_behaves_like
'snippet edit usage data counters'
end
context
'when there are ActiveRecord validation errors'
do
...
...
spec/requests/api/graphql/mutations/snippets/update_spec.rb
View file @
de68403b
...
...
@@ -131,6 +131,7 @@ RSpec.describe 'Updating a Snippet' do
it_behaves_like
'graphql update actions'
it_behaves_like
'when the snippet is not found'
it_behaves_like
'snippet edit usage data counters'
end
describe
'ProjectSnippet'
do
...
...
@@ -173,6 +174,8 @@ RSpec.describe 'Updating a Snippet' do
expect
(
errors
.
first
[
'message'
]).
to
eq
(
Gitlab
::
Graphql
::
Authorize
::
AuthorizeResource
::
RESOURCE_ACCESS_ERROR
)
end
end
it_behaves_like
'snippet edit usage data counters'
end
it_behaves_like
'when the snippet is not found'
...
...
spec/support/shared_examples/requests/api/graphql/mutations/snippets_shared_examples.rb
View file @
de68403b
...
...
@@ -8,3 +8,42 @@ RSpec.shared_examples 'when the snippet is not found' do
it_behaves_like
'a mutation that returns top-level errors'
,
errors:
[
Gitlab
::
Graphql
::
Authorize
::
AuthorizeResource
::
RESOURCE_ACCESS_ERROR
]
end
RSpec
.
shared_examples
'snippet edit usage data counters'
do
context
'when user is sessionless'
do
it
'does not track usage data actions'
do
expect
(
::
Gitlab
::
UsageDataCounters
::
EditorUniqueCounter
).
not_to
receive
(
:track_snippet_editor_edit_action
)
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
end
end
context
'when user is not sessionless'
do
before
do
session_id
=
Rack
::
Session
::
SessionId
.
new
(
'6919a6f1bb119dd7396fadc38fd18d0d'
)
session_hash
=
{
'warden.user.user.key'
=>
[[
current_user
.
id
],
current_user
.
encrypted_password
[
0
,
29
]]
}
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
set
(
"session:gitlab:
#{
session_id
.
private_id
}
"
,
Marshal
.
dump
(
session_hash
))
end
cookies
[
Gitlab
::
Application
.
config
.
session_options
[
:key
]]
=
session_id
.
public_id
end
it
'tracks usage data actions'
,
:clean_gitlab_redis_shared_state
do
expect
(
::
Gitlab
::
UsageDataCounters
::
EditorUniqueCounter
).
to
receive
(
:track_snippet_editor_edit_action
)
post_graphql_mutation
(
mutation
)
end
context
'when mutation result raises an error'
do
it
'does not track usage data actions'
do
mutation_vars
[
:title
]
=
nil
expect
(
::
Gitlab
::
UsageDataCounters
::
EditorUniqueCounter
).
not_to
receive
(
:track_snippet_editor_edit_action
)
post_graphql_mutation
(
mutation
)
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