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
1399dd2e
Commit
1399dd2e
authored
Jul 14, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename snippet_files to snippet_actions in snippet services
parent
27b98a2a
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
66 additions
and
66 deletions
+66
-66
app/graphql/mutations/snippets/create.rb
app/graphql/mutations/snippets/create.rb
+2
-2
app/graphql/mutations/snippets/update.rb
app/graphql/mutations/snippets/update.rb
+2
-2
app/services/snippets/base_service.rb
app/services/snippets/base_service.rb
+8
-8
app/services/snippets/create_service.rb
app/services/snippets/create_service.rb
+3
-3
app/services/snippets/update_service.rb
app/services/snippets/update_service.rb
+4
-4
spec/requests/api/graphql/mutations/snippets/create_spec.rb
spec/requests/api/graphql/mutations/snippets/create_spec.rb
+1
-1
spec/services/snippets/create_service_spec.rb
spec/services/snippets/create_service_spec.rb
+12
-12
spec/services/snippets/update_service_spec.rb
spec/services/snippets/update_service_spec.rb
+34
-34
No files found.
app/graphql/mutations/snippets/create.rb
View file @
1399dd2e
...
...
@@ -85,9 +85,9 @@ module Mutations
def
create_params
(
args
)
args
.
tap
do
|
create_args
|
# We need to rename `files` into `snippet_
file
s` because
# We need to rename `files` into `snippet_
action
s` because
# it's the expected key param
create_args
[
:snippet_
file
s
]
=
create_args
.
delete
(
:files
)
&
.
map
(
&
:to_h
)
create_args
[
:snippet_
action
s
]
=
create_args
.
delete
(
:files
)
&
.
map
(
&
:to_h
)
# We need to rename `uploaded_files` into `files` because
# it's the expected key param
...
...
app/graphql/mutations/snippets/update.rb
View file @
1399dd2e
...
...
@@ -56,9 +56,9 @@ module Mutations
def
update_params
(
args
)
args
.
tap
do
|
update_args
|
# We need to rename `files` into `snippet_
file
s` because
# We need to rename `files` into `snippet_
action
s` because
# it's the expected key param
update_args
[
:snippet_
file
s
]
=
update_args
.
delete
(
:files
)
&
.
map
(
&
:to_h
)
update_args
[
:snippet_
action
s
]
=
update_args
.
delete
(
:files
)
&
.
map
(
&
:to_h
)
end
end
end
...
...
app/services/snippets/base_service.rb
View file @
1399dd2e
...
...
@@ -6,15 +6,15 @@ module Snippets
CreateRepositoryError
=
Class
.
new
(
StandardError
)
attr_reader
:uploaded_assets
,
:snippet_
file
s
attr_reader
:uploaded_assets
,
:snippet_
action
s
def
initialize
(
project
,
user
=
nil
,
params
=
{})
super
@uploaded_assets
=
Array
(
@params
.
delete
(
:files
).
presence
)
input_actions
=
Array
(
@params
.
delete
(
:snippet_
file
s
).
presence
)
@snippet_
file
s
=
SnippetInputActionCollection
.
new
(
input_actions
,
allowed_actions:
restricted_files_actions
)
input_actions
=
Array
(
@params
.
delete
(
:snippet_
action
s
).
presence
)
@snippet_
action
s
=
SnippetInputActionCollection
.
new
(
input_actions
,
allowed_actions:
restricted_files_actions
)
filter_spam_check_params
end
...
...
@@ -32,18 +32,18 @@ module Snippets
end
def
valid_params?
return
true
if
snippet_
file
s
.
empty?
return
true
if
snippet_
action
s
.
empty?
(
params
.
keys
&
[
:content
,
:file_name
]).
none?
&&
snippet_
file
s
.
valid?
(
params
.
keys
&
[
:content
,
:file_name
]).
none?
&&
snippet_
action
s
.
valid?
end
def
invalid_params_error
(
snippet
)
if
snippet_
file
s
.
valid?
if
snippet_
action
s
.
valid?
[
:content
,
:file_name
].
each
do
|
key
|
snippet
.
errors
.
add
(
key
,
'and snippet files cannot be used together'
)
if
params
.
key?
(
key
)
end
else
snippet
.
errors
.
add
(
:snippet_
file
s
,
'have invalid data'
)
snippet
.
errors
.
add
(
:snippet_
action
s
,
'have invalid data'
)
end
snippet_error_response
(
snippet
,
403
)
...
...
@@ -75,7 +75,7 @@ module Snippets
end
def
files_to_commit
(
snippet
)
snippet_
file
s
.
to_commit_actions
.
presence
||
build_actions_from_params
(
snippet
)
snippet_
action
s
.
to_commit_actions
.
presence
||
build_actions_from_params
(
snippet
)
end
def
build_actions_from_params
(
snippet
)
...
...
app/services/snippets/create_service.rb
View file @
1399dd2e
...
...
@@ -37,13 +37,13 @@ module Snippets
end
end
# If the snippet_
file
s param is present
# If the snippet_
action
s param is present
# we need to fill content and file_name from
# the model
def
create_params
return
params
if
snippet_
file
s
.
empty?
return
params
if
snippet_
action
s
.
empty?
params
.
merge
(
content:
snippet_
files
[
0
].
content
,
file_name:
snippet_file
s
[
0
].
file_path
)
params
.
merge
(
content:
snippet_
actions
[
0
].
content
,
file_name:
snippet_action
s
[
0
].
file_path
)
end
def
save_and_commit
...
...
app/services/snippets/update_service.rb
View file @
1399dd2e
...
...
@@ -37,9 +37,9 @@ module Snippets
# is implemented.
# Once we can perform different operations through this service
# we won't need to keep track of the `content` and `file_name` fields
if
snippet_
file
s
.
any?
params
[
:content
]
=
snippet_
files
[
0
].
content
if
snippet_file
s
[
0
].
content
params
[
:file_name
]
=
snippet_
file
s
[
0
].
file_path
if
snippet_
action
s
.
any?
params
[
:content
]
=
snippet_
actions
[
0
].
content
if
snippet_action
s
[
0
].
content
params
[
:file_name
]
=
snippet_
action
s
[
0
].
file_path
end
snippet
.
assign_attributes
(
params
)
...
...
@@ -109,7 +109,7 @@ module Snippets
end
def
committable_attributes?
(
params
.
stringify_keys
.
keys
&
COMMITTABLE_ATTRIBUTES
).
present?
||
snippet_
file
s
.
any?
(
params
.
stringify_keys
.
keys
&
COMMITTABLE_ATTRIBUTES
).
present?
||
snippet_
action
s
.
any?
end
def
build_actions_from_params
(
snippet
)
...
...
spec/requests/api/graphql/mutations/snippets/create_spec.rb
View file @
1399dd2e
...
...
@@ -174,7 +174,7 @@ RSpec.describe 'Creating a Snippet' do
context
'when action is invalid'
do
let
(
:file_1
)
{
{
filePath:
'example_file1'
}}
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
'Snippet
file
s have invalid data'
]
it_behaves_like
'a mutation that returns errors in the response'
,
errors:
[
'Snippet
action
s have invalid data'
]
it_behaves_like
'does not create snippet'
end
end
...
...
spec/services/snippets/create_service_spec.rb
View file @
1399dd2e
...
...
@@ -228,15 +228,15 @@ RSpec.describe Snippets::CreateService do
end
end
shared_examples
'when snippet_
file
s param is present'
do
shared_examples
'when snippet_
action
s param is present'
do
let
(
:file_path
)
{
'snippet_file_path.rb'
}
let
(
:content
)
{
'snippet_content'
}
let
(
:snippet_
file
s
)
{
[{
action:
'create'
,
file_path:
file_path
,
content:
content
}]
}
let
(
:snippet_
action
s
)
{
[{
action:
'create'
,
file_path:
file_path
,
content:
content
}]
}
let
(
:base_opts
)
do
{
title:
'Test snippet'
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
,
snippet_
files:
snippet_file
s
snippet_
actions:
snippet_action
s
}
end
...
...
@@ -266,28 +266,28 @@ RSpec.describe Snippets::CreateService do
end
end
context
'when snippet_
file
s param is invalid'
do
let
(
:snippet_
file
s
)
{
[{
action:
'invalid_action'
,
file_path:
'snippet_file_path.rb'
,
content:
'snippet_content'
}]
}
context
'when snippet_
action
s param is invalid'
do
let
(
:snippet_
action
s
)
{
[{
action:
'invalid_action'
,
file_path:
'snippet_file_path.rb'
,
content:
'snippet_content'
}]
}
it
'a validation error is raised'
do
expect
(
subject
).
to
be_error
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
files
)).
to
eq
[
'Snippet file
s have invalid data'
]
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
actions
)).
to
eq
[
'Snippet action
s have invalid data'
]
expect
(
snippet
.
repository
.
exists?
).
to
be_falsey
end
end
context
'when snippet_
file
s contain an action different from "create"'
do
let
(
:snippet_
file
s
)
{
[{
action:
'delete'
,
file_path:
'snippet_file_path.rb'
}]
}
context
'when snippet_
action
s contain an action different from "create"'
do
let
(
:snippet_
action
s
)
{
[{
action:
'delete'
,
file_path:
'snippet_file_path.rb'
}]
}
it
'a validation error is raised'
do
expect
(
subject
).
to
be_error
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
files
)).
to
eq
[
'Snippet file
s have invalid data'
]
expect
(
snippet
.
errors
.
full_messages_for
(
:snippet_
actions
)).
to
eq
[
'Snippet action
s have invalid data'
]
expect
(
snippet
.
repository
.
exists?
).
to
be_falsey
end
end
context
'when "create" operation does not have file_path or is empty'
do
let
(
:snippet_
file
s
)
{
[{
action:
'create'
,
content:
content
},
{
action:
'create'
,
content:
content
,
file_path:
''
}]
}
let
(
:snippet_
action
s
)
{
[{
action:
'create'
,
content:
content
},
{
action:
'create'
,
content:
content
,
file_path:
''
}]
}
it
'generates the file path for the files'
do
expect
(
subject
).
to
be_success
...
...
@@ -311,7 +311,7 @@ RSpec.describe Snippets::CreateService do
it_behaves_like
'an error service response when save fails'
it_behaves_like
'creates repository and files'
it_behaves_like
'after_save callback to store_mentions'
,
ProjectSnippet
it_behaves_like
'when snippet_
file
s param is present'
it_behaves_like
'when snippet_
action
s param is present'
context
'when uploaded files are passed to the service'
do
let
(
:extra_opts
)
{
{
files:
[
'foo'
]
}
}
...
...
@@ -338,7 +338,7 @@ RSpec.describe Snippets::CreateService do
it_behaves_like
'an error service response when save fails'
it_behaves_like
'creates repository and files'
it_behaves_like
'after_save callback to store_mentions'
,
PersonalSnippet
it_behaves_like
'when snippet_
file
s param is present'
it_behaves_like
'when snippet_
action
s param is present'
context
'when the snippet description contains files'
do
include
FileMoverHelpers
...
...
spec/services/snippets/update_service_spec.rb
View file @
1399dd2e
This diff is collapsed.
Click to expand it.
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