Class: Admin::UsersController

Inherits:
AdminController
  • Object
show all
Includes:
Authentication, ToggleableEntity
Defined in:
app/controllers/admin/users_controller.rb

Overview

Handling users

Instance Method Summary collapse

Methods included from ToggleableEntity

#toggle

Methods included from Authentication

#create_token_for_user, #deactivate_token, #pop_token, #redirect_authenticated_user

Instance Method Details

#authenticateObject

post /admin/users/:id/authenticate



60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/admin/users_controller.rb', line 60

def authenticate
  cookies['pt'] = {
    value: cookies['token'],
    expires: 1.year.from_now,
    domain: :all,
    httponly: true
  }
  create_token_for_user(@entity)
  redirect_to my_path
end

#codesObject

get /admin/users/:id/codes



27
28
29
# File 'app/controllers/admin/users_controller.rb', line 27

def codes
  @collection = Code.owned_by(@entity).page_for_administration(current_page)
end

#grant_privilegeObject

put /admin/users/:id/privileges/:privilege_id



36
37
38
39
40
# File 'app/controllers/admin/users_controller.rb', line 36

def grant_privilege
  @privilege.grant(@entity, params[:region_id])

  render json: { data: { user_privilege_ids: @entity.user_privilege_ids } }
end

#indexObject

get /admin/users



12
13
14
15
# File 'app/controllers/admin/users_controller.rb', line 12

def index
  @search     = param_from_request(:q)
  @collection = User.page_for_administration current_page, @search
end

#privilegesObject

get /admin/users/:id/privileges



32
33
# File 'app/controllers/admin/users_controller.rb', line 32

def privileges
end

#revoke_privilegeObject

delete /admin/users/:id/privileges/:privilege_id



43
44
45
46
47
# File 'app/controllers/admin/users_controller.rb', line 43

def revoke_privilege
  @privilege.revoke(@entity, params[:region_id])

  render json: { data: { user_privilege_ids: @entity.user_privilege_ids } }
end

#searchObject

get /admin/users/search



50
51
52
53
54
55
56
57
# File 'app/controllers/admin/users_controller.rb', line 50

def search
  query = param_from_request(:q)
  if query.blank?
    @collection = []
  else
    @collection = User.search(query).order('slug asc').first(10)
  end
end

#showObject

get /admin/users/:id



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

def show
end

#tokensObject

get /admin/users/:id/tokens



22
23
24
# File 'app/controllers/admin/users_controller.rb', line 22

def tokens
  @collection = Token.owned_by(@entity).page_for_administration(current_page)
end