diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-03 21:08:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-03 21:08:55 +0300 |
commit | 8f9307985ea047abb5b8a7c6c56bb644e0b7c363 (patch) | |
tree | 474c91c280b903c345bd94f4842abf481c535656 /app/models | |
parent | 3cda3d43aef1e92e2eedf7383122c6db9c61149f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 1 | ||||
-rw-r--r-- | app/models/user_detail.rb | 19 | ||||
-rw-r--r-- | app/models/wiki_directory.rb | 2 | ||||
-rw-r--r-- | app/models/wiki_page.rb | 2 |
4 files changed, 17 insertions, 7 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 535f1bd874a..6151ba54555 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -380,6 +380,7 @@ class User < ApplicationRecord delegate :website_url, :website_url=, to: :user_detail, allow_nil: true delegate :location, :location=, to: :user_detail, allow_nil: true delegate :organization, :organization=, to: :user_detail, allow_nil: true + delegate :discord, :discord=, to: :user_detail, allow_nil: true accepts_nested_attributes_for :user_preference, update_only: true accepts_nested_attributes_for :user_detail, update_only: true 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') diff --git a/app/models/wiki_directory.rb b/app/models/wiki_directory.rb index f5d00013622..76fe664f23d 100644 --- a/app/models/wiki_directory.rb +++ b/app/models/wiki_directory.rb @@ -49,6 +49,6 @@ class WikiDirectory # Relative path to the partial to be used when rendering collections # of this object. def to_partial_path - '../shared/wikis/wiki_directory' + 'shared/wikis/wiki_directory' end end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 24b0b94eeb7..b04aa196883 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -259,7 +259,7 @@ class WikiPage # Relative path to the partial to be used when rendering collections # of this object. def to_partial_path - '../shared/wikis/wiki_page' + 'shared/wikis/wiki_page' end def sha |