DEV: Change mapping of emails

This commit is contained in:
Peter Bouda 2024-10-31 09:08:33 +00:00
parent 5f590e1c54
commit e8c5c97cb0

View file

@ -3,6 +3,34 @@
require "scimitar" require "scimitar"
module DiscourseScim::UserMixin module DiscourseScim::UserMixin
def scim_email_mapper=(scim_emails)
user_emails = scim_emails.map do |scim_email|
UserEmail.build({
email: scim_emails[0][:value],
primary: scim_emails[0].key?(:type) || scim_emails[0][:type] == "work"
})
end
primary_email = user_emails[0]
primary_emails = user_emails.select { |value| value.primary }
if primary_emails.length() > 0
primary_email = primary_emails[0]
end
self.user_emails = user_emails
self.primary_email = primary_email
end
def scim_email_mapper
self.user_emails.map do |user_email|
scim_email = { value: user_email[:email] }
if user_email[:primary]
scim_email[:type] = "primary"
end
scim_email
end
end
module UserClassMethods module UserClassMethods
def scim_resource_type def scim_resource_type
Scimitar::Resources::User Scimitar::Resources::User
@ -13,16 +41,7 @@ module DiscourseScim::UserMixin
id: :id, id: :id,
userName: :username, userName: :username,
displayName: :name, displayName: :name,
emails: [ emails: :scim_email_mapper,
{
match: "type",
with: "work",
using: {
value: :email,
primary: true
}
}
],
groups: [ groups: [
{ {
list: :groups, list: :groups,