Commit 5e3b5b60 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ee-resolve-lib-gitlab-differences' into 'master'

EE: Move EE specific code out of lib/gitlab

Closes #5964, #6023, #6661, and #6662

See merge request gitlab-org/gitlab-ee!9831
parents 7c3330ef b1c86666
...@@ -33,8 +33,8 @@ module EE ...@@ -33,8 +33,8 @@ module EE
} }
when :project_creation_level when :project_creation_level
{ {
from: ::EE::Gitlab::Access.level_name(old), from: ::Gitlab::Access.level_name(old),
to: ::EE::Gitlab::Access.level_name(new) to: ::Gitlab::Access.level_name(new)
} }
when :plan_id when :plan_id
{ {
......
...@@ -8,23 +8,26 @@ ...@@ -8,23 +8,26 @@
module EE module EE
module Gitlab module Gitlab
module Access module Access
extend self extend ActiveSupport::Concern
# Default project creation level # Default project creation level
NO_ONE_PROJECT_ACCESS = 0 NO_ONE_PROJECT_ACCESS = 0
MAINTAINER_PROJECT_ACCESS = 1 MAINTAINER_PROJECT_ACCESS = 1
DEVELOPER_MAINTAINER_PROJECT_ACCESS = 2 DEVELOPER_MAINTAINER_PROJECT_ACCESS = 2
ADMIN = 60
def project_creation_options class_methods do
{ def project_creation_options
s_('ProjectCreationLevel|No one') => NO_ONE_PROJECT_ACCESS, {
s_('ProjectCreationLevel|Maintainers') => MAINTAINER_PROJECT_ACCESS, s_('ProjectCreationLevel|No one') => NO_ONE_PROJECT_ACCESS,
s_('ProjectCreationLevel|Developers + Maintainers') => DEVELOPER_MAINTAINER_PROJECT_ACCESS s_('ProjectCreationLevel|Maintainers') => MAINTAINER_PROJECT_ACCESS,
} s_('ProjectCreationLevel|Developers + Maintainers') => DEVELOPER_MAINTAINER_PROJECT_ACCESS
end }
end
def level_name(name) def level_name(name)
project_creation_options.key(name) project_creation_options.key(name)
end
end end
end end
end end
......
# frozen_string_literal: true
module EE
module Gitlab
module BackgroundMigration
module PopulateImportState
extend ::Gitlab::Utils::Override
override :move_attributes_data_to_import_state
def move_attributes_data_to_import_state(start_id, end_id)
Rails.logger.info("#{self.class.name} - Moving import attributes data to project mirror data table: #{start_id} - #{end_id}")
ActiveRecord::Base.connection.execute <<~SQL
INSERT INTO project_mirror_data (project_id, status, jid, last_update_at, last_successful_update_at, last_error)
SELECT id, import_status, import_jid, mirror_last_update_at, mirror_last_successful_update_at, import_error
FROM projects
WHERE projects.import_status != 'none'
AND projects.id BETWEEN #{start_id} AND #{end_id}
AND NOT EXISTS (
SELECT id
FROM project_mirror_data
WHERE project_id = projects.id
)
SQL
ActiveRecord::Base.connection.execute <<~SQL
UPDATE projects
SET import_status = 'none'
WHERE import_status != 'none'
AND id BETWEEN #{start_id} AND #{end_id}
SQL
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module BackgroundMigration
module RollbackImportStateData
extend ::Gitlab::Utils::Override
override :move_attributes_data_to_project
def move_attributes_data_to_project(start_id, end_id)
Rails.logger.info("#{self.class.name} - Moving import attributes data to projects table: #{start_id} - #{end_id}")
if ::Gitlab::Database.mysql?
ActiveRecord::Base.connection.execute <<~SQL
UPDATE projects, project_mirror_data
SET
projects.import_status = project_mirror_data.status,
projects.import_jid = project_mirror_data.jid,
projects.mirror_last_update_at = project_mirror_data.last_update_at,
projects.mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
projects.import_error = project_mirror_data.last_error
WHERE project_mirror_data.project_id = projects.id
AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id}
SQL
else
ActiveRecord::Base.connection.execute <<~SQL
UPDATE projects
SET
import_status = project_mirror_data.status,
import_jid = project_mirror_data.jid,
mirror_last_update_at = project_mirror_data.last_update_at,
mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
import_error = project_mirror_data.last_error
FROM project_mirror_data
WHERE project_mirror_data.project_id = projects.id
AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id}
SQL
end
end
end
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module Ci
module Pipeline
module Chain
module Validate
module Abilities
extend ::Gitlab::Utils::Override
override :perform!
def perform!
# We check for `builds_enabled?` here so that this error does
# not get produced before the "pipelines are disabled" error.
if project.builds_enabled? &&
(command.allow_mirror_update && !project.mirror_trigger_builds?)
return error('Pipeline is disabled for mirror updates')
end
super
end
end
end
end
end
end
end
end
...@@ -3,41 +3,45 @@ ...@@ -3,41 +3,45 @@
module EE module EE
module Gitlab module Gitlab
module Database module Database
extend ::Gitlab::Utils::Override extend ActiveSupport::Concern
override :read_only? class_methods do
def read_only? extend ::Gitlab::Utils::Override
::Gitlab::Geo.secondary?
end
def healthy? override :read_only?
return true unless postgresql? def read_only?
::Gitlab::Geo.secondary?
end
!Postgresql::ReplicationSlot.lag_too_great? def healthy?
end return true unless postgresql?
# Disables prepared statements for the current database connection. !Postgresql::ReplicationSlot.lag_too_great?
def disable_prepared_statements end
config = ActiveRecord::Base.configurations[Rails.env]
config['prepared_statements'] = false
ActiveRecord::Base.establish_connection(config) # Disables prepared statements for the current database connection.
end def disable_prepared_statements
config = ActiveRecord::Base.configurations[Rails.env]
config['prepared_statements'] = false
ActiveRecord::Base.establish_connection(config)
end
override :add_post_migrate_path_to_rails override :add_post_migrate_path_to_rails
def add_post_migrate_path_to_rails(force: false) def add_post_migrate_path_to_rails(force: false)
super super
migrate_paths = Rails.application.config.paths['db/migrate'].to_a migrate_paths = Rails.application.config.paths['db/migrate'].to_a
migrate_paths.each do |migrate_path| migrate_paths.each do |migrate_path|
relative_migrate_path = Pathname.new(migrate_path).realpath(Rails.root).relative_path_from(Rails.root) relative_migrate_path = Pathname.new(migrate_path).realpath(Rails.root).relative_path_from(Rails.root)
ee_migrate_path = Rails.root.join('ee/', relative_migrate_path) ee_migrate_path = Rails.root.join('ee/', relative_migrate_path)
next if relative_migrate_path.to_s.start_with?('ee/') || next if relative_migrate_path.to_s.start_with?('ee/') ||
Rails.application.config.paths['db/migrate'].include?(ee_migrate_path.to_s) Rails.application.config.paths['db/migrate'].include?(ee_migrate_path.to_s)
Rails.application.config.paths['db/migrate'] << ee_migrate_path.to_s Rails.application.config.paths['db/migrate'] << ee_migrate_path.to_s
ActiveRecord::Migrator.migrations_paths << ee_migrate_path.to_s ActiveRecord::Migrator.migrations_paths << ee_migrate_path.to_s
end
end end
end end
end end
......
# frozen_string_literal: true
module EE
module Gitlab
module ExclusiveLease
# Try to obtain the lease. Returns the UUID and current TTL, which will be
# zero if it's not taken.
# rubocop: disable Gitlab/ModuleWithInstanceVariables
def try_obtain_with_ttl
::Gitlab::Redis::SharedState.with do |redis|
output = redis.set(@redis_shared_state_key, @uuid, nx: true, ex: @timeout) && @uuid
ttl = output ? 0 : redis.ttl(@redis_shared_state_key)
{ ttl: [ttl, 0].max, uuid: output }
end
end
# rubocop: enable Gitlab/ModuleWithInstanceVariables
# Returns true if the UUID for the key hasn't changed.
# rubocop: disable Gitlab/ModuleWithInstanceVariables
def same_uuid?
::Gitlab::Redis::SharedState.with do |redis|
redis.get(@redis_shared_state_key) == @uuid
end
end
# rubocop: enable Gitlab/ModuleWithInstanceVariables
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module Favicon
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :development_favicon
def development_favicon
'favicon-green.png'
end
end
end
end
end
...@@ -5,6 +5,8 @@ module EE ...@@ -5,6 +5,8 @@ module EE
module GitAccess module GitAccess
prepend GeoGitAccess prepend GeoGitAccess
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
include ActionView::Helpers::SanitizeHelper
include PathLocksHelper
override :check override :check
def check(cmd, changes) def check(cmd, changes)
......
# frozen_string_literal: true
module EE
module Gitlab
module ObjectHierarchy
# rubocop: disable CodeReuse/ActiveRecord
def roots
base_and_ancestors.where(namespaces: { parent_id: nil })
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
# frozen_string_literal: true
module EE
module Gitlab
module PathRegex
extend ActiveSupport::Concern
class_methods do
def saml_callback_regex
@saml_callback_regex ||= %r(\A\/groups\/(?<group>#{full_namespace_route_regex})\/\-\/saml\/callback\z).freeze
end
end
end
end
end
...@@ -3,41 +3,45 @@ ...@@ -3,41 +3,45 @@
module EE module EE
module Gitlab module Gitlab
module Regex module Regex
def environment_scope_regex_chars extend ActiveSupport::Concern
"#{environment_name_regex_chars}\\*"
end
def environment_scope_regex class_methods do
@environment_scope_regex ||= /\A[#{environment_scope_regex_chars}]+\z/.freeze def environment_scope_regex_chars
end "#{environment_name_regex_chars}\\*"
end
def environment_scope_regex_message def environment_scope_regex
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', '*' and spaces" @environment_scope_regex ||= /\A[#{environment_scope_regex_chars}]+\z/.freeze
end end
def package_name_regex def environment_scope_regex_message
@package_name_regex ||= %r{\A\@?(([\w\-\.]*)/)*([\w\-\.]*)\z}.freeze "can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', '*' and spaces"
end end
def maven_path_regex def package_name_regex
@maven_path_regex ||= %r{\A\@?(([\w\-\.]*)/)*([\w\-\.\+]*)\z}.freeze @package_name_regex ||= %r{\A\@?(([\w\-\.]*)/)*([\w\-\.]*)\z}.freeze
end end
def maven_app_name_regex def maven_path_regex
@maven_app_name_regex ||= /\A[\w\-\.]+\z/.freeze @maven_path_regex ||= %r{\A\@?(([\w\-\.]*)/)*([\w\-\.\+]*)\z}.freeze
end end
def maven_app_group_regex def maven_app_name_regex
maven_app_name_regex @maven_app_name_regex ||= /\A[\w\-\.]+\z/.freeze
end end
def feature_flag_regex def maven_app_group_regex
/\A[a-z]([-_a-z0-9]*[a-z0-9])?\z/ maven_app_name_regex
end end
def feature_flag_regex
/\A[a-z]([-_a-z0-9]*[a-z0-9])?\z/
end
def feature_flag_regex_message def feature_flag_regex_message
"can contain only lowercase letters, digits, '_' and '-'. " \ "can contain only lowercase letters, digits, '_' and '-'. " \
"Must start with a letter, and cannot end with '-' or '_'" "Must start with a letter, and cannot end with '-' or '_'"
end
end end
end end
end end
......
...@@ -3,142 +3,146 @@ ...@@ -3,142 +3,146 @@
module EE module EE
module Gitlab module Gitlab
module UsageData module UsageData
extend ::Gitlab::Utils::Override extend ActiveSupport::Concern
override :features_usage_data class_methods do
def features_usage_data extend ::Gitlab::Utils::Override
super.merge(features_usage_data_ee)
end
def features_usage_data_ee
{
elasticsearch_enabled: ::Gitlab::CurrentSettings.elasticsearch_search?,
geo_enabled: ::Gitlab::Geo.enabled?
}
end
override :license_usage_data override :features_usage_data
def license_usage_data def features_usage_data
usage_data = super super.merge(features_usage_data_ee)
license = ::License.current
usage_data[:edition] =
if license
license.edition
else
'EE Free'
end
if license
usage_data[:license_md5] = license.md5
usage_data[:license_id] = license.license_id
usage_data[:historical_max_users] = ::HistoricalData.max_historical_user_count
usage_data[:licensee] = license.licensee
usage_data[:license_user_count] = license.restricted_user_count
usage_data[:license_starts_at] = license.starts_at
usage_data[:license_expires_at] = license.expires_at
usage_data[:license_plan] = license.plan
usage_data[:license_add_ons] = license.add_ons
usage_data[:license_trial] = license.trial?
end end
usage_data def features_usage_data_ee
end {
elasticsearch_enabled: ::Gitlab::CurrentSettings.elasticsearch_search?,
geo_enabled: ::Gitlab::Geo.enabled?
}
end
# rubocop: disable CodeReuse/ActiveRecord override :license_usage_data
def projects_mirrored_with_pipelines_enabled def license_usage_data
count(::Project.joins(:project_feature).where( usage_data = super
mirror: true, license = ::License.current
mirror_trigger_builds: true, usage_data[:edition] =
project_features: { if license
builds_access_level: ::ProjectFeature::ENABLED license.edition
} else
)) 'EE Free'
end end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord if license
def service_desk_counts usage_data[:license_md5] = license.md5
return {} unless ::License.feature_available?(:service_desk) usage_data[:license_id] = license.license_id
usage_data[:historical_max_users] = ::HistoricalData.max_historical_user_count
usage_data[:licensee] = license.licensee
usage_data[:license_user_count] = license.restricted_user_count
usage_data[:license_starts_at] = license.starts_at
usage_data[:license_expires_at] = license.expires_at
usage_data[:license_plan] = license.plan
usage_data[:license_add_ons] = license.add_ons
usage_data[:license_trial] = license.trial?
end
projects_with_service_desk = ::Project.where(service_desk_enabled: true) usage_data
end
{ # rubocop: disable CodeReuse/ActiveRecord
service_desk_enabled_projects: count(projects_with_service_desk), def projects_mirrored_with_pipelines_enabled
service_desk_issues: count(::Issue.where( count(::Project.joins(:project_feature).where(
project: projects_with_service_desk, mirror: true,
author: ::User.support_bot, mirror_trigger_builds: true,
confidential: true project_features: {
builds_access_level: ::ProjectFeature::ENABLED
}
)) ))
} end
end # rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord def service_desk_counts
def security_products_usage return {} unless ::License.feature_available?(:service_desk)
types = {
container_scanning: :container_scanning_jobs, projects_with_service_desk = ::Project.where(service_desk_enabled: true)
dast: :dast_jobs,
dependency_scanning: :dependency_scanning_jobs, {
license_management: :license_management_jobs, service_desk_enabled_projects: count(projects_with_service_desk),
sast: :sast_jobs service_desk_issues: count(::Issue.where(
} project: projects_with_service_desk,
author: ::User.support_bot,
results = count(::Ci::Build.where(name: types.keys).group(:name), fallback: Hash.new(-1)) confidential: true
results.each_with_object({}) { |(key, value), response| response[types[key.to_sym]] = value } ))
end }
# rubocop: enable CodeReuse/ActiveRecord end
# rubocop: enable CodeReuse/ActiveRecord
# Note: when adding a preference, check if it's mapped to an attribute of a User model. If so, name
# the base key part after a corresponding User model attribute, use its possible values as suffix values. # rubocop: disable CodeReuse/ActiveRecord
override :user_preferences_usage def security_products_usage
def user_preferences_usage types = {
super.tap do |user_prefs_usage| container_scanning: :container_scanning_jobs,
if ::Feature.enabled?(:group_overview_security_dashboard) dast: :dast_jobs,
user_prefs_usage.merge!( dependency_scanning: :dependency_scanning_jobs,
group_overview_details: count(::User.active.group_view_details), license_management: :license_management_jobs,
group_overview_security_dashboard: count(::User.active.group_view_security_dashboard) sast: :sast_jobs
) }
results = count(::Ci::Build.where(name: types.keys).group(:name), fallback: Hash.new(-1))
results.each_with_object({}) { |(key, value), response| response[types[key.to_sym]] = value }
end
# rubocop: enable CodeReuse/ActiveRecord
# Note: when adding a preference, check if it's mapped to an attribute of a User model. If so, name
# the base key part after a corresponding User model attribute, use its possible values as suffix values.
override :user_preferences_usage
def user_preferences_usage
super.tap do |user_prefs_usage|
if ::Feature.enabled?(:group_overview_security_dashboard)
user_prefs_usage.merge!(
group_overview_details: count(::User.active.group_view_details),
group_overview_security_dashboard: count(::User.active.group_view_security_dashboard)
)
end
end end
end end
end
override :system_usage_data override :system_usage_data
def system_usage_data def system_usage_data
usage_data = super usage_data = super
usage_data[:counts] = usage_data[:counts].merge({ usage_data[:counts] = usage_data[:counts].merge({
epics: count(::Epic), epics: count(::Epic),
feature_flags: count(Operations::FeatureFlag), feature_flags: count(Operations::FeatureFlag),
geo_nodes: count(::GeoNode), geo_nodes: count(::GeoNode),
ldap_group_links: count(::LdapGroupLink), ldap_group_links: count(::LdapGroupLink),
ldap_keys: count(::LDAPKey), ldap_keys: count(::LDAPKey),
ldap_users: count(::User.ldap), ldap_users: count(::User.ldap),
projects_reporting_ci_cd_back_to_github: count(::GithubService.without_defaults.active), projects_reporting_ci_cd_back_to_github: count(::GithubService.without_defaults.active),
projects_mirrored_with_pipelines_enabled: projects_mirrored_with_pipelines_enabled, projects_mirrored_with_pipelines_enabled: projects_mirrored_with_pipelines_enabled,
projects_with_prometheus_alerts: count(PrometheusAlert.distinct_projects), projects_with_prometheus_alerts: count(PrometheusAlert.distinct_projects),
projects_with_packages: count(::Packages::Package.select('distinct project_id')), projects_with_packages: count(::Packages::Package.select('distinct project_id')),
projects_with_tracing_enabled: count(ProjectTracingSetting), projects_with_tracing_enabled: count(ProjectTracingSetting),
projects_enforcing_code_owner_approval: count(::Project.without_deleted.non_archived.requiring_code_owner_approval) projects_enforcing_code_owner_approval: count(::Project.without_deleted.non_archived.requiring_code_owner_approval)
}).merge(service_desk_counts).merge(security_products_usage) }).merge(service_desk_counts).merge(security_products_usage)
# MySql does not support recursive queries so we can't retrieve epics relationship depth # MySql does not support recursive queries so we can't retrieve epics relationship depth
if ::Group.supports_nested_objects? if ::Group.supports_nested_objects?
usage_data[:counts] = usage_data[:counts].merge(epics_deepest_relationship_level) usage_data[:counts] = usage_data[:counts].merge(epics_deepest_relationship_level)
end end
usage_data usage_data
end end
override :jira_usage override :jira_usage
def jira_usage def jira_usage
super.merge( super.merge(
projects_jira_dvcs_cloud_active: count(ProjectFeatureUsage.with_jira_dvcs_integration_enabled), projects_jira_dvcs_cloud_active: count(ProjectFeatureUsage.with_jira_dvcs_integration_enabled),
projects_jira_dvcs_server_active: count(ProjectFeatureUsage.with_jira_dvcs_integration_enabled(cloud: false)) projects_jira_dvcs_server_active: count(ProjectFeatureUsage.with_jira_dvcs_integration_enabled(cloud: false))
) )
end end
def epics_deepest_relationship_level def epics_deepest_relationship_level
{ epics_deepest_relationship_level: ::Epic.deepest_relationship_level } { epics_deepest_relationship_level: ::Epic.deepest_relationship_level }
end
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities do
set(:project) { create(:project, :repository) }
set(:user) { create(:user) }
let(:pipeline) do
build_stubbed(:ci_pipeline, project: project)
end
let(:command) do
Gitlab::Ci::Pipeline::Chain::Command
.new(project: project, current_user: user, origin_ref: ref)
end
let(:step) { described_class.new(pipeline, command) }
let(:ref) { 'master' }
describe '#perform!' do
context 'when triggering builds for project mirrors is disabled' do
it 'returns an error' do
project.add_developer(user)
allow(command)
.to receive(:allow_mirror_update)
.and_return(true)
allow(project)
.to receive(:mirror_trigger_builds?)
.and_return(false)
step.perform!
expect(pipeline.errors.to_a)
.to include('Pipeline is disabled for mirror updates')
end
end
end
end
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
# #
module Gitlab module Gitlab
module Access module Access
extend ::EE::Gitlab::Access # rubocop: disable Cop/InjectEnterpriseEditionModule
AccessDeniedError = Class.new(StandardError) AccessDeniedError = Class.new(StandardError)
NO_ACCESS = 0 NO_ACCESS = 0
...@@ -19,7 +17,6 @@ module Gitlab ...@@ -19,7 +17,6 @@ module Gitlab
# @deprecated # @deprecated
MASTER = MAINTAINER MASTER = MAINTAINER
OWNER = 50 OWNER = 50
ADMIN = 60
# Branch protection settings # Branch protection settings
PROTECTION_NONE = 0 PROTECTION_NONE = 0
...@@ -89,3 +86,5 @@ module Gitlab ...@@ -89,3 +86,5 @@ module Gitlab
end end
end end
end end
Gitlab::Access.prepend(EE::Gitlab::Access)
...@@ -15,8 +15,8 @@ module Gitlab ...@@ -15,8 +15,8 @@ module Gitlab
Rails.logger.info("#{self.class.name} - Moving import attributes data to project mirror data table: #{start_id} - #{end_id}") Rails.logger.info("#{self.class.name} - Moving import attributes data to project mirror data table: #{start_id} - #{end_id}")
ActiveRecord::Base.connection.execute <<~SQL ActiveRecord::Base.connection.execute <<~SQL
INSERT INTO project_mirror_data (project_id, status, jid, last_update_at, last_successful_update_at, last_error) INSERT INTO project_mirror_data (project_id, status, jid, last_error)
SELECT id, import_status, import_jid, mirror_last_update_at, mirror_last_successful_update_at, import_error SELECT id, import_status, import_jid, import_error
FROM projects FROM projects
WHERE projects.import_status != 'none' WHERE projects.import_status != 'none'
AND projects.id BETWEEN #{start_id} AND #{end_id} AND projects.id BETWEEN #{start_id} AND #{end_id}
...@@ -37,3 +37,5 @@ module Gitlab ...@@ -37,3 +37,5 @@ module Gitlab
end end
end end
end end
Gitlab::BackgroundMigration::PopulateImportState.prepend(EE::Gitlab::BackgroundMigration::PopulateImportState)
...@@ -18,8 +18,6 @@ module Gitlab ...@@ -18,8 +18,6 @@ module Gitlab
SET SET
projects.import_status = project_mirror_data.status, projects.import_status = project_mirror_data.status,
projects.import_jid = project_mirror_data.jid, projects.import_jid = project_mirror_data.jid,
projects.mirror_last_update_at = project_mirror_data.last_update_at,
projects.mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
projects.import_error = project_mirror_data.last_error projects.import_error = project_mirror_data.last_error
WHERE project_mirror_data.project_id = projects.id WHERE project_mirror_data.project_id = projects.id
AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id} AND project_mirror_data.id BETWEEN #{start_id} AND #{end_id}
...@@ -30,8 +28,6 @@ module Gitlab ...@@ -30,8 +28,6 @@ module Gitlab
SET SET
import_status = project_mirror_data.status, import_status = project_mirror_data.status,
import_jid = project_mirror_data.jid, import_jid = project_mirror_data.jid,
mirror_last_update_at = project_mirror_data.last_update_at,
mirror_last_successful_update_at = project_mirror_data.last_successful_update_at,
import_error = project_mirror_data.last_error import_error = project_mirror_data.last_error
FROM project_mirror_data FROM project_mirror_data
WHERE project_mirror_data.project_id = projects.id WHERE project_mirror_data.project_id = projects.id
...@@ -42,3 +38,5 @@ module Gitlab ...@@ -42,3 +38,5 @@ module Gitlab
end end
end end
end end
Gitlab::BackgroundMigration::RollbackImportStateData.prepend(EE::Gitlab::BackgroundMigration::RollbackImportStateData)
...@@ -11,10 +11,7 @@ module Gitlab ...@@ -11,10 +11,7 @@ module Gitlab
:trigger_request, :schedule, :merge_request, :trigger_request, :schedule, :merge_request,
:ignore_skip_ci, :save_incompleted, :ignore_skip_ci, :save_incompleted,
:seeds_block, :variables_attributes, :push_options, :seeds_block, :variables_attributes, :push_options,
:chat_data, :chat_data, :allow_mirror_update
# EE specific
:allow_mirror_update
) do ) do
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
......
...@@ -14,10 +14,6 @@ module Gitlab ...@@ -14,10 +14,6 @@ module Gitlab
return error('Pipelines are disabled!') return error('Pipelines are disabled!')
end end
if @command.allow_mirror_update && !project.mirror_trigger_builds?
return error('Pipeline is disabled for mirror updates')
end
unless allowed_to_trigger_pipeline? unless allowed_to_trigger_pipeline?
if can?(current_user, :create_pipeline, project) if can?(current_user, :create_pipeline, project)
return error("Insufficient permissions for protected ref '#{command.ref}'") return error("Insufficient permissions for protected ref '#{command.ref}'")
...@@ -58,3 +54,5 @@ module Gitlab ...@@ -58,3 +54,5 @@ module Gitlab
end end
end end
end end
Gitlab::Ci::Pipeline::Chain::Validate::Abilities.prepend(EE::Gitlab::Ci::Pipeline::Chain::Validate::Abilities)
...@@ -11,10 +11,6 @@ module Gitlab ...@@ -11,10 +11,6 @@ module Gitlab
# https://dev.mysql.com/doc/refman/5.7/en/datetime.html # https://dev.mysql.com/doc/refman/5.7/en/datetime.html
MAX_TIMESTAMP_VALUE = Time.at((1 << 31) - 1).freeze MAX_TIMESTAMP_VALUE = Time.at((1 << 31) - 1).freeze
class << self
prepend EE::Gitlab::Database # rubocop: disable Cop/InjectEnterpriseEditionModule
end
def self.config def self.config
ActiveRecord::Base.configurations[Rails.env] ActiveRecord::Base.configurations[Rails.env]
end end
...@@ -274,3 +270,5 @@ module Gitlab ...@@ -274,3 +270,5 @@ module Gitlab
end end
end end
end end
Gitlab::Database.prepend(EE::Gitlab::Database)
...@@ -68,18 +68,6 @@ module Gitlab ...@@ -68,18 +68,6 @@ module Gitlab
end end
end end
# Try to obtain the lease. Returns the UUID and current TTL, which will be
# zero if it's not taken.
def try_obtain_with_ttl
Gitlab::Redis::SharedState.with do |redis|
output = redis.set(@redis_shared_state_key, @uuid, nx: true, ex: @timeout) && @uuid
ttl = output ? 0 : redis.ttl(@redis_shared_state_key)
{ ttl: [ttl, 0].max, uuid: output }
end
end
# Try to renew an existing lease. Return lease UUID on success, # Try to renew an existing lease. Return lease UUID on success,
# false if the lease is taken by a different UUID or inexistent. # false if the lease is taken by a different UUID or inexistent.
def renew def renew
...@@ -106,12 +94,7 @@ module Gitlab ...@@ -106,12 +94,7 @@ module Gitlab
ttl if ttl.positive? ttl if ttl.positive?
end end
end end
# Returns true if the UUID for the key hasn't changed.
def same_uuid?
Gitlab::Redis::SharedState.with do |redis|
redis.get(@redis_shared_state_key) == @uuid
end
end
end end
end end
Gitlab::ExclusiveLease.prepend(EE::Gitlab::ExclusiveLease)
...@@ -10,7 +10,7 @@ module Gitlab ...@@ -10,7 +10,7 @@ module Gitlab
elsif Gitlab::Utils.to_boolean(ENV['CANARY']) elsif Gitlab::Utils.to_boolean(ENV['CANARY'])
'favicon-yellow.png' 'favicon-yellow.png'
elsif Rails.env.development? elsif Rails.env.development?
'favicon-green.png' development_favicon
else else
'favicon.png' 'favicon.png'
end end
...@@ -18,6 +18,12 @@ module Gitlab ...@@ -18,6 +18,12 @@ module Gitlab
ActionController::Base.helpers.image_path(image_name, host: host) ActionController::Base.helpers.image_path(image_name, host: host)
end end
def development_favicon
# This is a separate method so that EE can return a different favicon
# for development environments.
'favicon-blue.png'
end
def status_overlay(status_name) def status_overlay(status_name)
path = File.join( path = File.join(
'ci_favicons', 'ci_favicons',
...@@ -58,3 +64,5 @@ module Gitlab ...@@ -58,3 +64,5 @@ module Gitlab
end end
end end
end end
Gitlab::Favicon.prepend(EE::Gitlab::Favicon)
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
# class return an instance of `GitlabAccessStatus` # class return an instance of `GitlabAccessStatus`
module Gitlab module Gitlab
class GitAccess class GitAccess
prepend ::EE::Gitlab::GitAccess # rubocop: disable Cop/InjectEnterpriseEditionModule
include ActionView::Helpers::SanitizeHelper
include PathLocksHelper
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
UnauthorizedError = Class.new(StandardError) UnauthorizedError = Class.new(StandardError)
...@@ -249,22 +246,18 @@ module Gitlab ...@@ -249,22 +246,18 @@ module Gitlab
end end
end end
# TODO: please clean this up
def check_push_access! def check_push_access!
if project.repository_read_only? if project.repository_read_only?
# The repository is temporarily read-only. Please try again later.
raise UnauthorizedError, ERROR_MESSAGES[:read_only] raise UnauthorizedError, ERROR_MESSAGES[:read_only]
end end
if deploy_key? if deploy_key?
unless deploy_key.can_push_to?(project) unless deploy_key.can_push_to?(project)
# This deploy key does not have write access to this project.
raise UnauthorizedError, ERROR_MESSAGES[:deploy_key_upload] raise UnauthorizedError, ERROR_MESSAGES[:deploy_key_upload]
end end
elsif user elsif user
# User access is verified in check_change_access! # User access is verified in check_change_access!
else else
# You are not allowed to upload code for this project.
raise UnauthorizedError, ERROR_MESSAGES[:upload] raise UnauthorizedError, ERROR_MESSAGES[:upload]
end end
...@@ -407,3 +400,5 @@ module Gitlab ...@@ -407,3 +400,5 @@ module Gitlab
end end
end end
end end
Gitlab::GitAccess.prepend(EE::Gitlab::GitAccess)
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
module Gitlab module Gitlab
module HookData module HookData
class IssueBuilder < BaseBuilder class IssueBuilder < BaseBuilder
prepend ::EE::Gitlab::HookData::IssueBuilder # rubocop: disable Cop/InjectEnterpriseEditionModule
SAFE_HOOK_RELATIONS = %i[ SAFE_HOOK_RELATIONS = %i[
assignees assignees
labels labels
...@@ -55,3 +53,5 @@ module Gitlab ...@@ -55,3 +53,5 @@ module Gitlab
end end
end end
end end
Gitlab::HookData::IssueBuilder.prepend(EE::Gitlab::HookData::IssueBuilder)
...@@ -39,12 +39,6 @@ module Gitlab ...@@ -39,12 +39,6 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def roots
base_and_ancestors.where(namespaces: { parent_id: nil })
end
# rubocop: enable CodeReuse/ActiveRecord
# Returns a relation that includes the ancestors_base set of objects # Returns a relation that includes the ancestors_base set of objects
# and all their ancestors (recursively). # and all their ancestors (recursively).
# #
...@@ -179,3 +173,5 @@ module Gitlab ...@@ -179,3 +173,5 @@ module Gitlab
end end
end end
end end
Gitlab::ObjectHierarchy.prepend(EE::Gitlab::ObjectHierarchy)
...@@ -233,10 +233,6 @@ module Gitlab ...@@ -233,10 +233,6 @@ module Gitlab
}x }x
end end
def saml_callback_regex
@saml_callback_regex ||= %r(\A\/groups\/(?<group>#{full_namespace_route_regex})\/\-\/saml\/callback\z).freeze
end
private private
def single_line_regexp(regex) def single_line_regexp(regex)
...@@ -246,3 +242,5 @@ module Gitlab ...@@ -246,3 +242,5 @@ module Gitlab
end end
end end
end end
Gitlab::PathRegex.prepend(EE::Gitlab::PathRegex)
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
module Gitlab module Gitlab
module Regex module Regex
extend self extend self
extend EE::Gitlab::Regex # rubocop: disable Cop/InjectEnterpriseEditionModule
def namespace_name_regex def namespace_name_regex
@namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze @namespace_name_regex ||= /\A[\p{Alnum}\p{Pd}_\. ]*\z/.freeze
...@@ -108,3 +107,5 @@ module Gitlab ...@@ -108,3 +107,5 @@ module Gitlab
end end
end end
end end
Gitlab::Regex.prepend(EE::Gitlab::Regex)
...@@ -5,8 +5,6 @@ module Gitlab ...@@ -5,8 +5,6 @@ module Gitlab
APPROXIMATE_COUNT_MODELS = [Label, MergeRequest, Note, Todo].freeze APPROXIMATE_COUNT_MODELS = [Label, MergeRequest, Note, Todo].freeze
class << self class << self
prepend EE::Gitlab::UsageData # rubocop: disable Cop/InjectEnterpriseEditionModule
def data(force_refresh: false) def data(force_refresh: false)
Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data } Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data }
end end
...@@ -31,7 +29,7 @@ module Gitlab ...@@ -31,7 +29,7 @@ module Gitlab
installation_type: Gitlab::INSTALLATION_TYPE, installation_type: Gitlab::INSTALLATION_TYPE,
active_user_count: count(User.active), active_user_count: count(User.active),
recorded_at: Time.now, recorded_at: Time.now,
edition: 'EE' edition: 'CE'
} }
usage_data usage_data
...@@ -192,3 +190,5 @@ module Gitlab ...@@ -192,3 +190,5 @@ module Gitlab
end end
end end
end end
Gitlab::UsageData.prepend(EE::Gitlab::UsageData)
...@@ -104,7 +104,6 @@ module Gitlab ...@@ -104,7 +104,6 @@ module Gitlab
nil nil
end end
# EE below
def try_megabytes_to_bytes(size) def try_megabytes_to_bytes(size)
Integer(size).megabytes Integer(size).megabytes
rescue ArgumentError rescue ArgumentError
......
...@@ -213,4 +213,22 @@ describe Gitlab::Utils do ...@@ -213,4 +213,22 @@ describe Gitlab::Utils do
expect(subject[:variables].first[:key]).to eq('VAR1') expect(subject[:variables].first[:key]).to eq('VAR1')
end end
end end
describe '.try_megabytes_to_bytes' do
context 'when the size can be converted to megabytes' do
it 'returns the size in megabytes' do
size = described_class.try_megabytes_to_bytes(1)
expect(size).to eq(1.megabytes)
end
end
context 'when the size can not be converted to megabytes' do
it 'returns the input size' do
size = described_class.try_megabytes_to_bytes('foo')
expect(size).to eq('foo')
end
end
end
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