Commit 58a5c889 authored by Stan Hu's avatar Stan Hu

Merge branch '33815-add-validation-to-user-website-url' into 'master'

Validate user website_url

See merge request gitlab-org/gitlab!69624
parents 7dbcd212 f651f986
......@@ -253,6 +253,8 @@ class User < ApplicationRecord
validates :color_scheme_id, allow_nil: true, inclusion: { in: Gitlab::ColorSchemes.valid_ids,
message: _("%{placeholder} is not a valid color scheme") % { placeholder: '%{value}' } }
validates :website_url, allow_blank: true, url: true, if: :website_url_changed?
before_validation :sanitize_attrs
before_validation :reset_secondary_emails, if: :email_changed?
before_save :default_private_profile_to_false
......
......@@ -103,7 +103,7 @@
= f.text_field :skype, class: 'input-md gl-form-input', placeholder: s_("Profiles|username")
= f.text_field :linkedin, class: 'input-md gl-form-input', help: s_("Profiles|Your LinkedIn profile name from linkedin.com/in/profilename")
= f.text_field :twitter, class: 'input-md gl-form-input', placeholder: s_("Profiles|@username")
= f.text_field :website_url, class: 'input-lg gl-form-input', placeholder: s_("Profiles|website.com")
= f.text_field :website_url, class: 'input-lg gl-form-input', placeholder: s_("Profiles|https://website.com")
- if @user.read_only_attribute?(:location)
= f.text_field :location, class: 'gl-form-input', readonly: true, help: s_("Profiles|Your location was automatically set based on your %{provider_label} account") % { provider_label: attribute_provider_label(:location) }
- else
......
......@@ -25922,10 +25922,10 @@ msgstr ""
msgid "Profiles|e.g. My MacBook key"
msgstr ""
msgid "Profiles|username"
msgid "Profiles|https://website.com"
msgstr ""
msgid "Profiles|website.com"
msgid "Profiles|username"
msgstr ""
msgid "Profiles|your account"
......
......@@ -32,7 +32,7 @@ RSpec.describe 'User edit profile' do
fill_in 'user_skype', with: 'testskype'
fill_in 'user_linkedin', with: 'testlinkedin'
fill_in 'user_twitter', with: 'testtwitter'
fill_in 'user_website_url', with: 'testurl'
fill_in 'user_website_url', with: 'http://testurl.com'
fill_in 'user_location', with: 'Ukraine'
fill_in 'user_bio', with: 'I <3 GitLab :tada:'
fill_in 'user_job_title', with: 'Frontend Engineer'
......@@ -43,7 +43,7 @@ RSpec.describe 'User edit profile' do
skype: 'testskype',
linkedin: 'testlinkedin',
twitter: 'testtwitter',
website_url: 'testurl',
website_url: 'http://testurl.com',
bio: 'I <3 GitLab :tada:',
job_title: 'Frontend Engineer',
organization: 'GitLab'
......@@ -77,6 +77,17 @@ RSpec.describe 'User edit profile' do
end
end
it 'shows an error if the website url is not valid' do
fill_in 'user_website_url', with: 'admin@gitlab.com'
submit_settings
expect(user.reload).to have_attributes(
website_url: ''
)
expect(page).to have_content('Website url is not a valid URL')
end
describe 'when I change my email' do
before do
user.send_reset_password_instructions
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment