Commit 75e90ff2 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'ee-reduce-diff-with-ee-in-app-services' into 'master'

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

See merge request gitlab-org/gitlab-ee!9461
parents 2caa18e8 614ef82b
......@@ -8,3 +8,5 @@ module MirrorHelper
}
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 @@ class BaseCountService
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 @@ module Boards
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 @@ module Boards
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 @@ module Emails
end
end
end
Emails::DestroyService.prepend(EE::Emails::DestroyService)
......@@ -55,10 +55,6 @@ class GitPushService < BaseService
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 @@ class GitPushService < BaseService
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 @@ class GitPushService < BaseService
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 @@ class GitTagPushService < BaseService
@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 @@ class GitTagPushService < BaseService
[],
'')
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 @@ module Groups
# rubocop: enable CodeReuse/ActiveRecord
end
end
Groups::DestroyService.prepend(EE::Groups::DestroyService)
......@@ -51,8 +51,6 @@ module Issuable
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,5 @@ module Issuable
end
end
end
Issuable::Clone::BaseService.prepend(EE::Issuable::Clone::BaseService)
# 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 @@ class IssuableBaseService < BaseService
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 @@ module Issues
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 @@ module Issues
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 @@ module Issues
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 @@ module MergeRequests
end
end
end
MergeRequests::UpdateService.prepend(EE::MergeRequests::UpdateService)
......@@ -5,12 +5,16 @@ module Notes
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 @@ module Notes
end
end
end
Notes::QuickActionsService.prepend(EE::Notes::QuickActionsService)
......@@ -242,8 +242,6 @@ module NotificationRecipientService
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 @@ module NotificationRecipientService
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 @@ module NotificationRecipientService
@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 @@ module NotificationRecipientService
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 @@ module Projects
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 @@ module Projects
end
end
end
Projects::AutocompleteService.prepend(EE::Projects::AutocompleteService)
......@@ -51,4 +51,4 @@ module Projects
end
end
::Projects::CleanupService.prepend(::EE::Projects::CleanupService)
Projects::CleanupService.prepend(EE::Projects::CleanupService)
......@@ -2,7 +2,6 @@
module Projects
class CreateFromTemplateService < BaseService
prepend ::EE::Projects::CreateFromTemplateService # rubocop: disable Cop/InjectEnterpriseEditionModule
include Gitlab::Utils::StrongMemoize
def initialize(user, params)
......@@ -27,3 +26,5 @@ module Projects
end
end
end
Projects::CreateFromTemplateService.prepend(EE::Projects::CreateFromTemplateService)
......@@ -2,8 +2,6 @@
module Projects
class CreateService < BaseService
prepend ::EE::Projects::CreateService # rubocop: disable Cop/InjectEnterpriseEditionModule
def initialize(user, params)
@current_user, @params = user, params.dup
@skip_wiki = @params.delete(:skip_wiki)
......@@ -198,3 +196,5 @@ module Projects
end
end
end
Projects::CreateService.prepend(EE::Projects::CreateService)
......@@ -3,7 +3,6 @@
module Projects
class DestroyService < BaseService
include Gitlab::ShellAdapter
prepend ::EE::Projects::DestroyService # rubocop: disable Cop/InjectEnterpriseEditionModule
DestroyError = Class.new(StandardError)
......@@ -219,3 +218,5 @@ module Projects
end
end
end
Projects::DestroyService.prepend(EE::Projects::DestroyService)
......@@ -5,7 +5,6 @@
# The latter will under the hood just import an archive supplied by GitLab.
module Projects
class GitlabProjectsImportService
prepend ::EE::Projects::GitlabProjectsImportService # rubocop: disable Cop/InjectEnterpriseEditionModule
include Gitlab::Utils::StrongMemoize
include Gitlab::TemplateHelper
......@@ -70,3 +69,5 @@ module Projects
end
end
end
Projects::GitlabProjectsImportService.prepend(EE::Projects::GitlabProjectsImportService)
......@@ -3,8 +3,6 @@
module Projects
module GroupLinks
class CreateService < BaseService
prepend ::EE::Projects::GroupLinks::CreateService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute(group)
return false unless group
......@@ -17,3 +15,5 @@ module Projects
end
end
end
Projects::GroupLinks::CreateService.prepend(EE::Projects::GroupLinks::CreateService)
......@@ -3,8 +3,6 @@
module Projects
module GroupLinks
class DestroyService < BaseService
prepend ::EE::Projects::GroupLinks::DestroyService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute(group_link)
return false unless group_link
......@@ -13,3 +11,5 @@ module Projects
end
end
end
Projects::GroupLinks::DestroyService.prepend(EE::Projects::GroupLinks::DestroyService)
......@@ -7,8 +7,6 @@ module Projects
class MigrateAttachmentsService < BaseService
attr_reader :logger, :old_disk_path, :new_disk_path
prepend ::EE::Projects::HashedStorage::MigrateAttachmentsService # rubocop: disable Cop/InjectEnterpriseEditionModule
def initialize(project, old_disk_path, logger: nil)
@project = project
@logger = logger || Rails.logger
......@@ -64,3 +62,5 @@ module Projects
end
end
end
Projects::HashedStorage::MigrateAttachmentsService.prepend(EE::Projects::HashedStorage::MigrateAttachmentsService)
......@@ -3,8 +3,6 @@
module Projects
module HashedStorage
class MigrateRepositoryService < BaseRepositoryService
prepend ::EE::Projects::HashedStorage::MigrateRepositoryService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute
try_to_set_repository_read_only!
......@@ -52,3 +50,5 @@ module Projects
end
end
end
Projects::HashedStorage::MigrateRepositoryService.prepend(EE::Projects::HashedStorage::MigrateRepositoryService)
......@@ -13,8 +13,6 @@ module Projects
include Gitlab::ShellAdapter
TransferError = Class.new(StandardError)
prepend ::EE::Projects::TransferService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute(new_namespace)
@new_namespace = new_namespace
......@@ -172,3 +170,5 @@ module Projects
end
end
end
Projects::TransferService.prepend(EE::Projects::TransferService)
......@@ -4,8 +4,6 @@ module Projects
class UpdateService < BaseService
include UpdateVisibilityLevel
prepend ::EE::Projects::UpdateService # rubocop: disable Cop/InjectEnterpriseEditionModule
ValidationError = Class.new(StandardError)
# rubocop: disable CodeReuse/ActiveRecord
......@@ -135,3 +133,5 @@ module Projects
end
end
end
Projects::UpdateService.prepend(EE::Projects::UpdateService)
......@@ -3,18 +3,17 @@
module ProtectedBranches
class ApiService < BaseService
def create
@push_params = AccessLevelParams.new(:push, params)
@merge_params = AccessLevelParams.new(:merge, params)
@unprotect_params = AccessLevelParams.new(:unprotect, params)
::ProtectedBranches::CreateService.new(@project, @current_user, protected_branch_params).execute
end
protected_branch_params = {
def protected_branch_params
{
name: params[:name],
push_access_levels_attributes: @push_params.access_levels,
merge_access_levels_attributes: @merge_params.access_levels,
unprotect_access_levels_attributes: @unprotect_params.access_levels
push_access_levels_attributes: AccessLevelParams.new(:push, params).access_levels,
merge_access_levels_attributes: AccessLevelParams.new(:merge, params).access_levels
}
::ProtectedBranches::CreateService.new(@project, @current_user, protected_branch_params).execute
end
end
end
ProtectedBranches::ApiService.prepend(EE::ProtectedBranches::ApiService)
......@@ -6,30 +6,31 @@
# lives in this service.
module ProtectedBranches
class LegacyApiUpdateService < BaseService
attr_reader :protected_branch, :developers_can_push, :developers_can_merge
def execute(protected_branch)
@protected_branch = protected_branch
@developers_can_push = params.delete(:developers_can_push)
@developers_can_merge = params.delete(:developers_can_merge)
@protected_branch = protected_branch
protected_branch.transaction do
delete_redundant_ee_access_levels
delete_redundant_access_levels
case @developers_can_push
case developers_can_push
when true
params[:push_access_levels_attributes] = [{ access_level: Gitlab::Access::DEVELOPER }]
when false
params[:push_access_levels_attributes] = [{ access_level: Gitlab::Access::MAINTAINER }]
end
case @developers_can_merge
case developers_can_merge
when true
params[:merge_access_levels_attributes] = [{ access_level: Gitlab::Access::DEVELOPER }]
when false
params[:merge_access_levels_attributes] = [{ access_level: Gitlab::Access::MAINTAINER }]
end
service = ProtectedBranches::UpdateService.new(@project, @current_user, @params)
service = ProtectedBranches::UpdateService.new(project, current_user, params)
service.execute(protected_branch)
end
end
......@@ -37,34 +38,15 @@ module ProtectedBranches
private
def delete_redundant_access_levels
unless @developers_can_merge.nil?
@protected_branch.merge_access_levels.destroy_all # rubocop: disable DestroyAll # rubocop: disable DestroyAll
end
unless @developers_can_push.nil?
@protected_branch.push_access_levels.destroy_all # rubocop: disable DestroyAll # rubocop: disable DestroyAll
unless developers_can_merge.nil?
protected_branch.merge_access_levels.destroy_all # rubocop: disable DestroyAll
end
end
# If a protected branch can have more than one access level (EE), only
# remove the relevant access levels. If we don't do this, we'll have a
# failed validation.
def delete_redundant_ee_access_levels
case @developers_can_merge
when true
@protected_branch.merge_access_levels.developer.destroy_all # rubocop: disable DestroyAll
when false
@protected_branch.merge_access_levels.developer.destroy_all # rubocop: disable DestroyAll
@protected_branch.merge_access_levels.maintainer.destroy_all # rubocop: disable DestroyAll
end
case @developers_can_push
when true
@protected_branch.push_access_levels.developer.destroy_all # rubocop: disable DestroyAll
when false
@protected_branch.push_access_levels.developer.destroy_all # rubocop: disable DestroyAll
@protected_branch.push_access_levels.maintainer.destroy_all # rubocop: disable DestroyAll
unless developers_can_push.nil?
protected_branch.push_access_levels.destroy_all # rubocop: disable DestroyAll
end
end
end
end
ProtectedBranches::LegacyApiUpdateService.prepend(EE::ProtectedBranches::LegacyApiUpdateService)
......@@ -4,6 +4,7 @@ module QuickActions
class InterpretService < BaseService
include Gitlab::Utils::StrongMemoize
include Gitlab::QuickActions::Dsl
attr_reader :issuable
SHRUG = '¯\\_(ツ)_/¯'.freeze
......
......@@ -17,15 +17,7 @@ module Search
@projects = super.inside_path(group.full_path)
end
# rubocop: disable CodeReuse/ActiveRecord
def elastic_projects
@elastic_projects ||= projects.pluck(:id)
end
# rubocop: enable CodeReuse/ActiveRecord
def elastic_global
false
end
end
end
Search::GroupService.prepend(EE::Search::GroupService)
......@@ -9,17 +9,10 @@ module Search
end
def execute
if Gitlab::CurrentSettings.elasticsearch_search?
Gitlab::Elastic::ProjectSearchResults.new(current_user,
params[:search],
project.id,
params[:repository_ref])
else
Gitlab::ProjectSearchResults.new(current_user,
project,
params[:search],
params[:repository_ref])
end
Gitlab::ProjectSearchResults.new(current_user,
project,
params[:search],
params[:repository_ref])
end
def scope
......@@ -27,3 +20,5 @@ module Search
end
end
end
Search::ProjectService.prepend(EE::Search::ProjectService)
......@@ -130,7 +130,6 @@ class SystemHooksService
{
group_name: model.group.name,
group_path: model.group.path,
group_plan: model.group.plan&.name,
group_id: model.group.id,
user_username: model.user.username,
user_name: model.user.name,
......
......@@ -2,8 +2,6 @@
module Users
class BuildService < BaseService
prepend ::EE::Users::BuildService # rubocop: disable Cop/InjectEnterpriseEditionModule
delegate :user_default_internal_regex_enabled?,
:user_default_internal_regex_instance,
to: :'Gitlab::CurrentSettings.current_application_settings'
......@@ -123,3 +121,5 @@ module Users
end
end
end
Users::BuildService.prepend(EE::Users::BuildService)
......@@ -2,8 +2,6 @@
module Users
class DestroyService
prepend ::EE::Users::DestroyService # rubocop: disable Cop/InjectEnterpriseEditionModule
DestroyError = Class.new(StandardError)
attr_accessor :current_user
......@@ -66,3 +64,5 @@ module Users
end
end
end
Users::DestroyService.prepend(EE::Users::DestroyService)
......@@ -3,6 +3,7 @@
module Users
class UpdateService < BaseService
include NewUserNotifier
def initialize(current_user, params = {})
@current_user = current_user
@user = params.delete(:user)
......
......@@ -54,11 +54,14 @@ module Gitlab
ee_path = config.root.join('ee', Pathname.new(path).relative_path_from(config.root))
memo << ee_path.to_s if ee_path.exist?
end
config.eager_load_paths.unshift(*ee_paths)
# Eager load should load CE first
config.eager_load_paths.push(*ee_paths)
config.helpers_paths.push "#{config.root}/ee/app/helpers"
# Other than Ruby modules we load EE first
config.paths['lib/tasks'].unshift "#{config.root}/ee/lib/tasks"
config.paths['app/views'].unshift "#{config.root}/ee/app/views"
config.helpers_paths.unshift "#{config.root}/ee/app/helpers"
## EE-specific paths config END
# Rake tasks ignore the eager loading settings, so we need to set the
......
# frozen_string_literal: true
module EE
module MirrorHelper
def render_mirror_failed_message(raw_message:)
mirror_last_update_at = @project.import_state.last_update_at
message = "The repository failed to update #{time_ago_with_tooltip(mirror_last_update_at)}.".html_safe
return message if raw_message
message.insert(0, "#{icon('warning triangle')} ")
if can?(current_user, :admin_project, @project)
link_to message, project_mirror_path(@project)
else
message
end
end
def branch_diverged_tooltip_message
message = [s_('Branches|The branch could not be updated automatically because it has diverged from its upstream counterpart.')]
if can?(current_user, :push_code, @project)
message << '<br>'
message << s_("Branches|To discard the local changes and overwrite the branch with the upstream version, delete it here and choose 'Update Now' above.")
end
message.join
end
def options_for_mirror_user
options_from_collection_for_select(default_mirror_users, :id, :name, @project.mirror_user_id || current_user.id)
end
def mirrored_repositories_count(project = @project)
count = project.mirror == true ? 1 : 0
count + @project.remote_mirrors.to_a.count { |mirror| mirror.enabled }
end
end
end
# frozen_string_literal: true
module MirrorHelper
def render_mirror_failed_message(raw_message:)
mirror_last_update_at = @project.import_state.last_update_at
message = "The repository failed to update #{time_ago_with_tooltip(mirror_last_update_at)}.".html_safe
return message if raw_message
message.insert(0, "#{icon('warning triangle')} ")
if can?(current_user, :admin_project, @project)
link_to message, project_mirror_path(@project)
else
message
end
end
def branch_diverged_tooltip_message
message = [s_('Branches|The branch could not be updated automatically because it has diverged from its upstream counterpart.')]
if can?(current_user, :push_code, @project)
message << '<br>'
message << s_("Branches|To discard the local changes and overwrite the branch with the upstream version, delete it here and choose 'Update Now' above.")
end
message.join
end
def options_for_mirror_user
options_from_collection_for_select(default_mirror_users, :id, :name, @project.mirror_user_id || current_user.id)
end
def mirrored_repositories_count(project = @project)
count = project.mirror == true ? 1 : 0
count + @project.remote_mirrors.to_a.count { |mirror| mirror.enabled }
end
def mirrors_form_data_attributes
{ project_mirror_ssh_endpoint: ssh_host_keys_project_mirror_path(@project, :json),
project_mirror_endpoint: project_mirror_path(@project) }
end
end
......@@ -2,8 +2,10 @@
module EE
module Applications
# rubocop:disable Gitlab/ModuleWithInstanceVariables
module CreateService
extend ::Gitlab::Utils::Override
override :execute
def execute(request)
super.tap do |application|
audit_event_service(request.remote_ip).for_user(application.name).security_event
......@@ -11,8 +13,8 @@ module EE
end
def audit_event_service(ip_address)
::AuditEventService.new(@current_user,
@current_user,
::AuditEventService.new(current_user,
current_user,
action: :custom,
custom_message: 'OAuth access granted',
ip_address: ip_address)
......
......@@ -8,9 +8,9 @@ module EE
# could be incorrect for 2 weeks.
override :cache_options
def cache_options
value = super
value[:expires_in] = 20.minutes if ::Gitlab::Geo.secondary?
value
super.tap do |options|
options[:expires_in] = 20.minutes if ::Gitlab::Geo.secondary?
end
end
end
end
......@@ -8,17 +8,18 @@ module EE
override :issue_params
def issue_params
assignee_ids = Array(list.user_id || board.assignee&.id)
milestone_id = list.milestone_id || board.milestone_id
super.tap do |options|
assignee_ids = Array(list.user_id || board.assignee&.id)
milestone_id = list.milestone_id || board.milestone_id
{
label_ids: [list.label_id, *board.label_ids],
weight: board.weight,
milestone_id: milestone_id,
# This can be removed when boards have multiple assignee support.
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/3786
assignee_ids: assignee_ids
}
options[:label_ids].concat(board.label_ids)
options.merge!(
weight: board.weight,
milestone_id: milestone_id,
# This can be removed when boards have multiple assignee support.
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/3786
assignee_ids: assignee_ids)
end
end
end
end
......
......@@ -4,36 +4,32 @@ module EE
module Boards
module Lists
module ListService
extend ::Gitlab::Utils::Override
# When adding a new licensed type, make sure to also add
# it on license.rb with the pattern "board_<list_type>_lists"
LICENSED_LIST_TYPES = [:assignee, :milestone].freeze
extend ::Gitlab::Utils::Override
LICENSED_LIST_TYPES = %i[assignee milestone].freeze
override :execute
# rubocop: disable CodeReuse/ActiveRecord
def execute(board)
not_available_lists =
list_type_features_availability(board).select { |_, available| !available }
not_available_lists = list_type_features_availability(board)
.select { |_, available| !available }
if not_available_lists.any?
super.where.not(list_type: not_available_lists.keys)
super.where.not(list_type: not_available_lists.keys) # rubocop: disable CodeReuse/ActiveRecord
else
super
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
def list_type_features_availability(board)
parent = board.parent
{}.tap do |hash|
LICENSED_LIST_TYPES.each do |list_type|
list_type_key = ::List.list_types[list_type]
hash[list_type_key] = parent&.feature_available?(:"board_#{list_type}_lists")
end
LICENSED_LIST_TYPES.each_with_object({}) do |list_type, hash|
list_type_key = ::List.list_types[list_type]
hash[list_type_key] = parent&.feature_available?(:"board_#{list_type}_lists")
end
end
end
......
......@@ -3,9 +3,11 @@
module EE
module Emails
module CreateService
extend ::Gitlab::Utils::Override
include ::EE::Emails::BaseService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute(*args, &blk)
override :execute
def execute(extra_params = {})
super.tap do |email|
log_audit_event(action: :create) if email.persisted?
end
......
......@@ -3,9 +3,11 @@
module EE
module Emails
module DestroyService
extend ::Gitlab::Utils::Override
include ::EE::Emails::BaseService # rubocop: disable Cop/InjectEnterpriseEditionModule
def execute(*args, &blk)
override :execute
def execute(email)
super.tap do
log_audit_event(action: :destroy)
end
......
# frozen_string_literal: true
module EE
module GitPushService
extend ::Gitlab::Utils::Override
protected
override :execute_related_hooks
def execute_related_hooks
if ::Gitlab::CurrentSettings.elasticsearch_indexing? && default_branch?
::ElasticCommitIndexerWorker.perform_async(project.id, params[:oldrev], params[:newrev])
end
super
end
private
override :pipeline_options
def pipeline_options
{ mirror_update: project.mirror? && project.repository.up_to_date_with_upstream?(branch_name) }
end
end
end
# frozen_string_literal: true
module EE
module GitTagPushService
extend ::Gitlab::Utils::Override
private
override :pipeline_options
def pipeline_options
{ mirror_update: params[:mirror_update] }
end
end
end
# frozen_string_literal: true
module EE
module Issuable
module Clone
module BaseService
extend ::Gitlab::Utils::Override
private
override :group
def group
if new_entity.respond_to?(:group) && new_entity.group
new_entity.group
else
super
end
end
end
end
end
end
......@@ -2,10 +2,12 @@
module EE
module IssuableBaseService
extend ::Gitlab::Utils::Override
include ::Gitlab::Utils::StrongMemoize
private
override :filter_params
def filter_params(issuable)
# This security check is repeated here to avoid multiple backports,
# this should be refactored to be reused from the base class.
......
......@@ -3,6 +3,8 @@
module EE
module Issues
module BuildService
extend ::Gitlab::Utils::Override
def issue_params_from_template
return {} unless project.feature_available?(:issuable_default_templates)
......@@ -13,8 +15,9 @@ module EE
# They take precedence over eachother like this
# passed params > discussion params > template params
# The template params are filled in here, and might be overwritten by super
def issue_params
@issue_params ||= issue_params_from_template.merge(super)
override :build_issue_params
def build_issue_params
issue_params_from_template.merge(super)
end
end
end
......
......@@ -3,6 +3,9 @@
module EE
module Issues
module MoveService
extend ::Gitlab::Utils::Override
override :update_old_entity
def update_old_entity
rewrite_epic_issue
super
......
......@@ -35,6 +35,8 @@ module EE
merge_request
end
private
override :create_branch_change_note
def create_branch_change_note(merge_request, branch_type, old_branch, new_branch)
super
......@@ -42,8 +44,6 @@ module EE
reset_approvals(merge_request)
end
private
def reset_approvals(merge_request)
target_project = merge_request.target_project
......
# frozen_string_literal: true
module EE
module Notes
module QuickActionsService
extend ActiveSupport::Concern
include ::Gitlab::Utils::StrongMemoize
prepended do
EE_UPDATE_SERVICES = const_get(:UPDATE_SERVICES).merge(
'Epic' => Epics::UpdateService
).freeze
EE::Notes::QuickActionsService.private_constant :EE_UPDATE_SERVICES
end
class_methods do
extend ::Gitlab::Utils::Override
override :update_services
def update_services
EE_UPDATE_SERVICES
end
end
end
end
end
......@@ -4,6 +4,7 @@ module EE
module NotificationRecipientBuilders
module Default
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
class_methods do
extend ::Gitlab::Utils::Override
......@@ -13,6 +14,15 @@ module EE
super.append(:new_epic)
end
end
override :add_watchers
def add_watchers
if project
super
else # for group level targets
add_group_watchers
end
end
end
end
end
......@@ -7,16 +7,14 @@ module EE
override :execute
def execute
succeeded = super
# It's possible that some error occurred, but at the end of the day
# if the project is destroyed from the database, we should log events
# and clean up where we can.
if project&.destroyed?
mirror_cleanup(project)
super.tap do
# It's possible that some error occurred, but at the end of the day
# if the project is destroyed from the database, we should log events
# and clean up where we can.
if project&.destroyed?
mirror_cleanup(project)
end
end
succeeded
end
override :log_destroy_event
......
# frozen_string_literal: true
module EE
module ProtectedBranches
module ApiService
extend ::Gitlab::Utils::Override
override :protected_branch_params
def protected_branch_params
super.tap do |hash|
hash[:unprotect_access_levels_attributes] = ::ProtectedBranches::AccessLevelParams.new(:unprotect, params).access_levels
end
end
end
end
end
# frozen_string_literal: true
module EE
module ProtectedBranches
module LegacyApiUpdateService
extend ::Gitlab::Utils::Override
private
# If a protected branch can have more than one access level (EE), only
# remove the relevant access levels. If we don't do this, we'll have a
# failed validation.
override :delete_redundant_access_levels
def delete_redundant_access_levels
case developers_can_merge
when true
protected_branch.merge_access_levels.developer.destroy_all # rubocop: disable DestroyAll
when false
protected_branch.merge_access_levels.developer.destroy_all # rubocop: disable DestroyAll
protected_branch.merge_access_levels.maintainer.destroy_all # rubocop: disable DestroyAll
end
case developers_can_push
when true
protected_branch.push_access_levels.developer.destroy_all # rubocop: disable DestroyAll
when false
protected_branch.push_access_levels.developer.destroy_all # rubocop: disable DestroyAll
protected_branch.push_access_levels.maintainer.destroy_all # rubocop: disable DestroyAll
end
end
end
end
end
# frozen_string_literal: true
module EE
module Search
module GroupService
def elastic_projects
@elastic_projects ||= projects.pluck(:id) # rubocop:disable CodeReuse/ActiveRecord
end
def elastic_global
false
end
end
end
end
# frozen_string_literal: true
module EE
module Search
module ProjectService
extend ::Gitlab::Utils::Override
override :execute
def execute
if ::Gitlab::CurrentSettings.elasticsearch_search?
::Gitlab::Elastic::ProjectSearchResults.new(current_user,
params[:search],
project.id,
params[:repository_ref])
else
super
end
end
end
end
end
......@@ -2,14 +2,22 @@
module EE
module SystemHooksService
# override
extend ::Gitlab::Utils::Override
private
override :group_member_data
def group_member_data(model)
super.tap do |data|
data[:group_plan] = model.group.plan&.name
end
end
override :user_data
def user_data(model)
data = super
data.merge!(email_opted_in_data(model)) if ::Gitlab.com?
data
super.tap do |data|
data.merge!(email_opted_in_data(model)) if ::Gitlab.com?
end
end
def email_opted_in_data(model)
......
......@@ -16,6 +16,7 @@ module EE
private
override :signup_params
def signup_params
super + email_opted_in_params
end
......
......@@ -12,9 +12,8 @@ module EE
end
end
# rubocop: disable CodeReuse/ActiveRecord
def mirror_cleanup(user)
user_mirrors = ::Project.where(mirror_user: user)
user_mirrors = ::Project.where(mirror_user: user) # rubocop: disable CodeReuse/ActiveRecord
user_mirrors.find_each do |mirror|
new_mirror_user = first_mirror_owner(user, mirror)
......@@ -23,7 +22,6 @@ module EE
::NotificationService.new.project_mirror_user_changed(new_mirror_user, user.name, mirror)
end
end
# rubocop: enable CodeReuse/ActiveRecord
private
......
# frozen_string_literal: true
module Epics
class IssuePromoteService < Issuable::Clone::BaseService
class IssuePromoteService < ::Issuable::Clone::BaseService
PromoteError = Class.new(StandardError)
def execute(issue)
......
......@@ -18,5 +18,3 @@ module EE
end
end
end
ExpirePipelineCacheWorker.prepend(EE::ExpirePipelineCacheWorker)
......@@ -15,11 +15,13 @@ module EE
downstream_bridge_project_not_found: 'downstream project could not be found',
insufficient_bridge_permissions: 'no permissions to trigger downstream pipeline'
).freeze
EE::Gitlab::Ci::Status::Build::Failed.private_constant :EE_REASONS
end
class_methods do
extend ::Gitlab::Utils::Override
override :reasons
def reasons
EE_REASONS
end
......
......@@ -10,6 +10,7 @@ namespace :dev do
desc "GitLab | Eager load application"
task load: :environment do
Rails.configuration.eager_load = true
Rails.application.eager_load!
end
end
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