summaryrefslogtreecommitdiff
path: root/app/models/redirect_route.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/redirect_route.rb')
-rw-r--r--app/models/redirect_route.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/models/redirect_route.rb b/app/models/redirect_route.rb
new file mode 100644
index 00000000000..31de204d824
--- /dev/null
+++ b/app/models/redirect_route.rb
@@ -0,0 +1,20 @@
+class RedirectRoute < ActiveRecord::Base
+ belongs_to :source, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
+
+ validates :source, presence: true
+
+ validates :path,
+ length: { within: 1..255 },
+ presence: true,
+ uniqueness: { case_sensitive: false }
+
+ scope :matching_path_and_descendants, -> (path) do
+ wheres = if Gitlab::Database.postgresql?
+ 'LOWER(redirect_routes.path) = LOWER(?) OR LOWER(redirect_routes.path) LIKE LOWER(?)'
+ else
+ 'redirect_routes.path = ? OR redirect_routes.path LIKE ?'
+ end
+
+ where(wheres, path, "#{sanitize_sql_like(path)}/%")
+ end
+end