diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-03-05 13:02:36 +0100 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-03-28 14:12:08 +0200 |
commit | ce69419a60a04b78616e7fe7d26ed7ed936e7c62 (patch) | |
tree | cc210e78443643944e46ba11511f8254c9016d22 /app/models/route.rb | |
parent | 7ea08566f36d97e1cf2b31767ebb122883f4f30e (diff) | |
download | gitlab-ce-ce69419a60a04b78616e7fe7d26ed7ed936e7c62.tar.gz |
Remove permanent redirects
Removes permanent redirects, this means that redirects will only be
possible as long as the old route isn't taken by a new project/group.
Diffstat (limited to 'app/models/route.rb')
-rw-r--r-- | app/models/route.rb | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/app/models/route.rb b/app/models/route.rb index 07d96c21cf1..2d609920051 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -10,8 +10,6 @@ class Route < ActiveRecord::Base presence: true, uniqueness: { case_sensitive: false } - 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? @@ -45,7 +43,7 @@ class Route < ActiveRecord::Base # We are not calling route.delete_conflicting_redirects here, in hopes # of avoiding deadlocks. The parent (self, in this method) already # called it, which deletes conflicts for all descendants. - route.create_redirect(old_path, permanent: permanent_redirect?) if attributes[:path] + route.create_redirect(old_path) if attributes[:path] end end end @@ -55,31 +53,17 @@ class Route < ActiveRecord::Base end def conflicting_redirects - RedirectRoute.temporary.matching_path_and_descendants(path) + RedirectRoute.matching_path_and_descendants(path) end - def create_redirect(path, permanent: false) - RedirectRoute.create(source: source, path: path, permanent: permanent) + def create_redirect(path) + RedirectRoute.create(source: source, path: path) end private def create_redirect_for_old_path - create_redirect(path_was, permanent: permanent_redirect?) if path_changed? - end - - def permanent_redirect? - source_type != "Project" - end - - def ensure_permanent_paths - return if path.nil? - - errors.add(:path, "has been taken before") if conflicting_redirect_exists? - end - - def conflicting_redirect_exists? - RedirectRoute.permanent.matching_path_and_descendants(path).exists? + create_redirect(path_was) if path_changed? end def delete_conflicting_orphaned_routes |