DEV: Change mapping of emails
This commit is contained in:
parent
5f590e1c54
commit
e8c5c97cb0
1 changed files with 34 additions and 15 deletions
|
@ -3,6 +3,34 @@
|
|||
require "scimitar"
|
||||
|
||||
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
|
||||
def scim_resource_type
|
||||
Scimitar::Resources::User
|
||||
|
@ -10,29 +38,20 @@ module DiscourseScim::UserMixin
|
|||
|
||||
def scim_attributes_map
|
||||
{
|
||||
id: :id,
|
||||
userName: :username,
|
||||
displayName: :name,
|
||||
emails: [
|
||||
{
|
||||
match: "type",
|
||||
with: "work",
|
||||
using: {
|
||||
value: :email,
|
||||
primary: true
|
||||
}
|
||||
}
|
||||
],
|
||||
id: :id,
|
||||
userName: :username,
|
||||
displayName: :name,
|
||||
emails: :scim_email_mapper,
|
||||
groups: [
|
||||
{
|
||||
list: :groups,
|
||||
list: :groups,
|
||||
using: {
|
||||
value: :id,
|
||||
display: :name
|
||||
}
|
||||
}
|
||||
],
|
||||
active: :active
|
||||
active: :active
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue