mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
[SSO] field data mapping transformation on data reception
This commit is contained in:
parent
13f416a101
commit
3c277428bf
@ -85,7 +85,7 @@ class AuthenticationController
|
||||
$scope.datatype = datatype
|
||||
## data transformation rules
|
||||
$scope.transformation =
|
||||
rules: field.transformation || {}
|
||||
rules: field.transformation || {type: datatype}
|
||||
## available transformation formats
|
||||
$scope.formats =
|
||||
date: [
|
||||
@ -93,6 +93,14 @@ class AuthenticationController
|
||||
label: 'ISO 8601',
|
||||
value: 'iso8601'
|
||||
},
|
||||
{
|
||||
label: 'RFC 2822',
|
||||
value: 'rfc2822'
|
||||
},
|
||||
{
|
||||
label: 'RFC 3339',
|
||||
value: 'rfc3339'
|
||||
},
|
||||
{
|
||||
label: 'Timestamp (s)'
|
||||
value: 'timestamp-s'
|
||||
|
@ -59,7 +59,7 @@ class API::AuthProvidersController < API::ApiController
|
||||
:id, :base_url, :token_endpoint, :authorization_endpoint, :profile_url, :client_id, :client_secret,
|
||||
o_auth2_mappings_attributes: [
|
||||
:id, :local_model, :local_field, :api_field, :api_endpoint, :api_data_type, :_destroy,
|
||||
transformation: [:format, :true_value, :false_value, mapping: [:from, :to]]
|
||||
transformation: [:type, :format, :true_value, :false_value, mapping: [:from, :to]]
|
||||
]
|
||||
])
|
||||
end
|
||||
|
@ -54,12 +54,58 @@ module OmniAuth
|
||||
@parsed_info ||= Hash.new
|
||||
unless @parsed_info.size > 0
|
||||
OmniAuth::Strategies::SsoOauth2Provider.active_provider.providable.o_auth2_mappings.each do |mapping|
|
||||
@parsed_info[(mapping.local_model+'.'+mapping.local_field).to_sym] = raw_info[mapping.api_endpoint.to_sym][mapping.api_field]
|
||||
|
||||
if mapping.transformation
|
||||
case mapping.transformation['type']
|
||||
## INTEGER
|
||||
when 'integer'
|
||||
mapping.transformation['mapping'].each do |m|
|
||||
if m['from'] == raw_info[mapping.api_endpoint.to_sym][mapping.api_field]
|
||||
@parsed_info[local_sym(mapping)] = m['to']
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
## BOOLEAN
|
||||
when 'boolean'
|
||||
@parsed_info[local_sym(mapping)] = !(raw_info[mapping.api_endpoint.to_sym][mapping.api_field] == mapping.transformation['false_value'])
|
||||
@parsed_info[local_sym(mapping)] = (raw_info[mapping.api_endpoint.to_sym][mapping.api_field] == mapping.transformation['true_value'])
|
||||
|
||||
## DATE
|
||||
when 'date'
|
||||
case mapping.transformation['format']
|
||||
when 'iso8601'
|
||||
@parsed_info[local_sym(mapping)] = DateTime.iso8601(raw_info[mapping.api_endpoint.to_sym][mapping.api_field])
|
||||
when 'rfc2822'
|
||||
@parsed_info[local_sym(mapping)] = DateTime.rfc2822(raw_info[mapping.api_endpoint.to_sym][mapping.api_field])
|
||||
when 'rfc3339'
|
||||
@parsed_info[local_sym(mapping)] = DateTime.rfc3339(raw_info[mapping.api_endpoint.to_sym][mapping.api_field])
|
||||
when 'timestamp-s'
|
||||
@parsed_info[local_sym(mapping)] = DateTime.strptime(raw_info[mapping.api_endpoint.to_sym][mapping.api_field],'%s')
|
||||
when 'timestamp-ms'
|
||||
@parsed_info[local_sym(mapping)] = DateTime.strptime(raw_info[mapping.api_endpoint.to_sym][mapping.api_field],'%Q')
|
||||
else
|
||||
@parsed_info[local_sym(mapping)] = DateTime.parse(raw_info[mapping.api_endpoint.to_sym][mapping.api_field])
|
||||
end
|
||||
|
||||
## OTHER TRANSFORMATIONS (not supported)
|
||||
else
|
||||
@parsed_info[local_sym(mapping)] = raw_info[mapping.api_endpoint.to_sym][mapping.api_field]
|
||||
end
|
||||
|
||||
## NO TRANSFORMATION
|
||||
else
|
||||
@parsed_info[local_sym(mapping)] = raw_info[mapping.api_endpoint.to_sym][mapping.api_field]
|
||||
end
|
||||
end
|
||||
end
|
||||
@parsed_info
|
||||
end
|
||||
|
||||
private
|
||||
def local_sym(mapping)
|
||||
(mapping.local_model+'.'+mapping.local_field).to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user