Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/ability.rb2
-rw-r--r--app/models/concerns/cache_markdown_field.rb8
-rw-r--r--app/models/concerns/mentionable.rb6
-rw-r--r--app/models/concerns/participable.rb3
-rw-r--r--app/models/note.rb10
-rw-r--r--app/services/notes/post_process_service.rb9
-rw-r--r--app/services/notes/slash_commands_service.rb2
-rw-r--r--app/services/notification_service.rb23
-rw-r--r--app/views/notify/note_personal_snippet_email.html.haml2
-rw-r--r--app/views/notify/note_personal_snippet_email.text.erb8
10 files changed, 46 insertions, 27 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 5bad5c17747..ad6c588202e 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -29,7 +29,7 @@ class Ability
when Snippet::INTERNAL, Snippet::PUBLIC
users
when Snippet::PRIVATE
- users.select { |user| snippet.author == user }
+ users.include?(snippet.author) ? [snippet.author] : []
end
end
diff --git a/app/models/concerns/cache_markdown_field.rb b/app/models/concerns/cache_markdown_field.rb
index 25970158e70..a600f9c14c5 100644
--- a/app/models/concerns/cache_markdown_field.rb
+++ b/app/models/concerns/cache_markdown_field.rb
@@ -51,6 +51,10 @@ module CacheMarkdownField
CACHING_CLASSES.map(&:constantize)
end
+ def skip_project_check?
+ false
+ end
+
extend ActiveSupport::Concern
included do
@@ -112,9 +116,7 @@ module CacheMarkdownField
invalidation_method = "#{html_field}_invalidated?".to_sym
define_method(cache_method) do
- options = {
- skip_project_check: is_a?(Note) && for_personal_snippet?
- }
+ options = { skip_project_check: skip_project_check? }
html = Banzai::Renderer.cacheless_render_field(self, markdown_field, options)
__send__("#{html_field}=", html)
true
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb
index 9ded015aad3..ef2c1e5d414 100644
--- a/app/models/concerns/mentionable.rb
+++ b/app/models/concerns/mentionable.rb
@@ -52,7 +52,7 @@ module Mentionable
options = options.merge(
cache_key: [self, attr],
author: author,
- skip_project_check: is_a?(Note) && for_personal_snippet?
+ skip_project_check: skip_project_check?
)
extractor.analyze(text, options)
@@ -125,4 +125,8 @@ module Mentionable
def cross_reference_exists?(target)
SystemNoteService.cross_reference_exists?(target, local_reference)
end
+
+ def skip_project_check?
+ false
+ end
end
diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb
index 5d8a223fc21..4865c0a14b1 100644
--- a/app/models/concerns/participable.rb
+++ b/app/models/concerns/participable.rb
@@ -96,7 +96,8 @@ module Participable
participants.merge(ext.users)
- if self.is_a?(PersonalSnippet)
+ case self
+ when PersonalSnippet
Ability.users_that_can_read_personal_snippet(participants.to_a, self)
else
Ability.users_that_can_read_project(participants.to_a, project)
diff --git a/app/models/note.rb b/app/models/note.rb
index cbf1d0adda7..bf090a0438c 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -167,7 +167,11 @@ class Note < ActiveRecord::Base
end
def for_personal_snippet?
- noteable_type == "Snippet" && noteable.type == 'PersonalSnippet'
+ noteable.is_a?(PersonalSnippet)
+ end
+
+ def skip_project_check?
+ for_personal_snippet?
end
# override to return commits, which are not active record
@@ -225,6 +229,10 @@ class Note < ActiveRecord::Base
note.match(Banzai::Filter::EmojiFilter.emoji_pattern)[1]
end
+ def to_ability_name
+ for_personal_snippet? ? 'personal_snippet' : noteable_type.underscore
+ end
+
private
def keep_around_commit
diff --git a/app/services/notes/post_process_service.rb b/app/services/notes/post_process_service.rb
index 45d916800f6..6a10e172483 100644
--- a/app/services/notes/post_process_service.rb
+++ b/app/services/notes/post_process_service.rb
@@ -10,10 +10,11 @@ module Notes
# Skip system notes, like status changes and cross-references and awards
unless @note.system?
EventCreateService.new.leave_note(@note, @note.author)
- unless @note.for_personal_snippet?
- @note.create_cross_references!
- execute_note_hooks
- end
+
+ return if @note.for_personal_snippet?
+
+ @note.create_cross_references!
+ execute_note_hooks
end
end
diff --git a/app/services/notes/slash_commands_service.rb b/app/services/notes/slash_commands_service.rb
index aaea9717fc4..56913568cae 100644
--- a/app/services/notes/slash_commands_service.rb
+++ b/app/services/notes/slash_commands_service.rb
@@ -12,7 +12,7 @@ module Notes
def self.supported?(note, current_user)
noteable_update_service(note) &&
current_user &&
- current_user.can?(:"update_#{note.noteable_type.underscore}", note.noteable)
+ current_user.can?(:"update_#{note.to_ability_name}", note.noteable)
end
def supported?(note)
diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb
index 2a467ade542..f74e6cac174 100644
--- a/app/services/notification_service.rb
+++ b/app/services/notification_service.rb
@@ -179,14 +179,14 @@ class NotificationService
mentioned_users = note.mentioned_users
- if note.for_personal_snippet?
- mentioned_users.select! do |user|
- user.can?(:read_personal_snippet, note.noteable)
- end
- else
- mentioned_users.select! do |user|
- user.can?(:read_project, note.project)
- end
+ ability, subject = if note.for_personal_snippet?
+ [:read_personal_snippet, note.noteable]
+ else
+ [:read_project, note.project]
+ end
+
+ mentioned_users.select! do |user|
+ user.can?(ability, subject)
end
# Add all users participating in the thread (author, assignee, comment authors)
@@ -220,12 +220,7 @@ class NotificationService
recipients.delete(note.author)
recipients = recipients.uniq
- # build notify method like 'note_commit_email'
- if note.for_personal_snippet?
- notify_method = "note_personal_snippet_email".to_sym
- else
- notify_method = "note_#{note.noteable_type.underscore}_email".to_sym
- end
+ notify_method = "note_#{note.to_ability_name}_email".to_sym
recipients.each do |recipient|
mailer.send(notify_method, recipient.id, note.id).deliver_later
diff --git a/app/views/notify/note_personal_snippet_email.html.haml b/app/views/notify/note_personal_snippet_email.html.haml
index 3da199095d8..2fa2f784661 100644
--- a/app/views/notify/note_personal_snippet_email.html.haml
+++ b/app/views/notify/note_personal_snippet_email.html.haml
@@ -1 +1 @@
-render 'note_message'
+= render 'note_message'
diff --git a/app/views/notify/note_personal_snippet_email.text.erb b/app/views/notify/note_personal_snippet_email.text.erb
new file mode 100644
index 00000000000..b2a8809a23b
--- /dev/null
+++ b/app/views/notify/note_personal_snippet_email.text.erb
@@ -0,0 +1,8 @@
+New comment for Snippet <%= @snippet.id %>
+
+<%= url_for(snippet_url(@snippet, anchor: "note_#{@note.id}")) %>
+
+
+Author: <%= @note.author_name %>
+
+<%= @note.note %>