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/models/custom_emoji.rb')
-rw-r--r--app/models/custom_emoji.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb
index 4f8f86965d7..f4c914c6a3a 100644
--- a/app/models/custom_emoji.rb
+++ b/app/models/custom_emoji.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true
class CustomEmoji < ApplicationRecord
+ NAME_REGEXP = /[a-z0-9_-]+/.freeze
+
belongs_to :namespace, inverse_of: :custom_emoji
belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'namespace_id'
@@ -17,7 +19,12 @@ class CustomEmoji < ApplicationRecord
uniqueness: { scope: [:namespace_id, :name] },
presence: true,
length: { maximum: 36 },
- format: { with: /\A[a-z0-9][a-z0-9\-_]*[a-z0-9]\z/ }
+
+ format: { with: /\A#{NAME_REGEXP}\z/ }
+
+ scope :by_name, -> (names) { where(name: names) }
+
+ alias_attribute :url, :file # this might need a change in https://gitlab.com/gitlab-org/gitlab/-/issues/230467
private