Commit 647cbed2 authored by Sean McGivern's avatar Sean McGivern Committed by Douglas Barbosa Alexandre

Remove EE-specific code from 'Discussion' models

parent 5626a354
...@@ -25,7 +25,7 @@ module Noteable ...@@ -25,7 +25,7 @@ module Noteable
end end
def supports_discussions? def supports_discussions?
DiscussionNote::NOTEABLE_TYPES.include?(base_class_name) DiscussionNote.noteable_types.include?(base_class_name)
end end
def discussions_rendered_on_frontend? def discussions_rendered_on_frontend?
......
...@@ -8,12 +8,14 @@ class DiffNote < Note ...@@ -8,12 +8,14 @@ class DiffNote < Note
include DiffPositionableNote include DiffPositionableNote
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
NOTEABLE_TYPES = %w(MergeRequest Commit).freeze def self.noteable_types
%w(MergeRequest Commit)
end
validates :original_position, presence: true validates :original_position, presence: true
validates :position, presence: true validates :position, presence: true
validates :line_code, presence: true, line_code: true, if: :on_text? validates :line_code, presence: true, line_code: true, if: :on_text?
validates :noteable_type, inclusion: { in: NOTEABLE_TYPES } validates :noteable_type, inclusion: { in: noteable_types }
validate :positions_complete validate :positions_complete
validate :verify_supported validate :verify_supported
validate :diff_refs_match_commit, if: :for_commit? validate :diff_refs_match_commit, if: :for_commit?
......
...@@ -4,10 +4,14 @@ ...@@ -4,10 +4,14 @@
# #
# A note of this type can be resolvable. # A note of this type can be resolvable.
class DiscussionNote < Note class DiscussionNote < Note
prepend EE::DiscussionNote
# Names of all implementers of `Noteable` that support discussions. # Names of all implementers of `Noteable` that support discussions.
NOTEABLE_TYPES = %w(MergeRequest Issue Commit Snippet Epic).freeze def self.noteable_types
%w(MergeRequest Issue Commit Snippet)
end
validates :noteable_type, inclusion: { in: NOTEABLE_TYPES } validates :noteable_type, inclusion: { in: noteable_types }
def discussion_class(*) def discussion_class(*)
Discussion Discussion
......
...@@ -7,11 +7,7 @@ ...@@ -7,11 +7,7 @@
# #
# A note of this type is never resolvable. # A note of this type is never resolvable.
class LegacyDiffNote < Note class LegacyDiffNote < Note
# Elastic search configuration (it does not support STI properly) prepend EE::LegacyDiffNote
document_type 'doc'
index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
include Elastic::NotesSearch
include NoteOnDiff include NoteOnDiff
serialize :st_diff # rubocop:disable Cop/ActiveRecordSerialize serialize :st_diff # rubocop:disable Cop/ActiveRecordSerialize
......
...@@ -26,7 +26,6 @@ class MergeRequest < ActiveRecord::Base ...@@ -26,7 +26,6 @@ class MergeRequest < ActiveRecord::Base
:deleted_at :deleted_at
prepend ::EE::MergeRequest prepend ::EE::MergeRequest
include Elastic::MergeRequestsSearch
belongs_to :target_project, class_name: "Project" belongs_to :target_project, class_name: "Project"
belongs_to :source_project, class_name: "Project" belongs_to :source_project, class_name: "Project"
...@@ -163,7 +162,6 @@ class MergeRequest < ActiveRecord::Base ...@@ -163,7 +162,6 @@ class MergeRequest < ActiveRecord::Base
validates :merge_user, presence: true, if: :merge_when_pipeline_succeeds?, unless: :importing? validates :merge_user, presence: true, if: :merge_when_pipeline_succeeds?, unless: :importing?
validate :validate_branches, unless: [:allow_broken, :importing?, :closed_without_fork?] validate :validate_branches, unless: [:allow_broken, :importing?, :closed_without_fork?]
validate :validate_fork, unless: :closed_without_fork? validate :validate_fork, unless: :closed_without_fork?
validate :validate_approvals_before_merge, unless: :importing?
validate :validate_target_project, on: :create validate :validate_target_project, on: :create
scope :by_source_or_target_branch, ->(branch_name) do scope :by_source_or_target_branch, ->(branch_name) do
...@@ -678,7 +676,6 @@ class MergeRequest < ActiveRecord::Base ...@@ -678,7 +676,6 @@ class MergeRequest < ActiveRecord::Base
end end
def mergeable?(skip_ci_check: false) def mergeable?(skip_ci_check: false)
return false unless approved?
return false unless mergeable_state?(skip_ci_check: skip_ci_check) return false unless mergeable_state?(skip_ci_check: skip_ci_check)
check_if_can_be_merged check_if_can_be_merged
......
...@@ -15,11 +15,10 @@ class Milestone < ActiveRecord::Base ...@@ -15,11 +15,10 @@ class Milestone < ActiveRecord::Base
include Sortable include Sortable
include Referable include Referable
include StripAttribute include StripAttribute
include Elastic::MilestonesSearch
include Milestoneish include Milestoneish
include Gitlab::SQL::Pattern include Gitlab::SQL::Pattern
include ::EE::Milestone prepend ::EE::Milestone
cache_markdown_field :title, pipeline: :single_line cache_markdown_field :title, pipeline: :single_line
cache_markdown_field :description cache_markdown_field :description
...@@ -30,7 +29,6 @@ class Milestone < ActiveRecord::Base ...@@ -30,7 +29,6 @@ class Milestone < ActiveRecord::Base
has_internal_id :iid, scope: :project, init: ->(s) { s&.project&.milestones&.maximum(:iid) } has_internal_id :iid, scope: :project, init: ->(s) { s&.project&.milestones&.maximum(:iid) }
has_internal_id :iid, scope: :group, init: ->(s) { s&.group&.milestones&.maximum(:iid) } has_internal_id :iid, scope: :group, init: ->(s) { s&.group&.milestones&.maximum(:iid) }
has_many :boards
has_many :issues has_many :issues
has_many :labels, -> { distinct.reorder('labels.title') }, through: :issues has_many :labels, -> { distinct.reorder('labels.title') }, through: :issues
has_many :merge_requests has_many :merge_requests
......
...@@ -9,7 +9,6 @@ class Note < ActiveRecord::Base ...@@ -9,7 +9,6 @@ class Note < ActiveRecord::Base
include Participable include Participable
include Mentionable include Mentionable
include Elastic::NotesSearch
include Awardable include Awardable
include Importable include Importable
include FasterCacheKeys include FasterCacheKeys
...@@ -103,7 +102,6 @@ class Note < ActiveRecord::Base ...@@ -103,7 +102,6 @@ class Note < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader mount_uploader :attachment, AttachmentUploader
# Scopes # Scopes
scope :searchable, -> { where(system: false) }
scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) } scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) }
scope :system, -> { where(system: true) } scope :system, -> { where(system: true) }
scope :user, -> { where(system: false) } scope :user, -> { where(system: false) }
...@@ -200,10 +198,6 @@ class Note < ActiveRecord::Base ...@@ -200,10 +198,6 @@ class Note < ActiveRecord::Base
end end
end end
def searchable?
!system
end
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
def cross_reference? def cross_reference?
return unless system? return unless system?
......
# frozen_string_literal: true # frozen_string_literal: true
class PersonalSnippet < Snippet class PersonalSnippet < Snippet
# Elastic search configuration (it does not support STI) prepend EE::PersonalSnippet
document_type 'doc'
index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
include Elastic::SnippetsSearch
include WithUploads include WithUploads
end end
# frozen_string_literal: true # frozen_string_literal: true
class ProjectSnippet < Snippet class ProjectSnippet < Snippet
# Elastic search configuration (it does not support STI) prepend EE::ProjectSnippet
document_type 'doc'
index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
include Elastic::SnippetsSearch
belongs_to :project belongs_to :project
belongs_to :author, class_name: "User" belongs_to :author, class_name: "User"
......
...@@ -11,7 +11,6 @@ class SystemNoteMetadata < ActiveRecord::Base ...@@ -11,7 +11,6 @@ class SystemNoteMetadata < ActiveRecord::Base
TYPES_WITH_CROSS_REFERENCES = %w[ TYPES_WITH_CROSS_REFERENCES = %w[
commit cross_reference commit cross_reference
close duplicate close duplicate
relate unrelate
moved moved
].freeze ].freeze
......
# frozen_string_literal: true
module EE
module DiscussionNote
extend ActiveSupport::Concern
class_methods do
extend ::Gitlab::Utils::Override
override :noteable_types
def noteable_types
super + %w(Epic)
end
end
end
end
# frozen_string_literal: true
module EE
module LegacyDiffNote
extend ActiveSupport::Concern
prepended do
# Elastic search configuration (it does not support STI properly)
document_type 'doc'
index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
include Elastic::NotesSearch
end
end
end
module EE module EE
module MergeRequest module MergeRequest
extend ActiveSupport::Concern extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
include ::Approvable include ::Approvable
prepended do prepended do
include Elastic::MergeRequestsSearch
has_many :approvals, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent has_many :approvals, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_many :approved_by_users, through: :approvals, source: :user has_many :approved_by_users, through: :approvals, source: :user
has_many :approvers, as: :target, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent has_many :approvers, as: :target, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_many :approver_groups, as: :target, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent has_many :approver_groups, as: :target, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
has_many :draft_notes has_many :draft_notes
validate :validate_approvals_before_merge, unless: :importing?
delegate :performance_artifact, to: :head_pipeline, prefix: :head, allow_nil: true delegate :performance_artifact, to: :head_pipeline, prefix: :head, allow_nil: true
delegate :performance_artifact, to: :base_pipeline, prefix: :base, allow_nil: true delegate :performance_artifact, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :license_management_artifact, to: :head_pipeline, prefix: :head, allow_nil: true delegate :license_management_artifact, to: :head_pipeline, prefix: :head, allow_nil: true
...@@ -24,6 +29,13 @@ module EE ...@@ -24,6 +29,13 @@ module EE
participant :participant_approvers participant :participant_approvers
end end
override :mergeable?
def mergeable?(skip_ci_check: false)
return false unless approved?
super
end
def supports_weight? def supports_weight?
false false
end end
......
# frozen_string_literal: true
module EE module EE
module Milestone module Milestone
extend ActiveSupport::Concern
prepended do
include Elastic::MilestonesSearch
has_many :boards
end
def supports_weight? def supports_weight?
parent&.feature_available?(:issue_weights) parent&.feature_available?(:issue_weights)
end end
......
...@@ -5,6 +5,13 @@ module EE ...@@ -5,6 +5,13 @@ module EE
prepended do prepended do
include ::ObjectStorage::BackgroundMove include ::ObjectStorage::BackgroundMove
include Elastic::NotesSearch
scope :searchable, -> { where(system: false) }
end
def searchable?
!system
end end
def for_epic? def for_epic?
......
# frozen_string_literal: true
module EE
module PersonalSnippet
extend ActiveSupport::Concern
prepended do
document_type 'doc'
index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
include Elastic::SnippetsSearch
end
end
end
# frozen_string_literal: true
module EE
module ProjectSnippet
extend ActiveSupport::Concern
prepended do
document_type 'doc'
index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
include Elastic::SnippetsSearch
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