Commit 57f98564 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'bvl-design-diff-notes-ce' into 'master'

Adjustments related to DiffNotes on diffs outside of a project's main repository

See merge request gitlab-org/gitlab-ce!29023
parents 280aa61e 7412e2fa
......@@ -3,14 +3,16 @@
module Noteable
extend ActiveSupport::Concern
# `Noteable` class names that support resolvable notes.
RESOLVABLE_TYPES = %w(MergeRequest).freeze
class_methods do
# `Noteable` class names that support replying to individual notes.
def replyable_types
%w(Issue MergeRequest)
end
# `Noteable` class names that support resolvable notes.
def resolvable_types
%w(MergeRequest)
end
end
# The timestamp of the note (e.g. the :created_at or :updated_at attribute if provided via
......@@ -36,7 +38,7 @@ module Noteable
end
def supports_resolvable_notes?
RESOLVABLE_TYPES.include?(base_class_name)
self.class.resolvable_types.include?(base_class_name)
end
def supports_discussions?
......@@ -131,3 +133,5 @@ module Noteable
)
end
end
Noteable.extend(Noteable::ClassMethods)
......@@ -12,7 +12,7 @@ module ResolvableNote
validates :resolved_by, presence: true, if: :resolved?
# Keep this scope in sync with `#potentially_resolvable?`
scope :potentially_resolvable, -> { where(type: RESOLVABLE_TYPES).where(noteable_type: Noteable::RESOLVABLE_TYPES) }
scope :potentially_resolvable, -> { where(type: RESOLVABLE_TYPES).where(noteable_type: Noteable.resolvable_types) }
# Keep this scope in sync with `#resolvable?`
scope :resolvable, -> { potentially_resolvable.user }
......
......@@ -15,7 +15,9 @@ class DiffNote < Note
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 }
# We need to evaluate the `noteable` types when running the validation since
# EE might have added a type when the module was prepended
validates :noteable_type, inclusion: { in: -> (_note) { noteable_types } }
validate :positions_complete
validate :verify_supported
validate :diff_refs_match_commit, if: :for_commit?
......@@ -44,7 +46,7 @@ class DiffNote < Note
# Returns the diff file from `position`
def latest_diff_file
strong_memoize(:latest_diff_file) do
position.diff_file(project.repository)
position.diff_file(repository)
end
end
......@@ -111,7 +113,7 @@ class DiffNote < Note
if note_diff_file
diff = Gitlab::Git::Diff.new(note_diff_file.to_hash)
Gitlab::Diff::File.new(diff,
repository: project.repository,
repository: repository,
diff_refs: original_position.diff_refs)
elsif created_at_diff?(noteable.diff_refs)
# We're able to use the already persisted diffs (Postgres) if we're
......@@ -122,7 +124,7 @@ class DiffNote < Note
# `Diff::FileCollection::MergeRequestDiff`.
noteable.diffs(original_position.diff_options).diff_files.first
else
original_position.diff_file(self.project.repository)
original_position.diff_file(repository)
end
# Since persisted diff files already have its content "unfolded"
......@@ -137,7 +139,7 @@ class DiffNote < Note
end
def set_line_code
self.line_code = self.position.line_code(self.project.repository)
self.line_code = self.position.line_code(repository)
end
def verify_supported
......@@ -171,6 +173,10 @@ class DiffNote < Note
shas << self.position.head_sha
end
project.repository.keep_around(*shas)
repository.keep_around(*shas)
end
def repository
noteable.respond_to?(:repository) ? noteable.repository : project.repository
end
end
......@@ -206,7 +206,7 @@ module API
delete_note(noteable, params[:note_id])
end
if Noteable::RESOLVABLE_TYPES.include?(noteable_type.to_s)
if Noteable.resolvable_types.include?(noteable_type.to_s)
desc "Resolve/unresolve an existing #{noteable_type.to_s.downcase} discussion" do
success Entities::Discussion
end
......
......@@ -260,4 +260,16 @@ describe Noteable do
end
end
end
describe '.replyable_types' do
it 'exposes the replyable types' do
expect(described_class.replyable_types).to include('Issue', 'MergeRequest')
end
end
describe '.resolvable_types' do
it 'exposes the replyable types' do
expect(described_class.resolvable_types).to include('MergeRequest')
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