diff --git a/app/frontend/src/javascript/models/user.ts b/app/frontend/src/javascript/models/user.ts index 485757f8b..9b079a410 100644 --- a/app/frontend/src/javascript/models/user.ts +++ b/app/frontend/src/javascript/models/user.ts @@ -15,6 +15,7 @@ export interface User { name: string, need_completion: boolean, ip_address: string, + mapped_from_sso?: string[], profile: { id: number, first_name: string, diff --git a/app/models/concerns/single_sign_on_concern.rb b/app/models/concerns/single_sign_on_concern.rb index a38b95bd9..ac39ab44b 100644 --- a/app/models/concerns/single_sign_on_concern.rb +++ b/app/models/concerns/single_sign_on_concern.rb @@ -21,11 +21,11 @@ module SingleSignOnConcern when 'profile.avatar' profile.user_avatar.remote_attachment_url when 'profile.address' - invoicing_profile.address.address + invoicing_profile.address&.address when 'profile.organization_name' - invoicing_profile.organization.name + invoicing_profile.organization&.name when 'profile.organization_address' - invoicing_profile.organization.address.address + invoicing_profile.organization&.address&.address when 'profile.gender' statistic_profile.gender when 'profile.birthday' @@ -70,6 +70,9 @@ module SingleSignOnConcern profile[sso_mapping[8..-1].to_sym] = data unless data.nil? end end + return if data.nil? || mapped_from_sso.include?(sso_mapping) + + self.mapped_from_sso = [mapped_from_sso, sso_mapping].compact.join(',') end ## used to allow the migration of existing users between authentication providers diff --git a/app/views/api/members/_member.json.jbuilder b/app/views/api/members/_member.json.jbuilder index bda15311c..fbfb71f1a 100644 --- a/app/views/api/members/_member.json.jbuilder +++ b/app/views/api/members/_member.json.jbuilder @@ -5,6 +5,7 @@ json.role member.roles.first.name json.name member.profile.full_name json.need_completion member.need_completion? json.ip_address member.current_sign_in_ip.to_s +json.mapped_from_sso member.mapped_from_sso&.split(',') json.profile do json.id member.profile.id diff --git a/db/migrate/20220425095244_add_mapped_from_sso_to_user.rb b/db/migrate/20220425095244_add_mapped_from_sso_to_user.rb new file mode 100644 index 000000000..5b80f810b --- /dev/null +++ b/db/migrate/20220425095244_add_mapped_from_sso_to_user.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +# We save the data provided by the SSO provider in the user table. So we know, +# per user which data was provided or not. +class AddMappedFromSsoToUser < ActiveRecord::Migration[5.2] + def change + add_column :users, :mapped_from_sso, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index e3a85606f..65c866ce9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_03_28_145017) do +ActiveRecord::Schema.define(version: 2022_04_25_095244) do # These are extensions that must be enabled in order to support this database enable_extension "fuzzystrmatch" @@ -963,6 +963,7 @@ ActiveRecord::Schema.define(version: 2022_03_28_145017) do t.boolean "is_allow_newsletter" t.inet "current_sign_in_ip" t.inet "last_sign_in_ip" + t.string "mapped_from_sso" t.index ["auth_token"], name: "index_users_on_auth_token" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true