diff options
author | Fatih Acet <acetfatih@gmail.com> | 2016-07-14 14:50:34 +0000 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-07-14 14:50:34 +0000 |
commit | c49517a0048f24e57f6d6ab2a5e80c8de132280d (patch) | |
tree | b984c5f604b65cbf3c7424b16944eac63c0b85ed /app/models | |
parent | 005ce32f7ca8743465f797f43eb47e1745a006e9 (diff) | |
parent | 001c9aa3137e6648fe3994eca4237f9283d0ee6e (diff) | |
download | gitlab-ce-c49517a0048f24e57f6d6ab2a5e80c8de132280d.tar.gz |
Merge branch 'fix/persistent-import-data' into 'master'
Fix import_data being saved as a result of an invalid import_url
Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/19479
Seem that in all cases the `import_url` was an empty string. The `import_url` is now validated correctly and no longer creates the `import_data`even if it fails validation. <= Should cover cases 1, 3, and 4 of https://gitlab.com/gitlab-org/gitlab-ce/issues/19479#note_13005276
Also, it now rescues from all exceptions when importing from a URL, so we make sure the `import_status` is failed after that. Covers case 2 of https://gitlab.com/gitlab-org/gitlab-ce/issues/19479#note_13005276
See merge request !5206
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index a66b750cd48..e7b9835692d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -162,7 +162,7 @@ class Project < ActiveRecord::Base validates :namespace, presence: true validates_uniqueness_of :name, scope: :namespace_id validates_uniqueness_of :path, scope: :namespace_id - validates :import_url, addressable_url: true, if: :external_import? + validates :import_url, addressable_url: true, if: :import_url validates :star_count, numericality: { greater_than_or_equal_to: 0 } validate :check_limit, on: :create validate :avatar_type, @@ -464,8 +464,8 @@ class Project < ActiveRecord::Base return super(value) unless Gitlab::UrlSanitizer.valid?(value) import_url = Gitlab::UrlSanitizer.new(value) - create_or_update_import_data(credentials: import_url.credentials) super(import_url.sanitized_url) + create_or_update_import_data(credentials: import_url.credentials) end def import_url @@ -477,7 +477,13 @@ class Project < ActiveRecord::Base end end + def valid_import_url? + valid? || errors.messages[:import_url].nil? + end + def create_or_update_import_data(data: nil, credentials: nil) + return unless valid_import_url? + project_import_data = import_data || build_import_data if data project_import_data.data ||= {} |