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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 13:00:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-20 13:00:54 +0300
commit3cccd102ba543e02725d247893729e5c73b38295 (patch)
treef36a04ec38517f5deaaacb5acc7d949688d1e187 /app/validators/gitlab/emoji_name_validator.rb
parent205943281328046ef7b4528031b90fbda70c75ac (diff)
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
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