Commit 7cb6f860 authored by Markus Koller's avatar Markus Koller

Merge branch 'caw-snippets-use-base-container-service' into 'master'

Migrate snippet service subclasses to BaseProjectServices [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!62532
parents fe964d08 afd009e3
...@@ -49,7 +49,7 @@ module Mutations ...@@ -49,7 +49,7 @@ module Mutations
process_args_for_params!(args) process_args_for_params!(args)
service_response = ::Snippets::CreateService.new(project, current_user, args).execute service_response = ::Snippets::CreateService.new(project: project, current_user: current_user, params: args).execute
# Only when the user is not an api user and the operation was successful # Only when the user is not an api user and the operation was successful
if !api_user? && service_response.success? if !api_user? && service_response.success?
......
...@@ -34,7 +34,7 @@ module Mutations ...@@ -34,7 +34,7 @@ module Mutations
process_args_for_params!(args) process_args_for_params!(args)
service_response = ::Snippets::UpdateService.new(snippet.project, current_user, args).execute(snippet) service_response = ::Snippets::UpdateService.new(project: snippet.project, current_user: current_user, params: args).execute(snippet)
# TODO: DRY this up - From here down, this is all duplicated with Mutations::Snippets::Create#resolve, except for # TODO: DRY this up - From here down, this is all duplicated with Mutations::Snippets::Create#resolve, except for
# `snippet.reset`, which is required in order to return the object in its non-dirty, unmodified, database state # `snippet.reset`, which is required in order to return the object in its non-dirty, unmodified, database state
......
# frozen_string_literal: true # frozen_string_literal: true
module Snippets module Snippets
class BaseService < ::BaseService class BaseService < ::BaseProjectService
UPDATE_COMMIT_MSG = 'Update snippet' UPDATE_COMMIT_MSG = 'Update snippet'
INITIAL_COMMIT_MSG = 'Initial commit' INITIAL_COMMIT_MSG = 'Initial commit'
...@@ -9,7 +9,7 @@ module Snippets ...@@ -9,7 +9,7 @@ module Snippets
attr_reader :uploaded_assets, :snippet_actions attr_reader :uploaded_assets, :snippet_actions
def initialize(project, user = nil, params = {}) def initialize(project: nil, current_user: nil, params: {})
super super
@uploaded_assets = Array(@params.delete(:files).presence) @uploaded_assets = Array(@params.delete(:files).presence)
...@@ -20,7 +20,7 @@ module Snippets ...@@ -20,7 +20,7 @@ module Snippets
private private
def visibility_allowed?(snippet, visibility_level) def visibility_allowed?(visibility_level)
Gitlab::VisibilityLevel.allowed_for?(current_user, visibility_level) Gitlab::VisibilityLevel.allowed_for?(current_user, visibility_level)
end end
......
...@@ -12,7 +12,7 @@ module Snippets ...@@ -12,7 +12,7 @@ module Snippets
return invalid_params_error(@snippet) unless valid_params? return invalid_params_error(@snippet) unless valid_params?
unless visibility_allowed?(snippet, snippet.visibility_level) unless visibility_allowed?(snippet.visibility_level)
return forbidden_visibility_error(snippet) return forbidden_visibility_error(snippet)
end end
......
...@@ -14,7 +14,7 @@ module Snippets ...@@ -14,7 +14,7 @@ module Snippets
return invalid_params_error(snippet) unless valid_params? return invalid_params_error(snippet) unless valid_params?
if visibility_changed?(snippet) && !visibility_allowed?(snippet, visibility_level) if visibility_changed?(snippet) && !visibility_allowed?(visibility_level)
return forbidden_visibility_error(snippet) return forbidden_visibility_error(snippet)
end end
......
...@@ -75,7 +75,7 @@ module API ...@@ -75,7 +75,7 @@ module API
snippet_params = process_create_params(declared_params(include_missing: false)) snippet_params = process_create_params(declared_params(include_missing: false))
service_response = ::Snippets::CreateService.new(user_project, current_user, snippet_params).execute service_response = ::Snippets::CreateService.new(project: user_project, current_user: current_user, params: snippet_params).execute
snippet = service_response.payload[:snippet] snippet = service_response.payload[:snippet]
if service_response.success? if service_response.success?
...@@ -116,7 +116,7 @@ module API ...@@ -116,7 +116,7 @@ module API
snippet_params = process_update_params(declared_params(include_missing: false)) snippet_params = process_update_params(declared_params(include_missing: false))
service_response = ::Snippets::UpdateService.new(user_project, current_user, snippet_params).execute(snippet) service_response = ::Snippets::UpdateService.new(project: user_project, current_user: current_user, params: snippet_params).execute(snippet)
snippet = service_response.payload[:snippet] snippet = service_response.payload[:snippet]
if service_response.success? if service_response.success?
......
...@@ -84,7 +84,7 @@ module API ...@@ -84,7 +84,7 @@ module API
attrs = process_create_params(declared_params(include_missing: false)) attrs = process_create_params(declared_params(include_missing: false))
service_response = ::Snippets::CreateService.new(nil, current_user, attrs).execute service_response = ::Snippets::CreateService.new(project: nil, current_user: current_user, params: attrs).execute
snippet = service_response.payload[:snippet] snippet = service_response.payload[:snippet]
if service_response.success? if service_response.success?
...@@ -126,7 +126,7 @@ module API ...@@ -126,7 +126,7 @@ module API
attrs = process_update_params(declared_params(include_missing: false)) attrs = process_update_params(declared_params(include_missing: false))
service_response = ::Snippets::UpdateService.new(nil, current_user, attrs).execute(snippet) service_response = ::Snippets::UpdateService.new(project: nil, current_user: current_user, params: attrs).execute(snippet)
snippet = service_response.payload[:snippet] snippet = service_response.payload[:snippet]
......
...@@ -86,7 +86,7 @@ RSpec.describe 'Creating a Snippet' do ...@@ -86,7 +86,7 @@ RSpec.describe 'Creating a Snippet' do
it 'passes disable_spam_action_service param to service' do it 'passes disable_spam_action_service param to service' do
expect(::Snippets::CreateService) expect(::Snippets::CreateService)
.to receive(:new) .to receive(:new)
.with(anything, anything, hash_including(disable_spam_action_service: true)) .with(project: anything, current_user: anything, params: hash_including(disable_spam_action_service: true))
.and_call_original .and_call_original
subject subject
...@@ -190,7 +190,7 @@ RSpec.describe 'Creating a Snippet' do ...@@ -190,7 +190,7 @@ RSpec.describe 'Creating a Snippet' do
it do it do
expect(::Snippets::CreateService).to receive(:new) expect(::Snippets::CreateService).to receive(:new)
.with(nil, user, hash_including(files: expected_value)) .with(project: nil, current_user: user, params: hash_including(files: expected_value))
.and_return(double(execute: creation_response)) .and_return(double(execute: creation_response))
subject subject
......
...@@ -90,7 +90,7 @@ RSpec.describe 'Updating a Snippet' do ...@@ -90,7 +90,7 @@ RSpec.describe 'Updating a Snippet' do
it 'passes disable_spam_action_service param to service' do it 'passes disable_spam_action_service param to service' do
expect(::Snippets::UpdateService) expect(::Snippets::UpdateService)
.to receive(:new) .to receive(:new)
.with(anything, anything, hash_including(disable_spam_action_service: true)) .with(project: anything, current_user: anything, params: hash_including(disable_spam_action_service: true))
.and_call_original .and_call_original
subject subject
......
...@@ -20,7 +20,7 @@ RSpec.describe Snippets::CreateService do ...@@ -20,7 +20,7 @@ RSpec.describe Snippets::CreateService do
let(:extra_opts) { {} } let(:extra_opts) { {} }
let(:creator) { admin } let(:creator) { admin }
subject { described_class.new(project, creator, opts).execute } subject { described_class.new(project: project, current_user: creator, params: opts).execute }
let(:snippet) { subject.payload[:snippet] } let(:snippet) { subject.payload[:snippet] }
......
...@@ -20,7 +20,7 @@ RSpec.describe Snippets::UpdateService do ...@@ -20,7 +20,7 @@ RSpec.describe Snippets::UpdateService do
let(:extra_opts) { {} } let(:extra_opts) { {} }
let(:options) { base_opts.merge(extra_opts) } let(:options) { base_opts.merge(extra_opts) }
let(:updater) { user } let(:updater) { user }
let(:service) { Snippets::UpdateService.new(project, updater, options) } let(:service) { Snippets::UpdateService.new(project: project, current_user: updater, params: options) }
subject { service.execute(snippet) } subject { service.execute(snippet) }
......
...@@ -6,9 +6,9 @@ RSpec.shared_examples 'a mutation which can mutate a spammable' do ...@@ -6,9 +6,9 @@ RSpec.shared_examples 'a mutation which can mutate a spammable' do
describe "#additional_spam_params" do describe "#additional_spam_params" do
it 'passes additional spam params to the service' do it 'passes additional spam params to the service' do
args = [ args = [
anything, project: anything,
anything, current_user: anything,
hash_including( params: hash_including(
api: true, api: true,
request: instance_of(ActionDispatch::Request), request: instance_of(ActionDispatch::Request),
captcha_response: captcha_response, captcha_response: captcha_response,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment