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