Skip to content
Snippets Groups Projects
Verified Commit 3383cf0a authored by Rémy Coutable's avatar Rémy Coutable :red_circle:
Browse files

[EE] Reduce remaining diff with CE in app/services


Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 410789ad
No related branches found
No related tags found
2 merge requests!9800WIP: Pre fetch forked repositories,!9461[EE] Reduce remaining diff with CE in app/services
Showing
with 85 additions and 58 deletions
......@@ -8,3 +8,5 @@ def mirrors_form_data_attributes
}
end
end
MirrorHelper.prepend(EE::MirrorHelper)
......@@ -2,18 +2,18 @@
module Applications
class CreateService
prepend ::EE::Applications::CreateService # rubocop: disable Cop/InjectEnterpriseEditionModule
attr_reader :current_user, :params
# rubocop: disable CodeReuse/ActiveRecord
def initialize(current_user, params)
@current_user = current_user
@params = params.except(:ip_address)
@params = params.except(:ip_address) # rubocop: disable CodeReuse/ActiveRecord
end
# rubocop: enable CodeReuse/ActiveRecord
# EE would override and use `request` arg
def execute(request)
Doorkeeper::Application.create(@params)
Doorkeeper::Application.create(params)
end
end
end
Applications::CreateService.prepend(EE::Applications::CreateService)
......@@ -3,8 +3,6 @@
# Base class for services that count a single resource such as the number of
# issues for a project.
class BaseCountService
prepend ::EE::BaseCountService # rubocop: disable Cop/InjectEnterpriseEditionModule
def relation_for_count
raise(
NotImplementedError,
......@@ -50,3 +48,5 @@ def update_cache_for_key(key, &block)
Rails.cache.write(key, block_given? ? yield : uncached_count, raw: raw?)
end
end
BaseCountService.prepend(EE::BaseCountService)
......@@ -3,8 +3,6 @@
module Boards
module Issues
class CreateService < Boards::BaseService
prepend ::EE::Boards::Issues::CreateService # rubocop: disable Cop/InjectEnterpriseEditionModule
attr_accessor :project
def initialize(parent, project, user, params = {})
......@@ -37,3 +35,5 @@ def create_issue(params)
end
end
end
Boards::Issues::CreateService.prepend(EE::Boards::Issues::CreateService)
......@@ -3,8 +3,6 @@
module Boards
module Lists
class ListService < Boards::BaseService
prepend ::EE::Boards::Lists::ListService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute(board)
board.lists.create(list_type: :backlog) unless board.lists.backlog.exists?
......@@ -13,3 +11,5 @@ def execute(board)
end
end
end
Boards::Lists::ListService.prepend(EE::Boards::Lists::ListService)
......@@ -2,10 +2,11 @@
module Emails
class BaseService
attr_reader :current_user
attr_reader :current_user, :params, :user
def initialize(current_user, params = {})
@current_user, @params = current_user, params.dup
@current_user = current_user
@params = params.dup
@user = params.delete(:user)
end
end
......
......@@ -2,15 +2,14 @@
module Emails
class CreateService < ::Emails::BaseService
prepend ::EE::Emails::CreateService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute(extra_params = {})
skip_confirmation = @params.delete(:skip_confirmation)
email = @user.emails.create(@params.merge(extra_params))
skip_confirmation = params.delete(:skip_confirmation)
email&.confirm if skip_confirmation && current_user.admin?
email
user.emails.create(params.merge(extra_params)).tap do |email|
email&.confirm if skip_confirmation && current_user.admin?
end
end
end
end
Emails::CreateService.prepend(EE::Emails::CreateService)
......@@ -2,8 +2,6 @@
module Emails
class DestroyService < ::Emails::BaseService
prepend ::EE::Emails::DestroyService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute(email)
email.destroy && update_secondary_emails!
end
......@@ -19,3 +17,5 @@ def update_secondary_emails!
end
end
end
Emails::DestroyService.prepend(EE::Emails::DestroyService)
......@@ -55,10 +55,6 @@ def execute
update_gitattributes if default_branch?
end
if Gitlab::CurrentSettings.elasticsearch_indexing? && default_branch?
ElasticCommitIndexerWorker.perform_async(@project.id, params[:oldrev], params[:newrev])
end
execute_related_hooks
perform_housekeeping
......@@ -143,10 +139,8 @@ def execute_related_hooks
UpdateMergeRequestsWorker
.perform_async(project.id, current_user.id, params[:oldrev], params[:newrev], params[:ref])
mirror_update = project.mirror? && project.repository.up_to_date_with_upstream?(branch_name)
EventCreateService.new.push(project, current_user, build_push_data)
Ci::CreatePipelineService.new(project, current_user, build_push_data).execute(:push, mirror_update: mirror_update)
Ci::CreatePipelineService.new(project, current_user, build_push_data).execute(:push, pipeline_options)
project.execute_hooks(build_push_data.dup, :push_hooks)
project.execute_services(build_push_data.dup, :push_hooks)
......@@ -237,4 +231,12 @@ def push_commits_count_for_ref
def last_pushed_commits
@last_pushed_commits ||= @push_commits.last(PROCESS_COMMIT_LIMIT)
end
private
def pipeline_options
{} # to be overriden in EE
end
end
GitPushService.prepend(EE::GitPushService)
......@@ -10,7 +10,7 @@ def execute
@push_data = build_push_data
EventCreateService.new.push(project, current_user, push_data)
Ci::CreatePipelineService.new(project, current_user, push_data).execute(:push, mirror_update: params[:mirror_update])
Ci::CreatePipelineService.new(project, current_user, push_data).execute(:push, pipeline_options)
SystemHooksService.new.execute_hooks(build_system_push_data, :tag_push_hooks)
project.execute_hooks(push_data.dup, :tag_push_hooks)
......@@ -59,4 +59,10 @@ def build_system_push_data
[],
'')
end
def pipeline_options
{} # to be overriden in EE
end
end
GitTagPushService.prepend(EE::GitTagPushService)
......@@ -2,8 +2,6 @@
module Groups
class DestroyService < Groups::BaseService
prepend ::EE::Groups::DestroyService # rubocop: disable Cop/InjectEnterpriseEditionModule
DestroyError = Class.new(StandardError)
def async_execute
......@@ -36,3 +34,5 @@ def execute
# rubocop: enable CodeReuse/ActiveRecord
end
end
Groups::DestroyService.prepend(EE::Groups::DestroyService)
......@@ -51,8 +51,6 @@ def new_parent
end
def group
return new_entity.group if new_entity.respond_to?(:group) && new_entity.group
if new_entity.project&.group && current_user.can?(:read_group, new_entity.project.group)
new_entity.project.group
end
......@@ -60,3 +58,11 @@ def group
end
end
end
# In the case we are eager-loading, `ee/app/services/ee/issuable/clone/base_service.rb`
# is loaded first, and explicitely requires this file to avoid a
# "TypeError: superclass must be a Class (Module given)" error.
# That also means that we cannot perform the prepending in this file otherwise
# we'd get a circular dependency error, thus we perform the prepending in
# `ee/app/services/ee/issuable/clone/base_service.rb` in that case.
Issuable::Clone::BaseService.prepend(EE::Issuable::Clone::BaseService) unless Rails.configuration.eager_load
# frozen_string_literal: true
class IssuableBaseService < BaseService
prepend ::EE::IssuableBaseService # rubocop: disable Cop/InjectEnterpriseEditionModule
private
attr_accessor :params, :skip_milestone_email
......@@ -390,3 +388,5 @@ def parent
project
end
end
IssuableBaseService.prepend(EE::IssuableBaseService)
......@@ -3,7 +3,6 @@
module Issues
class BuildService < Issues::BaseService
include ResolveDiscussions
prepend ::EE::Issues::BuildService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute
filter_resolve_discussion_params
......@@ -58,9 +57,11 @@ def item_for_discussion(discussion)
end
def issue_params
@issue_params ||= issue_params_with_info_from_discussions.merge(whitelisted_issue_params)
@issue_params ||= build_issue_params
end
private
def whitelisted_issue_params
if can?(current_user, :admin_issue, project)
params.slice(:title, :description, :milestone_id)
......@@ -68,5 +69,11 @@ def whitelisted_issue_params
params.slice(:title, :description)
end
end
def build_issue_params
issue_params_with_info_from_discussions.merge(whitelisted_issue_params)
end
end
end
Issues::BuildService.prepend(EE::Issues::BuildService)
......@@ -2,8 +2,6 @@
module Issues
class MoveService < Issuable::Clone::BaseService
prepend ::EE::Issues::MoveService # rubocop: disable Cop/InjectEnterpriseEditionModule
MoveError = Class.new(StandardError)
def execute(issue, target_project)
......@@ -66,3 +64,5 @@ def add_note_to
end
end
end
Issues::MoveService.prepend(EE::Issues::MoveService)
......@@ -2,8 +2,6 @@
module MergeRequests
class UpdateService < MergeRequests::BaseService
prepend ::EE::MergeRequests::UpdateService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute(merge_request)
# We don't allow change of source/target projects and source branch
# after merge request was created
......@@ -136,3 +134,5 @@ def create_branch_change_note(issuable, branch_type, old_branch, new_branch)
end
end
end
MergeRequests::UpdateService.prepend(EE::MergeRequests::UpdateService)
......@@ -5,12 +5,16 @@ class QuickActionsService < BaseService
UPDATE_SERVICES = {
'Issue' => Issues::UpdateService,
'MergeRequest' => MergeRequests::UpdateService,
'Commit' => Commits::TagService,
'Epic' => Epics::UpdateService
'Commit' => Commits::TagService
}.freeze
private_constant :UPDATE_SERVICES
def self.update_services
UPDATE_SERVICES
end
def self.noteable_update_service(note)
UPDATE_SERVICES[note.noteable_type]
update_services[note.noteable_type]
end
def self.supported?(note)
......@@ -36,3 +40,5 @@ def execute(command_params, note)
end
end
end
Notes::QuickActionsService.prepend(EE::Notes::QuickActionsService)
......@@ -242,8 +242,6 @@ def add_labels_subscribers(labels: nil)
end
class Default < Base
prepend ::EE::NotificationRecipientBuilders::Default # rubocop: disable Cop/InjectEnterpriseEditionModule
MENTION_TYPE_ACTIONS = [:new_issue, :new_merge_request].freeze
attr_reader :target
......@@ -251,6 +249,7 @@ class Default < Base
attr_reader :action
attr_reader :previous_assignee
attr_reader :skip_current_user
def initialize(target, current_user, action:, custom_action: nil, previous_assignee: nil, skip_current_user: true)
@target = target
@current_user = current_user
......@@ -260,15 +259,13 @@ def initialize(target, current_user, action:, custom_action: nil, previous_assig
@skip_current_user = skip_current_user
end
def add_watchers
add_project_watchers
end
def build!
add_participants(current_user)
if project
add_project_watchers
else # for group level targets
add_group_watchers
end
add_watchers
add_custom_notifications
# Re-assign is considered as a mention of the new assignee
......@@ -414,4 +411,5 @@ def acting_user
end
end
NotificationRecipientService::Builder::Default.prepend(EE::NotificationRecipientBuilders::Default) # rubocop: disable Cop/InjectEnterpriseEditionModule
NotificationRecipientService.prepend(EE::NotificationRecipientService)
......@@ -12,8 +12,6 @@ module Projects
#
# Projects::AfterRenameService.new(project).execute
class AfterRenameService
prepend ::EE::Projects::AfterRenameService # rubocop: disable Cop/InjectEnterpriseEditionModule
# @return [String] The Project being renamed.
attr_reader :project
......@@ -141,3 +139,5 @@ def rename_failed!
end
end
end
Projects::AfterRenameService.prepend(EE::Projects::AfterRenameService)
......@@ -2,8 +2,6 @@
module Projects
class AutocompleteService < BaseService
prepend EE::Projects::AutocompleteService # rubocop: disable Cop/InjectEnterpriseEditionModule
include LabelsAsHash
def issues
IssuesFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
......@@ -40,3 +38,5 @@ def labels_as_hash(target)
end
end
end
Projects::AutocompleteService.prepend(EE::Projects::AutocompleteService)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment