diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-02 12:08:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-02 12:08:25 +0000 |
commit | ac2d27b008ced210e234910179234bc45f31b7e1 (patch) | |
tree | a2c6b7b081eb6e32f9e33d11c85eb76a9053d18c /app/validators | |
parent | a84d2572e943a70fdf95ef4514499df7c5f9db67 (diff) | |
download | gitlab-ce-ac2d27b008ced210e234910179234bc45f31b7e1.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/gitlab/emoji_name_validator.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/app/validators/gitlab/emoji_name_validator.rb b/app/validators/gitlab/emoji_name_validator.rb index a9092d0194f..c14d6e4ec78 100644 --- a/app/validators/gitlab/emoji_name_validator.rb +++ b/app/validators/gitlab/emoji_name_validator.rb @@ -11,9 +11,24 @@ 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) + namespace = record.try(:awardable).try(:namespace) + + return unless namespace + + namespace.custom_emoji&.by_name(value.to_s)&.any? end end end |