limosa-io / laravel-scim-server

SCIM 2.0 Server implementation for Laravel
MIT License
47 stars 28 forks source link

Problem to create (new) groups for existing members #47

Closed pieterdt closed 1 week ago

pieterdt commented 1 year ago

In the example https://github.com/idaas-nl/idaas.nl/blob/893b18731464f810da9eae2e4e466b1f00fe9241/app/SCIMConfig.php#L426 members get added to group. This works for a patch on Group that modifies the list of its users.

However, for a POST (create) on Group (if it has a members attribute), the $object does not have an id yet when it passes in this 'Add' callable to add its members.

How could I tackle this? The group object is only saved when all attributes have been handled. Should I customise the ResourceController for this case, or can this somehow also be handled in the CustomSCIMConfig?

pieterdt commented 1 year ago

I fixed the problem by explicitely putting an $object->save() in my 'Add' callable before attaching the members. I hope this is a safe way to deal with it.

While debugging, I also found that a group create passes all members to the Add callable, while the update passes the members one by one. This makes the callable a bit complex because it needs to analyse the incoming $value structure to decide how to proceed. I think it s probably better to just pass the value array in the update operation as well, and remove the foreach loop that is currently there in https://github.com/arietimmerman/laravel-scim-server/blob/master/src/Http/Controllers/ResourceController.php#L265.

Any thoughts on this?

arietimmerman commented 1 week ago

With the latest release, the code you are talking about has been rewritten completely. I believe this also solves the issues you've found.