summaryrefslogtreecommitdiff
path: root/app/services/resource_events
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-02 13:03:23 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-02 13:03:23 +0000
commita72a9af092c1bfcf9f8024d59c11cf222f07e1e7 (patch)
tree44b60265c1d476d026b2862d2c1244748f558d4f /app/services/resource_events
parentb085478c4c2bed74fdc6eb2c33bfc62e791baf03 (diff)
downloadgitlab-ce-a72a9af092c1bfcf9f8024d59c11cf222f07e1e7.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/resource_events')
-rw-r--r--app/services/resource_events/base_synthetic_notes_builder_service.rb39
-rw-r--r--app/services/resource_events/merge_into_notes_service.rb43
-rw-r--r--app/services/resource_events/synthetic_label_notes_builder_service.rb27
3 files changed, 75 insertions, 34 deletions
diff --git a/app/services/resource_events/base_synthetic_notes_builder_service.rb b/app/services/resource_events/base_synthetic_notes_builder_service.rb
new file mode 100644
index 00000000000..1b85ca811a1
--- /dev/null
+++ b/app/services/resource_events/base_synthetic_notes_builder_service.rb
@@ -0,0 +1,39 @@
+# 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
+
+ def since_fetch_at(events)
+ return events unless params[:last_fetched_at].present?
+
+ last_fetched_at = Time.at(params.fetch(:last_fetched_at).to_i)
+ events.created_after(last_fetched_at - NotesFinder::FETCH_OVERLAP)
+ end
+
+ def resource_parent
+ strong_memoize(:resource_parent) do
+ resource.project || resource.group
+ end
+ end
+ end
+end
diff --git a/app/services/resource_events/merge_into_notes_service.rb b/app/services/resource_events/merge_into_notes_service.rb
index 7504773a002..47948fcff6e 100644
--- a/app/services/resource_events/merge_into_notes_service.rb
+++ b/app/services/resource_events/merge_into_notes_service.rb
@@ -1,10 +1,9 @@
# frozen_string_literal: true
-# We store events about issuable label changes in a separate table (not as
-# other system notes), but we still want to display notes about label changes
-# as classic system notes in UI. This service generates "synthetic" notes for
-# label event changes and merges them with classic notes and sorts them by
-# creation time.
+# We store events about issuable label changes and weight changes in separate tables (not as
+# other system notes), but we still want to display notes about label and weight changes
+# as classic system notes in UI. This service merges synthetic label and weight notes
+# with classic notes and sorts them by creation time.
module ResourceEvents
class MergeIntoNotesService
@@ -19,39 +18,15 @@ module ResourceEvents
end
def execute(notes = [])
- (notes + label_notes).sort_by { |n| n.created_at }
+ (notes + synthetic_notes).sort_by { |n| n.created_at }
end
private
- def label_notes
- label_events_by_discussion_id.map do |discussion_id, events|
- LabelNote.from_events(events, resource: resource, resource_parent: resource_parent)
- end
- end
-
- # rubocop: disable CodeReuse/ActiveRecord
- def label_events_by_discussion_id
- return [] unless resource.respond_to?(:resource_label_events)
-
- events = resource.resource_label_events.includes(:label, user: :status)
- events = since_fetch_at(events)
-
- events.group_by { |event| event.discussion_id }
- end
- # rubocop: enable CodeReuse/ActiveRecord
-
- def since_fetch_at(events)
- return events unless params[:last_fetched_at].present?
-
- last_fetched_at = Time.at(params.fetch(:last_fetched_at).to_i)
- events.created_after(last_fetched_at - NotesFinder::FETCH_OVERLAP)
- end
-
- def resource_parent
- strong_memoize(:resource_parent) do
- resource.project || resource.group
- end
+ def synthetic_notes
+ SyntheticLabelNotesBuilderService.new(resource, current_user, params).execute
end
end
end
+
+ResourceEvents::MergeIntoNotesService.prepend_if_ee('EE::ResourceEvents::MergeIntoNotesService')
diff --git a/app/services/resource_events/synthetic_label_notes_builder_service.rb b/app/services/resource_events/synthetic_label_notes_builder_service.rb
new file mode 100644
index 00000000000..fd128101b49
--- /dev/null
+++ b/app/services/resource_events/synthetic_label_notes_builder_service.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+# We store events about issuable label changes in a separate table (not as
+# other system notes), but we still want to display notes about label changes
+# as classic system notes in UI. This service generates "synthetic" notes for
+# label event changes.
+
+module ResourceEvents
+ class SyntheticLabelNotesBuilderService < BaseSyntheticNotesBuilderService
+ private
+
+ def synthetic_notes
+ label_events_by_discussion_id.map do |discussion_id, events|
+ LabelNote.from_events(events, resource: resource, resource_parent: resource_parent)
+ end
+ end
+
+ def label_events_by_discussion_id
+ return [] unless resource.respond_to?(:resource_label_events)
+
+ events = resource.resource_label_events.includes(:label, user: :status) # rubocop: disable CodeReuse/ActiveRecord
+ events = since_fetch_at(events)
+
+ events.group_by { |event| event.discussion_id }
+ end
+ end
+end