diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /app/models/custom_emoji.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'app/models/custom_emoji.rb')
-rw-r--r-- | app/models/custom_emoji.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index 173b38b2c63..09fbb93525b 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -28,6 +28,19 @@ class CustomEmoji < ApplicationRecord alias_attribute :url, :file # this might need a change in https://gitlab.com/gitlab-org/gitlab/-/issues/230467 + # Find custom emoji for the given resource. + # A resource can be either a Project or a Group, or anything responding to #root_ancestor. + # Usually it's the return value of #resource_parent on any model. + scope :for_resource, -> (resource) do + return none if resource.nil? + + namespace = resource.root_ancestor + + return none if namespace.nil? || Feature.disabled?(:custom_emoji, namespace) + + namespace.custom_emoji + end + private def valid_emoji_name |