HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/openproject/app/cells/user_filter_cell.rb
class UserFilterCell < RailsCell
  include UsersHelper
  include ActionView::Helpers::FormOptionsHelper

  options :groups, :status, :roles, :clear_url, :project

  class << self
    def filter(params)
      q = base_query.new

      filter_project q, params[:project_id]
      filter_name q, params[:name]
      filter_status q, status_param(params)
      filter_group q, params[:group_id]
      filter_role q, params[:role_id]

      q.results
    end

    def filtered?(params)
      %i(name status group_id role_id).any? { |name| params[name].present? }
    end

    ##
    # Returns the selected status from the parameters
    # or the default status to be filtered by (all)
    # if no status is given.
    def status_param(params)
      params[:status].presence || 'all'
    end

    def filter_name(query, name)
      if name.present?
        query.where(:any_name_attribute, '~', name)
      end
    end

    def filter_status(query, status)
      return unless status && status != 'all'

      case status
      when 'blocked'
        query.where(:blocked, '=', :blocked)
      when 'active'
        query.where(:status, '=', status.to_sym)
        query.where(:blocked, '!', :blocked)
      else
        query.where(:status, '=', status.to_sym)
      end
    end

    def filter_group(query, group_id)
      if group_id.present?
        query.where(:group, '=', group_id)
      end
    end

    def filter_role(query, role_id)
      if role_id.present?
        query.where(:role_id, '=', role_id)
      end
    end

    def filter_project(query, project_id)
      if project_id.present?
        query.where(:project_id, '=', project_id)
      end
    end

    def base_query
      Queries::Users::UserQuery
    end
  end

  # INSTANCE METHODS:

  def filter_path
    users_path
  end

  def initially_visible?
    true
  end

  def has_close_icon?
    false
  end

  def params
    model
  end

  def user_status_options
    users_status_options_for_select status, extra: extra_user_status_options
  end

  def extra_user_status_options
    {}
  end
end