diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 09:10:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 09:10:17 +0300 |
commit | fb10c412ec153dd64a9c5ce98e6c6091621e62c2 (patch) | |
tree | 0253638333028d0e151e9e93da50e14e36877f16 /app/services/resource_events | |
parent | fefca4c7b96dddf0afcd34f33be8bf249448918b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/resource_events')
-rw-r--r-- | app/services/resource_events/base_change_timebox_service.rb | 35 | ||||
-rw-r--r-- | app/services/resource_events/change_milestone_service.rb | 29 |
2 files changed, 46 insertions, 18 deletions
diff --git a/app/services/resource_events/base_change_timebox_service.rb b/app/services/resource_events/base_change_timebox_service.rb new file mode 100644 index 00000000000..5c83f7b12f7 --- /dev/null +++ b/app/services/resource_events/base_change_timebox_service.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module ResourceEvents + class BaseChangeTimeboxService + attr_reader :resource, :user, :event_created_at + + def initialize(resource, user, created_at: Time.current) + @resource = resource + @user = user + @event_created_at = created_at + end + + def execute + create_event + + resource.expire_note_etag_cache + end + + private + + def create_event + raise NotImplementedError + end + + def build_resource_args + key = resource.class.name.foreign_key + + { + user_id: user.id, + created_at: event_created_at, + key => resource.id + } + end + end +end diff --git a/app/services/resource_events/change_milestone_service.rb b/app/services/resource_events/change_milestone_service.rb index 82c3e2acad5..dcdf87599ac 100644 --- a/app/services/resource_events/change_milestone_service.rb +++ b/app/services/resource_events/change_milestone_service.rb @@ -1,37 +1,30 @@ # frozen_string_literal: true module ResourceEvents - class ChangeMilestoneService - attr_reader :resource, :user, :event_created_at, :milestone, :old_milestone + class ChangeMilestoneService < BaseChangeTimeboxService + attr_reader :milestone, :old_milestone def initialize(resource, user, created_at: Time.current, old_milestone:) - @resource = resource - @user = user - @event_created_at = created_at + super(resource, user, created_at: created_at) + @milestone = resource&.milestone @old_milestone = old_milestone end - def execute - ResourceMilestoneEvent.create(build_resource_args) + private - resource.expire_note_etag_cache + def create_event + ResourceMilestoneEvent.create(build_resource_args) end - private - def build_resource_args action = milestone.blank? ? :remove : :add - key = resource.class.name.foreign_key - { - user_id: user.id, - created_at: event_created_at, - milestone_id: action == :add ? milestone&.id : old_milestone&.id, + super.merge({ state: ResourceMilestoneEvent.states[resource.state], - action: ResourceMilestoneEvent.actions[action], - key => resource.id - } + action: ResourceTimeboxEvent.actions[action], + milestone_id: milestone.blank? ? old_milestone&.id : milestone&.id + }) end end end |