Class: Editor::UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/editor/users_controller.rb

Overview

This controller manage User model for editors

Instance Method Summary collapse

Instance Method Details

#filter_paramsObject (private)

Filter params for search a Fact


42
43
44
# File 'app/controllers/editor/users_controller.rb', line 42

def filter_params
  params.fetch(:filter, {}).permit(:text, :admin, :editor)
end

#indexObject

GET /editor/users


7
# File 'app/controllers/editor/users_controller.rb', line 7

def index; end

#listObject

GET /editor/users/list


10
11
12
13
14
15
16
# File 'app/controllers/editor/users_controller.rb', line 10

def list
  options = {}
  options[:admin] = true if filter_params[:admin].present?
  options[:editor] = true if filter_params[:editor].present?
  @text = ['username ilike :text or email ilike :text', { text: "%#{filter_params[:text]}%" }] if filter_params[:text].present?
  @pagy, @users = pagy(User.where(@text).where(options))
end

#set_userObject (private)

Set @user for some method


37
38
39
# File 'app/controllers/editor/users_controller.rb', line 37

def set_user
  @user = User.find(params[:id])
end

#showObject

GET /editor/users/:id


19
# File 'app/controllers/editor/users_controller.rb', line 19

def show; end

#ticketsObject

GET /editor/users/:id/tickets


22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/editor/users_controller.rb', line 22

def tickets
  @text = ['facts.title ilike :string', { string: "%#{filter_params[:text]}%" }] if filter_params[:text].present?
  if current_user.admin?
    @pagy, @tickets = pagy(@user.tickets.joins(happening: [:fact]).where(@text), items: 6)
  else
    @pagy, @tickets = pagy(
      @user.tickets.joins(happening: [:fact]).where(happening: { fact: @current_user.facts }).where(@text),
      items: 6
    )
  end
end