Class: Dscf::Core::UserRolesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/dscf/core/user_roles_controller.rb

Instance Method Summary collapse

Methods included from Authorizable

#authorize, #authorize_action!, #policy_scope, #pundit_user

Methods included from JsonResponse

#render_error, #render_success, #serialize

Methods included from TokenAuthenticatable

#require_valid_refresh_token, #validate_device_consistency, #validate_token_expiry

Methods included from Authenticatable

#authenticate_user, #authenticate_user!, #current_user, #refresh_token, #sign_in, #sign_out

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/dscf/core/user_roles_controller.rb', line 14

def create
  @clazz = Dscf::Core::UserRole
  user_role = Dscf::Core::UserRole.new(
    user: @target_user,
    role_id: params[:role_id],
    assigned_by: current_user
  )

  if user_role.save
    render_success(data: user_role, status: :created)
  else
    render_error(errors: user_role.errors.full_messages[0],
                 status: :unprocessable_entity)
  end
end

#destroyObject



30
31
32
33
34
# File 'app/controllers/dscf/core/user_roles_controller.rb', line 30

def destroy
  @clazz = Dscf::Core::UserRole
  @user_role.destroy
  render_success
end

#indexObject



8
9
10
11
12
# File 'app/controllers/dscf/core/user_roles_controller.rb', line 8

def index
  @clazz = Dscf::Core::UserRole
  user_roles = @target_user.user_roles.includes(:role)
  render_success(data: user_roles)
end