2024-10-22 08:31:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "scimitar"
|
|
|
|
|
|
|
|
module DiscourseScim::GroupMixin
|
|
|
|
module GroupClassMethods
|
|
|
|
def scim_resource_type
|
|
|
|
Scimitar::Resources::Group
|
|
|
|
end
|
|
|
|
|
|
|
|
def scim_attributes_map
|
|
|
|
{
|
|
|
|
id: :id,
|
|
|
|
displayName: :name,
|
2024-10-25 09:00:50 +00:00
|
|
|
members: [
|
|
|
|
list: :scim_users_and_groups,
|
2024-10-22 08:31:57 +00:00
|
|
|
using: {
|
|
|
|
value: :id
|
|
|
|
},
|
|
|
|
find_with: -> (scim_list_entry) {
|
|
|
|
id = scim_list_entry['value']
|
|
|
|
type = scim_list_entry['type' ] || 'User'
|
|
|
|
|
|
|
|
case type.downcase
|
|
|
|
when 'user'
|
|
|
|
User.find_by_id(id)
|
|
|
|
when 'group'
|
|
|
|
Group.find_by_id(id)
|
|
|
|
else
|
|
|
|
User.find_by_id(id)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def scim_mutable_attributes
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def scim_queryable_attributes
|
|
|
|
{
|
|
|
|
displayName: :name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def scim_users_and_groups
|
2024-10-25 09:00:50 +00:00
|
|
|
self.users.select{ |item| item.id >= 0 }.to_a + self.associated_groups.to_a
|
2024-10-22 08:31:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def scim_users_and_groups=(mixed_array)
|
2024-10-25 09:00:50 +00:00
|
|
|
self.users = mixed_array.select { |item| item.is_a?(User) && item.id >=0 }
|
2024-10-22 08:31:57 +00:00
|
|
|
self.associated_groups = mixed_array.select { |item| item.is_a?(Group) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.included(base)
|
|
|
|
base.extend GroupClassMethods
|
|
|
|
end
|
|
|
|
end
|