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/user_detail.rb')
-rw-r--r--app/models/user_detail.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/app/models/user_detail.rb b/app/models/user_detail.rb
index b6765cb0285..9d3df3d6400 100644
--- a/app/models/user_detail.rb
+++ b/app/models/user_detail.rb
@@ -14,11 +14,13 @@ class UserDetail < ApplicationRecord
DEFAULT_FIELD_LENGTH = 500
+ validates :discord, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
+ validate :discord_format
validates :linkedin, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
- validates :twitter, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
- validates :skype, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
validates :location, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
validates :organization, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
+ validates :skype, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
+ validates :twitter, length: { maximum: DEFAULT_FIELD_LENGTH }, allow_blank: true
validates :website_url, length: { maximum: DEFAULT_FIELD_LENGTH }, url: true, allow_blank: true, if: :website_url_changed?
before_validation :sanitize_attrs
@@ -27,7 +29,7 @@ class UserDetail < ApplicationRecord
enum registration_objective: REGISTRATION_OBJECTIVE_PAIRS, _suffix: true
def sanitize_attrs
- %i[linkedin skype twitter website_url].each do |attr|
+ %i[discord linkedin skype twitter website_url].each do |attr|
value = self[attr]
self[attr] = Sanitize.clean(value) if value.present?
end
@@ -41,13 +43,20 @@ class UserDetail < ApplicationRecord
def prevent_nil_fields
self.bio = '' if bio.nil?
+ self.discord = '' if discord.nil?
self.linkedin = '' if linkedin.nil?
- self.twitter = '' if twitter.nil?
- self.skype = '' if skype.nil?
self.location = '' if location.nil?
self.organization = '' if organization.nil?
+ self.skype = '' if skype.nil?
+ self.twitter = '' if twitter.nil?
self.website_url = '' if website_url.nil?
end
end
+def discord_format
+ return if discord.blank? || discord =~ %r{\A\d{17,20}\z}
+
+ errors.add(:discord, _('must contain only a discord user ID.'))
+end
+
UserDetail.prepend_mod_with('UserDetail')