Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-01-18 22:16:54 +0300
committerRobert Speicher <rspeicher@gmail.com>2018-01-22 22:35:20 +0300
commit76720afd1f03f5cde28091dca82e7108cce22178 (patch)
treed4a277c47b206c0d5a893b92641db08207e1f0d8 /app
parent241cc25e997c08d049efd64f73c19be8ab331fbe (diff)
Merge branch 'mk-delete-orphaned-routes-before-validation' into 'master'
Delete conflicting orphaned routes before validation Closes #39551 See merge request gitlab-org/gitlab-ce!16242
Diffstat (limited to 'app')
-rw-r--r--app/models/route.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/route.rb b/app/models/route.rb
index 412f5fb45a5..3d4b5a8b5ee 100644
--- a/app/models/route.rb
+++ b/app/models/route.rb
@@ -1,4 +1,6 @@
class Route < ActiveRecord::Base
+ include CaseSensitivity
+
belongs_to :source, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
validates :source, presence: true
@@ -10,6 +12,7 @@ class Route < ActiveRecord::Base
validate :ensure_permanent_paths, if: :path_changed?
+ before_validation :delete_conflicting_orphaned_routes
after_create :delete_conflicting_redirects
after_update :delete_conflicting_redirects, if: :path_changed?
after_update :create_redirect_for_old_path
@@ -78,4 +81,13 @@ class Route < ActiveRecord::Base
def conflicting_redirect_exists?
RedirectRoute.permanent.matching_path_and_descendants(path).exists?
end
+
+ def delete_conflicting_orphaned_routes
+ conflicting = self.class.iwhere(path: path)
+ conflicting_orphaned_routes = conflicting.select do |route|
+ route.source.nil?
+ end
+
+ conflicting_orphaned_routes.each(&:destroy)
+ end
end