Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Greenlight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arbeitsgruppe Hardwarenahe IT-Systeme
Greenlight
Commits
6be629ae
Unverified
Commit
6be629ae
authored
4 years ago
by
Ahmad Farhat
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Make all LIKE queries case insensitive (#2402)
parent
752b192e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/models/concerns/queries.rb
+41
-0
41 additions, 0 deletions
app/models/concerns/queries.rb
app/models/room.rb
+19
-22
19 additions, 22 deletions
app/models/room.rb
app/models/user.rb
+29
-30
29 additions, 30 deletions
app/models/user.rb
with
89 additions
and
52 deletions
app/models/concerns/queries.rb
0 → 100644
+
41
−
0
View file @
6be629ae
# frozen_string_literal: true
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
module
Queries
extend
ActiveSupport
::
Concern
def
created_at_text
active_database
=
Rails
.
configuration
.
database_configuration
[
Rails
.
env
][
"adapter"
]
# Postgres requires created_at to be cast to a string
if
active_database
==
"postgresql"
"created_at::text"
else
"created_at"
end
end
def
like_text
active_database
=
Rails
.
configuration
.
database_configuration
[
Rails
.
env
][
"adapter"
]
# Use postgres case insensitive like
if
active_database
==
"postgresql"
"ILIKE"
else
"LIKE"
end
end
end
This diff is collapsed.
Click to expand it.
app/models/room.rb
+
19
−
22
View file @
6be629ae
...
@@ -32,23 +32,19 @@ class Room < ApplicationRecord
...
@@ -32,23 +32,19 @@ class Room < ApplicationRecord
has_one_attached
:presentation
has_one_attached
:presentation
def
self
.
admins_search
(
string
)
class
<<
self
active_database
=
Rails
.
configuration
.
database_configuration
[
Rails
.
env
][
"adapter"
]
include
Queries
# Postgres requires created_at to be cast to a string
created_at_query
=
if
active_database
==
"postgresql"
"created_at::text"
else
"created_at"
end
search_query
=
"rooms.name LIKE :search OR rooms.uid LIKE :search OR users.email LIKE :search"
\
def
admins_search
(
string
)
" OR users.
#{
created_at_query
}
LIKE :search"
like
=
like_text
search_query
=
"rooms.name
#{
like
}
:search OR rooms.uid
#{
like
}
:search OR users.email
#{
like
}
:search"
\
" OR users.
#{
created_at_text
}
#{
like
}
:search"
search_param
=
"%
#{
sanitize_sql_like
(
string
)
}
%"
search_param
=
"%
#{
sanitize_sql_like
(
string
)
}
%"
where
(
search_query
,
search:
search_param
)
where
(
search_query
,
search:
search_param
)
end
end
def
self
.
admins_order
(
column
,
direction
,
running_ids
)
def
admins_order
(
column
,
direction
,
running_ids
)
# Include the owner of the table
# Include the owner of the table
table
=
joins
(
:owner
)
table
=
joins
(
:owner
)
...
@@ -63,6 +59,7 @@ class Room < ApplicationRecord
...
@@ -63,6 +59,7 @@ class Room < ApplicationRecord
table
table
end
end
end
# Determines if a user owns a room.
# Determines if a user owns a room.
def
owned_by?
(
user
)
def
owned_by?
(
user
)
...
...
This diff is collapsed.
Click to expand it.
app/models/user.rb
+
29
−
30
View file @
6be629ae
...
@@ -54,6 +54,7 @@ class User < ApplicationRecord
...
@@ -54,6 +54,7 @@ class User < ApplicationRecord
class
<<
self
class
<<
self
include
AuthValues
include
AuthValues
include
Queries
# Generates a user from omniauth.
# Generates a user from omniauth.
def
from_omniauth
(
auth
)
def
from_omniauth
(
auth
)
...
@@ -69,49 +70,47 @@ class User < ApplicationRecord
...
@@ -69,49 +70,47 @@ class User < ApplicationRecord
u
.
save!
u
.
save!
end
end
end
end
end
def
self
.
admins_search
(
string
)
def
admins_search
(
string
)
return
all
if
string
.
blank?
return
all
if
string
.
blank?
active_database
=
Rails
.
configuration
.
database_configuration
[
Rails
.
env
][
"adapter"
]
like
=
like_text
# Get the correct like clause to use based on db adapter
# Postgres requires created_at to be cast to a string
created_at_query
=
if
active_database
==
"postgresql"
"created_at::text"
else
"created_at"
end
search_query
=
"users.name
LIKE
:search OR email
LIKE
:search OR username
LIKE
:search"
\
search_query
=
"users.name
#{
like
}
:search OR email
#{
like
}
:search OR username
#{
like
}
:search"
\
" OR users.
#{
created_at_
query
}
LIKE
:search OR users.provider
LIKE
:search"
\
" OR users.
#{
created_at_
text
}
#{
like
}
:search OR users.provider
#{
like
}
:search"
\
" OR roles.name
LIKE
:search"
" OR roles.name
#{
like
}
:search"
search_param
=
"%
#{
sanitize_sql_like
(
string
)
}
%"
search_param
=
"%
#{
sanitize_sql_like
(
string
)
}
%"
where
(
search_query
,
search:
search_param
)
where
(
search_query
,
search:
search_param
)
end
end
def
self
.
admins_order
(
column
,
direction
)
def
admins_order
(
column
,
direction
)
# Arel.sql to avoid sql injection
# Arel.sql to avoid sql injection
order
(
Arel
.
sql
(
"users.
#{
column
}
#{
direction
}
"
))
order
(
Arel
.
sql
(
"users.
#{
column
}
#{
direction
}
"
))
end
end
def
self
.
shared_list_search
(
string
)
def
shared_list_search
(
string
)
return
all
if
string
.
blank?
return
all
if
string
.
blank?
search_query
=
"users.name LIKE :search OR users.uid LIKE :search"
like
=
like_text
# Get the correct like clause to use based on db adapter
search_query
=
"users.name
#{
like
}
:search OR users.uid
#{
like
}
:search"
search_param
=
"%
#{
sanitize_sql_like
(
string
)
}
%"
search_param
=
"%
#{
sanitize_sql_like
(
string
)
}
%"
where
(
search_query
,
search:
search_param
)
where
(
search_query
,
search:
search_param
)
end
end
def
self
.
merge_list_search
(
string
)
def
merge_list_search
(
string
)
return
all
if
string
.
blank?
return
all
if
string
.
blank?
search_query
=
"users.name LIKE :search OR users.email LIKE :search"
like
=
like_text
# Get the correct like clause to use based on db adapter
search_query
=
"users.name
#{
like
}
:search OR users.email
#{
like
}
:search"
search_param
=
"%
#{
sanitize_sql_like
(
string
)
}
%"
search_param
=
"%
#{
sanitize_sql_like
(
string
)
}
%"
where
(
search_query
,
search:
search_param
)
where
(
search_query
,
search:
search_param
)
end
end
end
# Returns a list of rooms ordered by last session (with nil rooms last)
# Returns a list of rooms ordered by last session (with nil rooms last)
def
ordered_rooms
def
ordered_rooms
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment