summaryrefslogtreecommitdiff
path: root/app/models/event.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-19 12:09:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-19 12:09:33 +0000
commit652bd073731b0028641672a75355c7918b5ac116 (patch)
treee0239f98153492ac89c6fc374c5dfd1aa270d8bf /app/models/event.rb
parent2af90cef2e2e9c776eae4394a43dba3be7f33d1e (diff)
downloadgitlab-ce-652bd073731b0028641672a75355c7918b5ac116.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/event.rb')
-rw-r--r--app/models/event.rb31
1 files changed, 30 insertions, 1 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index 18682bd694c..c4ca5389fdf 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -6,6 +6,7 @@ class Event < ApplicationRecord
include Presentable
include DeleteWithLimit
include CreatedAtFilterable
+ include Gitlab::Utils::StrongMemoize
default_scope { reorder(nil) }
@@ -42,7 +43,8 @@ class Event < ApplicationRecord
note: Note,
project: Project,
snippet: Snippet,
- user: User
+ user: User,
+ wiki: WikiPage::Meta
).freeze
RESET_PROJECT_ACTIVITY_INTERVAL = 1.hour
@@ -79,6 +81,7 @@ class Event < ApplicationRecord
scope :recent, -> { reorder(id: :desc) }
scope :code_push, -> { where(action: PUSHED) }
scope :merged, -> { where(action: MERGED) }
+ scope :for_wiki_page, -> { where(target_type: WikiPage::Meta.name) }
scope :with_associations, -> do
# We're using preload for "push_event_payload" as otherwise the association
@@ -197,6 +200,14 @@ class Event < ApplicationRecord
created_action? && !target && target_type.nil?
end
+ def created_wiki_page?
+ wiki_page? && action == CREATED
+ end
+
+ def updated_wiki_page?
+ wiki_page? && action == UPDATED
+ end
+
def created_target?
created_action? && target
end
@@ -217,6 +228,10 @@ class Event < ApplicationRecord
target_type == "MergeRequest"
end
+ def wiki_page?
+ target_type == WikiPage::Meta.name
+ end
+
def milestone
target if milestone?
end
@@ -229,6 +244,14 @@ class Event < ApplicationRecord
target if merge_request?
end
+ def wiki_page
+ strong_memoize(:wiki_page) do
+ next unless wiki_page?
+
+ ProjectWiki.new(project, author).find_page(target.canonical_slug)
+ end
+ end
+
def note
target if note?
end
@@ -250,6 +273,10 @@ class Event < ApplicationRecord
'destroyed'
elsif commented_action?
"commented on"
+ elsif created_wiki_page?
+ 'created'
+ elsif updated_wiki_page?
+ 'updated'
elsif created_project_action?
created_project_action_name
else
@@ -362,6 +389,8 @@ class Event < ApplicationRecord
:read_snippet
elsif milestone?
:read_milestone
+ elsif wiki_page?
+ :read_wiki
end
end
end