From 3fb985078669532b9cde6cd6c27f37e2a6975778 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 20 Dec 2021 14:07:25 +0100 Subject: [PATCH] [bug] unable to bind sso to Profile.bithday or Profile.gender --- app/models/profile.rb | 3 ++- app/models/user.rb | 10 ++++++++++ .../api/auth_providers/mapping_fields.json.jbuilder | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 1c5d3c0ed..ec5853dfd 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -27,7 +27,8 @@ class Profile < ApplicationRecord # we protect some fields as they are designed to be managed by the system and must not be updated externally blacklist = %w[id user_id created_at updated_at] # model-relationships must be added manually - additional = [%w[avatar string], %w[address string], %w[organization_name string], %w[organization_address string]] + additional = [%w[avatar string], %w[address string], %w[organization_name string], %w[organization_address string], + %w[gender boolean], %w[birthday date]] Profile.columns_hash .map { |k, v| [k, v.type.to_s] } .delete_if { |col| blacklist.include?(col[0]) } diff --git a/app/models/user.rb b/app/models/user.rb index 637198ae8..78122042c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -242,6 +242,10 @@ class User < ApplicationRecord invoicing_profile.organization.name when 'profile.organization_address' invoicing_profile.organization.address.address + when 'profile.gender' + statistic_profile.gender + when 'profile.birthday' + statistic_profile.birthday else profile[parsed[2].to_sym] end @@ -269,6 +273,12 @@ class User < ApplicationRecord invoicing_profile.organization ||= Organization.new invoicing_profile.organization.address ||= Address.new invoicing_profile.organization.address.address = data + when 'profile.gender' + statistic_profile ||= StatisticProfile.new + statistic_profile.gender = data + when 'profile.birthday' + statistic_profile ||= StatisticProfile.new + statistic_profile.birthday = data else profile[sso_mapping[8..-1].to_sym] = data unless data.nil? end diff --git a/app/views/api/auth_providers/mapping_fields.json.jbuilder b/app/views/api/auth_providers/mapping_fields.json.jbuilder index 7eb9615bf..6959341ef 100644 --- a/app/views/api/auth_providers/mapping_fields.json.jbuilder +++ b/app/views/api/auth_providers/mapping_fields.json.jbuilder @@ -1,4 +1,4 @@ +# frozen_string_literal: true json.user User.mapping - -json.profile Profile.mapping \ No newline at end of file +json.profile Profile.mapping