app/queries/decidim/admin/users_officialization.rb in decidim-admin-0.9.3 vs app/queries/decidim/admin/users_officialization.rb in decidim-admin-0.10.0
- old
+ new
@@ -4,39 +4,42 @@
module Admin
# A class used to filter User's by their officialization state.
class UsersOfficialization < Rectify::Query
# Syntactic sugar to initialize the class and return the queried objects.
#
- # q - query to filter user group names
+ # organization - the Decidim::Organization where search will be scoped to
+ # name_query - query to filter user group names
# state - evaluation state to be used as a filter
- def self.for(q = nil, state = nil)
- new(q, state).query
+ def self.for(organization, name_query = nil, state = nil)
+ new(organization, name_query, state).query
end
# Initializes the class.
#
- # q - query to filter user group names
+ # organization - the Decidim::Organization where search will be scoped to
+ # name_query - query to filter user group names
# state - officialization state to be used as a filter
- def initialize(q = nil, state = nil)
- @q = q
+ def initialize(organization, name_query = nil, state = nil)
+ @organization = organization
+ @name_query = name_query
@state = state
end
# List the User groups by the diferents filters.
def query
- users = Decidim::User.all
+ users = Decidim::User.where(organization: organization)
users = filter_by_search(users)
users = filter_by_state(users)
users
end
private
- attr_reader :q, :state
+ attr_reader :name_query, :state, :organization
def filter_by_search(users)
- return users if q.blank?
- users.where("LOWER(name) LIKE LOWER(?)", "%#{q}%")
+ return users if name_query.blank?
+ users.where("LOWER(name) LIKE LOWER(?)", "%#{name_query}%")
end
def filter_by_state(users)
case state
when "officialized"