diff options
author | George Koltsov <gkoltsov@gitlab.com> | 2019-07-30 13:53:23 +0300 |
---|---|---|
committer | George Koltsov <gkoltsov@gitlab.com> | 2019-08-02 17:39:18 +0300 |
commit | 8abf920d1f55e9117dd3b05d81ee9ebf7721f2bd (patch) | |
tree | bcdc229c8b9819f0ff6f5dc99095fe40bbeff51c /app/models/hooks | |
parent | ac7661924eebd6eb0fa72848e2b4bf4391ebf113 (diff) |
Refactor SystemHookUrlValidator and specs
Simplify SystemHookUrlValidator to inherit from PublicUrlValidator
Refactor specs to move out shared examples to be used in both
system hooks and public url validators.
Diffstat (limited to 'app/models/hooks')
-rw-r--r-- | app/models/hooks/system_hook.rb | 3 | ||||
-rw-r--r-- | app/models/hooks/web_hook.rb | 4 |
2 files changed, 3 insertions, 4 deletions
diff --git a/app/models/hooks/system_hook.rb b/app/models/hooks/system_hook.rb index b83913c845f..3d54d17e787 100644 --- a/app/models/hooks/system_hook.rb +++ b/app/models/hooks/system_hook.rb @@ -14,8 +14,7 @@ class SystemHook < WebHook default_value_for :repository_update_events, true default_value_for :merge_requests_events, false - validates :url, presence: true, public_url: false, system_hook_url: { allow_localhost: lambda(&:allow_local_requests?), - allow_local_network: lambda(&:allow_local_requests?) } + validates :url, system_hook_url: true # Allow urls pointing localhost and the local network def allow_local_requests? diff --git a/app/models/hooks/web_hook.rb b/app/models/hooks/web_hook.rb index 3203bb024ab..16fc7fdbd48 100644 --- a/app/models/hooks/web_hook.rb +++ b/app/models/hooks/web_hook.rb @@ -15,8 +15,8 @@ class WebHook < ApplicationRecord has_many :web_hook_logs, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent - validates :url, presence: true, public_url: { allow_localhost: lambda(&:allow_local_requests?), - allow_local_network: lambda(&:allow_local_requests?) } + validates :url, presence: true + validates :url, public_url: true, unless: ->(hook) { hook.is_a?(SystemHook) } validates :token, format: { without: /\n/ } validates :push_events_branch_filter, branch_filter: true |