summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-02 00:07:41 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-02 00:07:41 +0000
commit42263d6451c0af3c0e7a61747ffb046a806e4477 (patch)
tree989941de7bbf543963942e7d9a4b1b89bdf7e386 /app
parent2412ddf03da787012161ea1e8a03787275f9cde9 (diff)
downloadgitlab-ce-42263d6451c0af3c0e7a61747ffb046a806e4477.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/models/resource_event.rb (renamed from app/models/concerns/resource_event_tools.rb)25
-rw-r--r--app/models/resource_label_event.rb18
-rw-r--r--app/models/resource_milestone_event.rb12
-rw-r--r--app/models/resource_weight_event.rb19
4 files changed, 26 insertions, 48 deletions
diff --git a/app/models/concerns/resource_event_tools.rb b/app/models/resource_event.rb
index 7226b9573e1..9b3a211ad43 100644
--- a/app/models/concerns/resource_event_tools.rb
+++ b/app/models/resource_event.rb
@@ -1,16 +1,27 @@
# frozen_string_literal: true
-module ResourceEventTools
- extend ActiveSupport::Concern
+class ResourceEvent < ApplicationRecord
+ include Gitlab::Utils::StrongMemoize
+ include Importable
- included do
- belongs_to :user
+ self.abstract_class = true
- validates :user, presence: { unless: :importing? }, on: :create
+ validates :user, presence: { unless: :importing? }, on: :create
- validate :exactly_one_issuable
+ belongs_to :user
- scope :created_after, ->(time) { where('created_at > ?', time) }
+ scope :created_after, ->(time) { where('created_at > ?', time) }
+
+ def discussion_id
+ strong_memoize(:discussion_id) do
+ Digest::SHA1.hexdigest(discussion_id_key.join("-"))
+ end
+ end
+
+ private
+
+ def discussion_id_key
+ [self.class.name, created_at, user_id]
end
def exactly_one_issuable
diff --git a/app/models/resource_label_event.rb b/app/models/resource_label_event.rb
index 59907f1b962..970d4e1e562 100644
--- a/app/models/resource_label_event.rb
+++ b/app/models/resource_label_event.rb
@@ -1,10 +1,7 @@
# frozen_string_literal: true
-class ResourceLabelEvent < ApplicationRecord
- include Importable
- include Gitlab::Utils::StrongMemoize
+class ResourceLabelEvent < ResourceEvent
include CacheMarkdownField
- include ResourceEventTools
cache_markdown_field :reference
@@ -13,8 +10,11 @@ class ResourceLabelEvent < ApplicationRecord
belongs_to :label
scope :inc_relations, -> { includes(:label, :user) }
+ scope :by_issue, ->(issue) { where(issue_id: issue.id) }
+ scope :by_merge_request, ->(merge_request) { where(merge_request_id: merge_request.id) }
validates :label, presence: { unless: :importing? }, on: :create
+ validate :exactly_one_issuable
after_save :expire_etag_cache
after_destroy :expire_etag_cache
@@ -41,12 +41,6 @@ class ResourceLabelEvent < ApplicationRecord
issue || merge_request
end
- def discussion_id(resource = nil)
- strong_memoize(:discussion_id) do
- Digest::SHA1.hexdigest(discussion_id_key.join("-"))
- end
- end
-
def project
issuable.project
end
@@ -109,10 +103,6 @@ class ResourceLabelEvent < ApplicationRecord
def resource_parent
issuable.project || issuable.group
end
-
- def discussion_id_key
- [self.class.name, created_at, user_id]
- end
end
ResourceLabelEvent.prepend_if_ee('EE::ResourceLabelEvent')
diff --git a/app/models/resource_milestone_event.rb b/app/models/resource_milestone_event.rb
index ba43a1ee363..d362ebc307a 100644
--- a/app/models/resource_milestone_event.rb
+++ b/app/models/resource_milestone_event.rb
@@ -1,10 +1,6 @@
# frozen_string_literal: true
-class ResourceMilestoneEvent < ApplicationRecord
- include Gitlab::Utils::StrongMemoize
- include Importable
- include ResourceEventTools
-
+class ResourceMilestoneEvent < ResourceEvent
belongs_to :issue
belongs_to :merge_request
belongs_to :milestone
@@ -12,6 +8,8 @@ class ResourceMilestoneEvent < ApplicationRecord
scope :by_issue, ->(issue) { where(issue_id: issue.id) }
scope :by_merge_request, ->(merge_request) { where(merge_request_id: merge_request.id) }
+ validate :exactly_one_issuable
+
enum action: {
add: 1,
remove: 2
@@ -23,8 +21,4 @@ class ResourceMilestoneEvent < ApplicationRecord
def self.issuable_attrs
%i(issue merge_request).freeze
end
-
- def resource
- issue || merge_request
- end
end
diff --git a/app/models/resource_weight_event.rb b/app/models/resource_weight_event.rb
index ab288798aed..e0cc0c87a83 100644
--- a/app/models/resource_weight_event.rb
+++ b/app/models/resource_weight_event.rb
@@ -1,26 +1,9 @@
# frozen_string_literal: true
-class ResourceWeightEvent < ApplicationRecord
- include Gitlab::Utils::StrongMemoize
-
- validates :user, presence: true
+class ResourceWeightEvent < ResourceEvent
validates :issue, presence: true
- belongs_to :user
belongs_to :issue
scope :by_issue, ->(issue) { where(issue_id: issue.id) }
- scope :created_after, ->(time) { where('created_at > ?', time) }
-
- def discussion_id(resource = nil)
- strong_memoize(:discussion_id) do
- Digest::SHA1.hexdigest(discussion_id_key.join("-"))
- end
- end
-
- private
-
- def discussion_id_key
- [self.class.name, created_at, user_id]
- end
end