Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
d5ea9346
Commit
d5ea9346
authored
Dec 01, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom UrlValidator
parent
2928e19d
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
79 additions
and
37 deletions
+79
-37
app/models/application_setting.rb
app/models/application_setting.rb
+2
-2
app/models/ci/web_hook.rb
app/models/ci/web_hook.rb
+1
-2
app/models/hooks/web_hook.rb
app/models/hooks/web_hook.rb
+1
-2
app/models/project.rb
app/models/project.rb
+1
-1
app/models/project_services/bamboo_service.rb
app/models/project_services/bamboo_service.rb
+2
-5
app/models/project_services/drone_ci_service.rb
app/models/project_services/drone_ci_service.rb
+13
-16
app/models/project_services/external_wiki_service.rb
app/models/project_services/external_wiki_service.rb
+2
-4
app/models/project_services/teamcity_service.rb
app/models/project_services/teamcity_service.rb
+5
-5
app/validators/url_validator.rb
app/validators/url_validator.rb
+36
-0
spec/models/application_setting_spec.rb
spec/models/application_setting_spec.rb
+16
-0
No files found.
app/models/application_setting.rb
View file @
d5ea9346
...
...
@@ -43,12 +43,12 @@ class ApplicationSetting < ActiveRecord::Base
validates
:home_page_url
,
allow_blank:
true
,
format:
{
with:
/\A
#{
URI
.
regexp
(
%w(http https)
)
}
\z/
,
message:
"should be a valid url"
}
,
url:
true
,
if: :home_page_url_column_exist
validates
:after_sign_out_path
,
allow_blank:
true
,
format:
{
with:
/\A
#{
URI
.
regexp
(
%w(http https)
)
}
\z/
,
message:
"should be a valid url"
}
url:
true
validates
:admin_notification_email
,
allow_blank:
true
,
...
...
app/models/ci/web_hook.rb
View file @
d5ea9346
...
...
@@ -20,8 +20,7 @@ module Ci
# HTTParty timeout
default_timeout
10
validates
:url
,
presence:
true
,
format:
{
with:
URI
::
regexp
(
%w(http https)
),
message:
"should be a valid url"
}
validates
:url
,
presence:
true
,
url:
true
def
execute
(
data
)
parsed_url
=
URI
.
parse
(
url
)
...
...
app/models/hooks/web_hook.rb
View file @
d5ea9346
...
...
@@ -31,8 +31,7 @@ class WebHook < ActiveRecord::Base
# HTTParty timeout
default_timeout
Gitlab
.
config
.
gitlab
.
webhook_timeout
validates
:url
,
presence:
true
,
format:
{
with:
/\A
#{
URI
.
regexp
(
%w(http https)
)
}
\z/
,
message:
"should be a valid url"
}
validates
:url
,
presence:
true
,
url:
true
def
execute
(
data
,
hook_name
)
parsed_url
=
URI
.
parse
(
url
)
...
...
app/models/project.rb
View file @
d5ea9346
...
...
@@ -152,7 +152,7 @@ class Project < ActiveRecord::Base
validates_uniqueness_of
:name
,
scope: :namespace_id
validates_uniqueness_of
:path
,
scope: :namespace_id
validates
:import_url
,
format:
{
with:
/\A
#{
URI
.
regexp
(
%w(ssh git http https)
)
}
\z/
,
message:
'should be a valid url'
},
url:
{
protocols:
%w(ssh git http https)
},
if: :external_import?
validates
:star_count
,
numericality:
{
greater_than_or_equal_to:
0
}
validate
:check_limit
,
on: :create
...
...
app/models/project_services/bamboo_service.rb
View file @
d5ea9346
...
...
@@ -23,10 +23,7 @@ class BambooService < CiService
prop_accessor
:bamboo_url
,
:build_key
,
:username
,
:password
validates
:bamboo_url
,
presence:
true
,
format:
{
with:
/\A
#{
URI
.
regexp
}
\z/
},
if: :activated?
validates
:bamboo_url
,
presence:
true
,
url:
true
,
if: :activated?
validates
:build_key
,
presence:
true
,
if: :activated?
validates
:username
,
presence:
true
,
...
...
app/models/project_services/drone_ci_service.rb
View file @
d5ea9346
...
...
@@ -21,12 +21,9 @@
class
DroneCiService
<
CiService
prop_accessor
:drone_url
,
:token
,
:enable_ssl_verification
validates
:drone_url
,
presence:
true
,
format:
{
with:
/\A
#{
URI
.
regexp
(
%w(http https)
)
}
\z/
,
message:
"should be a valid url"
},
if: :activated?
validates
:token
,
presence:
true
,
if: :activated?
validates
:drone_url
,
presence:
true
,
url:
true
,
if: :activated?
validates
:token
,
presence:
true
,
if: :activated?
after_save
:compose_service_hook
,
if: :activated?
...
...
app/models/project_services/external_wiki_service.rb
View file @
d5ea9346
...
...
@@ -22,10 +22,8 @@ class ExternalWikiService < Service
include
HTTParty
prop_accessor
:external_wiki_url
validates
:external_wiki_url
,
presence:
true
,
format:
{
with:
/\A
#{
URI
.
regexp
}
\z/
},
if: :activated?
validates
:external_wiki_url
,
presence:
true
,
url:
true
,
if: :activated?
def
title
'External Wiki'
...
...
app/models/project_services/teamcity_service.rb
View file @
d5ea9346
...
...
@@ -23,16 +23,16 @@ class TeamcityService < CiService
prop_accessor
:teamcity_url
,
:build_type
,
:username
,
:password
validates
:teamcity_url
,
presence:
true
,
format:
{
with:
/\A
#{
URI
.
regexp
}
\z/
},
if: :activated?
validates
:teamcity_url
,
presence:
true
,
url:
true
,
if: :activated?
validates
:build_type
,
presence:
true
,
if: :activated?
validates
:username
,
presence:
true
,
if:
->
(
service
)
{
service
.
password?
},
if: :activated?
if:
->
(
service
)
{
service
.
password?
},
if: :activated?
validates
:password
,
presence:
true
,
if:
->
(
service
)
{
service
.
username?
},
if: :activated?
if:
->
(
service
)
{
service
.
username?
},
if: :activated?
attr_accessor
:response
...
...
app/validators/url_validator.rb
0 → 100644
View file @
d5ea9346
# UrlValidator
#
# Custom validator for URLs.
#
# By default, only URLs for the HTTP(S) protocols will be considered valid.
# Provide a `:protocols` option to configure accepted protocols.
#
# Example:
#
# class User < ActiveRecord::Base
# validates :personal_url, url: true
#
# validates :ftp_url, url: { protocols: %w(ftp) }
#
# validates :git_url, url: { protocols: %w(http https ssh git) }
# end
#
class
UrlValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
unless
valid_url?
(
value
)
record
.
errors
.
add
(
attribute
,
"must be a valid URL"
)
end
end
private
def
default_options
@default_options
||=
{
protocols:
%w(http https)
}
end
def
valid_url?
(
value
)
options
=
default_options
.
merge
(
self
.
options
)
value
=~
/\A
#{
URI
.
regexp
(
options
[
:protocols
])
}
\z/
end
end
spec/models/application_setting_spec.rb
View file @
d5ea9346
...
...
@@ -36,6 +36,22 @@ describe ApplicationSetting, models: true do
it
{
expect
(
setting
).
to
be_valid
}
describe
'validations'
do
let
(
:http
)
{
'http://example.com'
}
let
(
:https
)
{
'https://example.com'
}
let
(
:ftp
)
{
'ftp://example.com'
}
it
{
is_expected
.
to
allow_value
(
nil
).
for
(
:home_page_url
)
}
it
{
is_expected
.
to
allow_value
(
http
).
for
(
:home_page_url
)
}
it
{
is_expected
.
to
allow_value
(
https
).
for
(
:home_page_url
)
}
it
{
is_expected
.
not_to
allow_value
(
ftp
).
for
(
:home_page_url
)
}
it
{
is_expected
.
to
allow_value
(
nil
).
for
(
:after_sign_out_path
)
}
it
{
is_expected
.
to
allow_value
(
http
).
for
(
:after_sign_out_path
)
}
it
{
is_expected
.
to
allow_value
(
https
).
for
(
:after_sign_out_path
)
}
it
{
is_expected
.
not_to
allow_value
(
ftp
).
for
(
:after_sign_out_path
)
}
end
context
'restricted signup domains'
do
it
'set single domain'
do
setting
.
restricted_signup_domains_raw
=
'example.com'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment