summaryrefslogtreecommitdiff
path: root/app/models/group.rb
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-03-16 20:16:42 -0300
committerFelipe Artur <felipefac@gmail.com>2016-03-16 20:16:42 -0300
commit44c127447b5a3cfc7aaea6f19e18baf9f42ad500 (patch)
treef386dbb06fec8c5fdec92812394ac63cf67183a0 /app/models/group.rb
parentec20fdf366843e60ed30abb5322c3c1b8f471b4a (diff)
parent59064aeeef8562a87d4d03efa9b11012a007e261 (diff)
downloadgitlab-ce-44c127447b5a3cfc7aaea6f19e18baf9f42ad500.tar.gz
Merge 4009-external-users into issue_12658
Diffstat (limited to 'app/models/group.rb')
-rw-r--r--app/models/group.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/app/models/group.rb b/app/models/group.rb
index 02b9a968dcd..b094a65e3d6 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -25,6 +25,8 @@ class Group < Namespace
has_many :group_members, dependent: :destroy, as: :source, class_name: 'GroupMember'
alias_method :members, :group_members
has_many :users, through: :group_members
+ has_many :project_group_links, dependent: :destroy
+ has_many :shared_projects, through: :project_group_links, source: :project
validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? }
validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
@@ -35,8 +37,18 @@ class Group < Namespace
after_destroy :post_destroy_hook
class << self
+ # Searches for groups matching the given query.
+ #
+ # This method uses ILIKE on PostgreSQL and LIKE on MySQL.
+ #
+ # query - The search query as a String
+ #
+ # Returns an ActiveRecord::Relation.
def search(query)
- where("LOWER(namespaces.name) LIKE :query or LOWER(namespaces.path) LIKE :query", query: "%#{query.downcase}%")
+ table = Namespace.arel_table
+ pattern = "%#{query}%"
+
+ where(table[:name].matches(pattern).or(table[:path].matches(pattern)))
end
def sort(method)