Class: Scimaenaga::ScimUsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/scimaenaga/scim_users_controller.rb

Constant Summary

Constants included from Response

Response::CONTENT_TYPE

Instance Method Summary collapse

Methods included from Response

#json_response, #json_scim_response

Instance Method Details

#createObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/scimaenaga/scim_users_controller.rb', line 35

def create
  if Scimaenaga.config.scim_user_prevent_update_on_create
    user = @company
           .public_send(Scimaenaga.config.scim_users_scope)
           .create!(permitted_user_params)
  else
    username_key = Scimaenaga.config.queryable_user_attributes[:userName]
    find_by_username = {}
    find_by_username[username_key] = permitted_user_params[username_key]
    user = @company
           .public_send(Scimaenaga.config.scim_users_scope)
           .find_or_create_by(find_by_username)
    user.update!(permitted_user_params)
  end
  json_scim_response(object: user, status: :created)
end

#destroyObject

Raises:

  • (ActiveRecord::RecordNotFound)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/scimaenaga/scim_users_controller.rb', line 71

def destroy
  unless Scimaenaga.config.user_destroy_method
    raise Scimaenaga::ExceptionHandler::InvalidConfiguration
  end

  user = @company.public_send(Scimaenaga.config.scim_users_scope).find(params[:id])
  raise ActiveRecord::RecordNotFound unless user

  begin
    user.public_send(Scimaenaga.config.user_destroy_method)
  rescue NoMethodError => e
    raise Scimaenaga::ExceptionHandler::InvalidConfiguration, e.message
  rescue ActiveRecord::RecordNotDestroyed => e
    raise Scimaenaga::ExceptionHandler::InvalidRequest, e.message
  rescue StandardError => e
    raise Scimaenaga::ExceptionHandler::UnexpectedError, e.message
  end

  head :no_content
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/scimaenaga/scim_users_controller.rb', line 6

def index
  if params[:filter].present?
    query = Scimaenaga::ScimQueryParser.new(
      params[:filter], Scimaenaga.config.queryable_user_attributes
    )

    users = @company
            .public_send(Scimaenaga.config.scim_users_scope)
            .where(
              "#{Scimaenaga.config.scim_users_model
          .connection.quote_column_name(query.attribute)} #{query.operator} ?",
              query.parameter
            )
            .order(Scimaenaga.config.scim_users_list_order)
  else
    users = @company
            .public_send(Scimaenaga.config.scim_users_scope)
            .order(Scimaenaga.config.scim_users_list_order)
  end

  counts = ScimCount.new(
    start_index: params[:startIndex],
    limit: params[:count],
    total: users.count
  )

  json_scim_response(object: users, counts: counts)
end

#patch_updateObject



63
64
65
66
67
68
69
# File 'app/controllers/scimaenaga/scim_users_controller.rb', line 63

def patch_update
  user = @company.public_send(Scimaenaga.config.scim_users_scope).find(params[:id])
  patch = ScimPatch.new(params, :user)
  patch.save(user)

  json_scim_response(object: user)
end

#put_updateObject



57
58
59
60
61
# File 'app/controllers/scimaenaga/scim_users_controller.rb', line 57

def put_update
  user = @company.public_send(Scimaenaga.config.scim_users_scope).find(params[:id])
  user.update!(permitted_user_params)
  json_scim_response(object: user)
end

#showObject



52
53
54
55
# File 'app/controllers/scimaenaga/scim_users_controller.rb', line 52

def show
  user = @company.public_send(Scimaenaga.config.scim_users_scope).find(params[:id])
  json_scim_response(object: user)
end