Sha256: eeac11056b6d8cf7017397cbee527c99bb75c941f85c7e0f4ab728f3ec7f0086

Contents?: true

Size: 1.43 KB

Versions: 50

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A class used to find the ParticipatoryProcesses that the given user can
    # manage.
    class UserGroupsEvaluation < Rectify::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # user - a User Group that needs to be listed.
      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
      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.
      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}%')")
      end

      def filter_by_state(user_groups)
        case @state
        when "verified"
          user_groups.where.not(verified_at: nil)
        when "rejected"
          user_groups.where.not(rejected_at: nil)
        when "pending"
          user_groups.where(verified_at: nil, rejected_at: nil)
        else
          user_groups
        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 2 rubygems

Version Path
decidim-admin-0.8.4 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.8.3 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.8.2 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.8.1 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.8.0 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.7.4 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.7.3 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.7.2 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.7.1 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.7.0 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.6.8 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-0.6.8 decidim-admin/app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.6.7 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-0.6.7 decidim-admin/app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.6.6 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-0.6.6 decidim-admin/app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.6.5 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-0.6.5 decidim-admin/app/queries/decidim/admin/user_groups_evaluation.rb
decidim-admin-0.6.4 app/queries/decidim/admin/user_groups_evaluation.rb
decidim-0.6.4 decidim-admin/app/queries/decidim/admin/user_groups_evaluation.rb