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
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
if !api_user? && service_response.success?
......
......@@ -34,7 +34,7 @@ module Mutations
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
# `snippet.reset`, which is required in order to return the object in its non-dirty, unmodified, database state
......
# frozen_string_literal: true
module Snippets
class BaseService < ::BaseService
class BaseService < ::BaseProjectService
UPDATE_COMMIT_MSG = 'Update snippet'
INITIAL_COMMIT_MSG = 'Initial commit'
......@@ -9,7 +9,7 @@ module Snippets
attr_reader :uploaded_assets, :snippet_actions
def initialize(project, user = nil, params = {})
def initialize(project: nil, current_user: nil, params: {})
super
@uploaded_assets = Array(@params.delete(:files).presence)
......@@ -20,7 +20,7 @@ module Snippets
private
def visibility_allowed?(snippet, visibility_level)
def visibility_allowed?(visibility_level)
Gitlab::VisibilityLevel.allowed_for?(current_user, visibility_level)
end
......
......@@ -12,7 +12,7 @@ module Snippets
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)
end
......
......@@ -14,7 +14,7 @@ module Snippets
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)
end
......
......@@ -75,7 +75,7 @@ module API
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]
if service_response.success?
......@@ -116,7 +116,7 @@ module API
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]
if service_response.success?
......
......@@ -84,7 +84,7 @@ module API
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]
if service_response.success?
......@@ -126,7 +126,7 @@ module API
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]
......
......@@ -86,7 +86,7 @@ RSpec.describe 'Creating a Snippet' do
it 'passes disable_spam_action_service param to service' do
expect(::Snippets::CreateService)
.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
subject
......@@ -190,7 +190,7 @@ RSpec.describe 'Creating a Snippet' do
it do
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))
subject
......
......@@ -90,7 +90,7 @@ RSpec.describe 'Updating a Snippet' do
it 'passes disable_spam_action_service param to service' do
expect(::Snippets::UpdateService)
.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
subject
......
......@@ -20,7 +20,7 @@ RSpec.describe Snippets::CreateService do
let(:extra_opts) { {} }
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] }
......
......@@ -20,7 +20,7 @@ RSpec.describe Snippets::UpdateService do
let(:extra_opts) { {} }
let(:options) { base_opts.merge(extra_opts) }
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) }
......
......@@ -6,9 +6,9 @@ RSpec.shared_examples 'a mutation which can mutate a spammable' do
describe "#additional_spam_params" do
it 'passes additional spam params to the service' do
args = [
anything,
anything,
hash_including(
project: anything,
current_user: anything,
params: hash_including(
api: true,
request: instance_of(ActionDispatch::Request),
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