Sha256: 8f78f92bfbb7ff83615ee1a1b375a4f2bcbf5eb2d4511c9c2b9544a7071da275

Contents?: true

Size: 1.58 KB

Versions: 39

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # 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_groups - the initial User Group relation that needs to be filtered.
      # query - query to filter user group names
      # state - evaluation state to be used as a filter
      def self.for(user_groups, query = nil, state = nil)
        new(user_groups, query, state).query
      end

      # Initializes the class.
      #
      # user_groups - the User groups that need to be filtered
      # query - query to filter user group names
      # state - evaluation state to be used as a filter
      def initialize(user_groups, query = nil, state = nil)
        @user_groups = user_groups
        @query = query
        @state = state
      end

      # 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

      def filter_by_search(user_groups)
        return user_groups if @query.blank?

        user_groups.where("LOWER(name) LIKE LOWER(?)", "%#{@query}%")
      end

      def filter_by_state(user_groups)
        case @state
        when "verified"
          user_groups.verified
        when "rejected"
          user_groups.rejected
        when "pending"
          user_groups.pending
        else
          user_groups
        end
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.9 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.8 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.7 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.5 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.4 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.3 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.2 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.1 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.0 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.0.rc2 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.26.0.rc1 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.25.2 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.25.1 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.25.0 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.25.0.rc4 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.25.0.rc3 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.25.0.rc2 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.25.0.rc1 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.24.3 app/queries/decidim/admin/user_groups_evaluation.rb