diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2017-12-06 18:22:29 -0600 |
---|---|---|
committer | Mayra Cabrera <mcabrera@gitlab.com> | 2017-12-07 08:14:47 -0600 |
commit | 8a1a257b94127e7b205d1faa5fddb4aed71d057d (patch) | |
tree | 5551a5edb78752fca8aab3c870fc0b5ff2424e20 | |
parent | 6a0d92611d5842fd5798c0d0268b724c73c8f625 (diff) | |
download | gitlab-ce-8a1a257b94127e7b205d1faa5fddb4aed71d057d.tar.gz |
Ensures validations are only executed if RedirectRoute#permanent column exists
-rw-r--r-- | app/models/namespace.rb | 2 | ||||
-rw-r--r-- | app/models/route.rb | 18 |
2 files changed, 18 insertions, 2 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 0ff169d4531..03089dcefa5 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -266,6 +266,8 @@ class Namespace < ActiveRecord::Base end def namespace_previously_created_with_same_path? + return false unless RedirectRoute.column_names.include? "permanent" + RedirectRoute.permanent.exists?(path: path) end end diff --git a/app/models/route.rb b/app/models/route.rb index 88d09a329e1..c293f58b623 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -52,11 +52,19 @@ class Route < ActiveRecord::Base end def conflicting_redirects - RedirectRoute.temporary.matching_path_and_descendants(path) + if permanent_column_exists? + RedirectRoute.temporary.matching_path_and_descendants(path) + else + RedirectRoute.matching_path_and_descendants(path) + end end def create_redirect(path, permanent) - RedirectRoute.create(source: source, path: path, permanent: permanent) + if permanent_column_exists? + RedirectRoute.create(source: source, path: path, permanent: permanent) + else + RedirectRoute.create(source: source, path: path) + end end private @@ -76,6 +84,12 @@ class Route < ActiveRecord::Base end def conflicting_redirect_exists? + return false unless permanent_column_exists? + RedirectRoute.permanent.exists?(path: path) end + + def permanent_column_exists? + RedirectRoute.column_names.include? "permanent" + end end |