Class: ScimPatch

Inherits:
Object
  • Object
show all
Defined in:
app/libraries/scim_patch.rb

Overview

Parse PATCH request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, resource_type) ⇒ ScimPatch

Returns a new instance of ScimPatch.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/libraries/scim_patch.rb', line 7

def initialize(params, resource_type)
  if params['schemas'] != ['urn:ietf:params:scim:api:messages:2.0:PatchOp'] ||
     params['Operations'].nil?
    raise Scimaenaga::ExceptionHandler::UnsupportedPatchRequest
  end

  # complex-value(Hash) operation is converted to multiple single-value operations
  converted_operations = ScimPatchOperationConverter.convert(params['Operations'])
  @operations = converted_operations.map do |o|
    create_operation(resource_type, o['op'], o['path'], o['value'])
  end
end

Instance Attribute Details

#operationsObject

Returns the value of attribute operations.



5
6
7
# File 'app/libraries/scim_patch.rb', line 5

def operations
  @operations
end

Instance Method Details

#create_operation(resource_type, op, path, value) ⇒ Object



20
21
22
23
24
25
26
# File 'app/libraries/scim_patch.rb', line 20

def create_operation(resource_type, op, path, value)
  if resource_type == :user
    ScimPatchOperationUser.new(op, path, value)
  else
    ScimPatchOperationGroup.new(op, path, value)
  end
end

#save(model) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/libraries/scim_patch.rb', line 28

def save(model)
  model.transaction do
    @operations.each do |operation|
      operation.save(model)
    end
    model.save! if model.changed?
  end
rescue ActiveRecord::RecordNotFound
  raise
rescue StandardError => e
  raise Scimaenaga::ExceptionHandler::UnsupportedPatchRequest, e.message
end