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
diff options
context:
space:
mode:
Diffstat (limited to 'app/validators/gitlab/emoji_name_validator.rb')
-rw-r--r--app/validators/gitlab/emoji_name_validator.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/app/validators/gitlab/emoji_name_validator.rb b/app/validators/gitlab/emoji_name_validator.rb
index a9092d0194f..c034a79214b 100644
--- a/app/validators/gitlab/emoji_name_validator.rb
+++ b/app/validators/gitlab/emoji_name_validator.rb
@@ -11,9 +11,22 @@
module Gitlab
class EmojiNameValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
- unless TanukiEmoji.find_by_alpha_code(value.to_s)
- record.errors.add(attribute, (options[:message] || 'is not a valid emoji name'))
- end
+ return if valid_tanuki_emoji?(value)
+ return if valid_custom_emoji?(record, value)
+
+ record.errors.add(attribute, (options[:message] || 'is not a valid emoji name'))
+ end
+
+ private
+
+ def valid_tanuki_emoji?(value)
+ TanukiEmoji.find_by_alpha_code(value.to_s)
+ end
+
+ def valid_custom_emoji?(record, value)
+ resource = record.try(:resource_parent)
+
+ CustomEmoji.for_resource(resource).by_name(value.to_s).any?
end
end
end