app/queries/decidim/admin/user_groups_evaluation.rb in decidim-admin-0.8.4 vs app/queries/decidim/admin/user_groups_evaluation.rb in decidim-admin-0.9.0

- old
+ new

@@ -1,41 +1,42 @@ # frozen_string_literal: true module Decidim module Admin - # A class used to find the ParticipatoryProcesses that the given user can - # manage. + # A class used to find the UserGroup's by their evaluation state. class UserGroupsEvaluation < Rectify::Query # Syntactic sugar to initialize the class and return the queried objects. # - # user - a User Group that needs to be listed. + # user_groups - the initial User Group relation that needs to be filtered. + # q - query to filter user group names + # state - evaluation state to be used as a filter def self.for(user_groups, q = nil, state = nil) new(user_groups, q, state).query end # Initializes the class. # - # user_group - a User groups that need to be lsited + # user_groups - the User groups that need to be filtered + # q - query to filter user group names + # state - evaluation state to be used as a filter def initialize(user_groups, q = nil, state = nil) @user_groups = user_groups @q = q @state = state end - # List the User groups by the diferents filters. + # List the User groups by the diferent filters. def query @user_groups = filter_by_search(@user_groups) @user_groups = filter_by_state(@user_groups) @user_groups end private - attr_reader :user_group - def filter_by_search(user_groups) return user_groups if @q.blank? - user_groups.where("LOWER(name) LIKE LOWER('%#{@q}%')") + user_groups.where("LOWER(name) LIKE LOWER(?)", "%#{@q}%") end def filter_by_state(user_groups) case @state when "verified"