Class: Editor::UsersController

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

Overview

This controller manage User model for editors

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_editor!

Methods inherited from ApplicationController

#access_denied!, #default_url_options, #record_not_found!, #set_turbo, #switch_locale

Instance Method Details

#filter_paramsObject (private)

Filter params for search a Event



51
52
53
# File 'app/controllers/editor/users_controller.rb', line 51

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

#indexObject

GET /editor/users



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

def index
  if filter_params[:text].present?
    @text = [ "email ilike :text or email ilike :text",
             { text: "%#{filter_params[:text]}%" } ]
  end
  @pagy, @users = pagy User.where(@text)
end

#listObject

GET /editor/users/list



17
18
19
20
21
22
23
# File 'app/controllers/editor/users_controller.rb', line 17

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

#set_userObject (private)

Set @user for some method



46
47
48
# File 'app/controllers/editor/users_controller.rb', line 46

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

#showObject

GET /editor/users/:id



26
27
28
# File 'app/controllers/editor/users_controller.rb', line 26

def show
  @categories = [ [ @user.email, @user.id ] ]
end

#ticketsObject

GET /editor/users/:id/tickets



31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/editor/users_controller.rb', line 31

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