Class: Scimaenaga::ScimGroupsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/scimaenaga/scim_groups_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



43
44
45
46
47
48
49
# File 'app/controllers/scimaenaga/scim_groups_controller.rb', line 43

def create
  group = @company
          .public_send(Scimaenaga.config.scim_groups_scope)
          .create!(permitted_group_params)

  json_scim_response(object: group, status: :created)
end

#destroyObject

Raises:

  • (ActiveRecord::RecordNotFound)


69
70
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_groups_controller.rb', line 69

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

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

  begin
    group.public_send(Scimaenaga.config.group_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



5
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
34
# File 'app/controllers/scimaenaga/scim_groups_controller.rb', line 5

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

    groups = @company
             .public_send(Scimaenaga.config.scim_groups_scope)
             .where(
               "#{Scimaenaga.config.scim_groups_model
                           .connection.quote_column_name(query.attribute)}
                           #{query.operator} ?",
               query.parameter
             )
             .order(Scimaenaga.config.scim_groups_list_order)
  else
    groups = @company
             .public_send(Scimaenaga.config.scim_groups_scope)
             .preload(:users)
             .order(Scimaenaga.config.scim_groups_list_order)
  end

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

  json_scim_response(object: groups, counts: counts)
end

#patch_updateObject



59
60
61
62
63
64
65
66
67
# File 'app/controllers/scimaenaga/scim_groups_controller.rb', line 59

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

  json_scim_response(object: group)
end

#put_updateObject



51
52
53
54
55
56
57
# File 'app/controllers/scimaenaga/scim_groups_controller.rb', line 51

def put_update
  group = @company
          .public_send(Scimaenaga.config.scim_groups_scope)
          .find(params[:id])
  group.update!(permitted_group_params)
  json_scim_response(object: group)
end

#showObject



36
37
38
39
40
41
# File 'app/controllers/scimaenaga/scim_groups_controller.rb', line 36

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