Как переопределить метод build_query в role_adapter rolify? - PullRequest
0 голосов
/ 08 января 2019

Я использую rolify gem для авторизации. Когда я создаю нового пользователя динамически через пользовательский интерфейс, моя вставка таблицы users_roles (в моем случае role_user_map) не происходит. Есть ли способ переопределить метод build_query? Пожалуйста, ведите меня с этим. Благодарю вас. ` users_controller.rb

def index
    store_list = @query_stores.split(" ").join("','")
    profile_list = @profiles.map {|role| role.role_name}.join("','")
    if params[:search_by].present?
      search_by = params[:search_by]
      if current_user.admin? || current_user.radial_readonly?
        @users = User.distinct.joins('LEFT JOIN stores_users ON dim_user.user_id = stores_users.user_id')
                     .joins('LEFT JOIN stores ON stores.id = stores_users.store_id')
                     .joins('LEFT JOIN clients_users ON dim_user.user_id = clients_users.user_id')
                     .joins('LEFT JOIN clients ON clients_users.client_id = clients.id')
                     .joins(:DIM_ROLE)
                     .where('dim_user.full_name LIKE :search OR dim_user.email LIKE :search OR DIM_ROLE.role_name LIKE :search OR clients.code LIKE :search OR stores.code LIKE :search', search: "%#{search_by}%")
      else
        @users = User.distinct.joins(:store_user_assignments)
                     .joins(:stores)
                     .where("stores.code IN ('#{store_list}')")
                     .joins('LEFT JOIN clients_users ON dim_user.user_id = clients_users.user_id')
                     .joins('LEFT JOIN clients ON clients_users.client_id = clients.id')
                     .joins(:DIM_ROLE)
                     .where("DIM_ROLE.role_name IN ('#{profile_list}')")
                     .where('dim_user.full_name LIKE :search OR dim_user.email LIKE :search OR DIM_ROLE.role_name LIKE :search OR clients.code LIKE :search OR stores.code LIKE :search', search: "%#{search_by}%")
      end
    else
      if current_user.admin? || current_user.radial_readonly?
        @users = User.distinct.joins('LEFT JOIN stores_users ON dim_user.user_id = stores_users.store_id')
      else
        @users = User.distinct.joins(:store_user_assignments).joins(:DIM_ROLE).where("DIM_ROLE.role_name IN ('#{profile_list}')").joins(:stores).where("stores.code IN ('#{store_list}')")
      end
    end

    if current_user.pmt_ptl_accnt_manager?
      @users = @users.find_all {|user| !user.admin? and current_user.client_list.include? user.client_list}
    end
    # added @users_total to get the total users count before paginate
=begin
    @users_total = @users
    @users = @users.paginate(:per_page => params[:per_page] || 5, :page => params[:page])
    @users_per_page = [{"name" => "5 per page", "id" => "5"},
                       {"name" => "10 per page", "id" => "10"},
                       {"name" => "15 per page", "id" => "15"},
                       {"name" => "20 per page", "id" => "20"}]
=end
  end

`

...