2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
# rubocop:disable Style/Documentation
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module BackgroundMigration
|
|
|
|
module UserMentions
|
|
|
|
module Models
|
|
|
|
class Note < ActiveRecord::Base
|
2020-10-24 23:57:45 +05:30
|
|
|
include EachBatch
|
2020-04-08 14:13:33 +05:30
|
|
|
include Concerns::IsolatedMentionable
|
2020-03-13 15:44:24 +05:30
|
|
|
include CacheMarkdownField
|
|
|
|
|
|
|
|
self.table_name = 'notes'
|
|
|
|
self.inheritance_column = :_type_disabled
|
|
|
|
|
|
|
|
attr_mentionable :note, pipeline: :note
|
|
|
|
cache_markdown_field :note, pipeline: :note, issuable_state_filter_enabled: true
|
|
|
|
|
|
|
|
belongs_to :author, class_name: "User"
|
|
|
|
belongs_to :noteable, polymorphic: true
|
|
|
|
belongs_to :project
|
|
|
|
|
|
|
|
def for_personal_snippet?
|
2020-04-08 14:13:33 +05:30
|
|
|
noteable && noteable.class.name == 'PersonalSnippet'
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def for_project_noteable?
|
2020-04-22 19:07:51 +05:30
|
|
|
!for_personal_snippet? && !for_epic?
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def skip_project_check?
|
|
|
|
!for_project_noteable?
|
|
|
|
end
|
|
|
|
|
|
|
|
def for_epic?
|
2020-04-08 14:13:33 +05:30
|
|
|
noteable && noteable_type == 'Epic'
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def user_mention_resource_id
|
|
|
|
noteable_id || commit_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_mention_note_id
|
|
|
|
id
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
def noteable
|
|
|
|
super unless for_commit?
|
|
|
|
end
|
|
|
|
|
|
|
|
def for_commit?
|
|
|
|
noteable_type == "Commit"
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def mentionable_params
|
|
|
|
return super unless for_epic?
|
|
|
|
|
|
|
|
super.merge(banzai_context_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def banzai_context_params
|
2020-04-08 14:13:33 +05:30
|
|
|
return {} unless noteable
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
{ group: noteable.group, label_url_method: :group_epics_url }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|