diff options
author | Michael Kozono <mkozono@gmail.com> | 2017-05-03 10:14:30 -0700 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2017-05-05 12:11:58 -0700 |
commit | 72872ee2136436e48ce394268fc8bfb8a2118810 (patch) | |
tree | b72060fed4a7458f480991de18ec5a21b9b634bd /app/models/route.rb | |
parent | a0368e91310a3b2c0e9e0b717f931a482eb0b90a (diff) | |
download | gitlab-ce-72872ee2136436e48ce394268fc8bfb8a2118810.tar.gz |
Delete conflicting redirects
Diffstat (limited to 'app/models/route.rb')
-rw-r--r-- | app/models/route.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/app/models/route.rb b/app/models/route.rb index df801714b5f..e0d85ff7db7 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -8,7 +8,8 @@ class Route < ActiveRecord::Base presence: true, uniqueness: { case_sensitive: false } - after_update :create_redirect_if_path_changed + after_save :delete_conflicting_redirects + after_update :create_redirect_for_old_path after_update :rename_direct_descendant_routes scope :inside_path, -> (path) { where('routes.path LIKE ?', "#{sanitize_sql_like(path)}/%") } @@ -34,13 +35,19 @@ class Route < ActiveRecord::Base end end - def create_redirect_if_path_changed - if path_changed? - create_redirect(path_was) - end + def delete_conflicting_redirects + conflicting_redirects.delete_all + end + + def conflicting_redirects + RedirectRoute.matching_path_and_descendants(path) + end + + def create_redirect_for_old_path + create_redirect(path_was) if path_changed? end - def create_redirect(old_path) - source.redirect_routes.create(path: old_path) + def create_redirect(path) + RedirectRoute.create(source: source, path: path) end end |