2020-01-02 13:03:23 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# We store events about issuable label changes and weight changes in a separate
|
|
|
|
# table (not as other system notes), but we still want to display notes about
|
|
|
|
# label changes and weight changes as classic system notes in UI. This service
|
|
|
|
# generates "synthetic" notes for label event changes.
|
|
|
|
|
|
|
|
module ResourceEvents
|
|
|
|
class BaseSyntheticNotesBuilderService
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
attr_reader :resource, :current_user, :params
|
|
|
|
|
|
|
|
def initialize(resource, current_user, params = {})
|
|
|
|
@resource = resource
|
|
|
|
@current_user = current_user
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
synthetic_notes
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-07-17 00:09:37 +00:00
|
|
|
def apply_common_filters(events)
|
|
|
|
events = apply_last_fetched_at(events)
|
2021-04-19 15:09:08 +00:00
|
|
|
apply_fetch_until(events)
|
2020-07-17 00:09:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def apply_last_fetched_at(events)
|
2020-01-02 13:03:23 +00:00
|
|
|
return events unless params[:last_fetched_at].present?
|
|
|
|
|
2020-07-17 00:09:37 +00:00
|
|
|
last_fetched_at = params[:last_fetched_at] - NotesFinder::FETCH_OVERLAP
|
|
|
|
|
|
|
|
events.created_after(last_fetched_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
def apply_fetch_until(events)
|
|
|
|
return events unless params[:fetch_until].present?
|
|
|
|
|
|
|
|
events.created_on_or_before(params[:fetch_until])
|
2020-01-02 13:03:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def resource_parent
|
|
|
|
strong_memoize(:resource_parent) do
|
|
|
|
resource.project || resource.group
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|