A free open source IT asset/license management system
Fixed SCIM test
snipe24c216ce800a
diff --git a/app/Models/SnipeSCIMConfig.php b/app/Models/SnipeSCIMConfig.phpindex d09325ba85..85d5e4def5 100644--- a/app/Models/SnipeSCIMConfig.php+++ b/app/Models/SnipeSCIMConfig.php@@ -322,7 +322,37 @@ class SnipeMutableCollection extends MutableCollection$requestedUserIds = $this->userIdsFromMemberPayload($value);$previouslyAttachedIds = $this->pivotFilterToAttached($object, $requestedUserIds);- parent::add($value, $object);+ // 1) Skip its trailing $object->load($this->attribute) call.+ // That load fires a `select users.* from users inner join+ // users_groups` that hydrates the entire membership into+ // User models on every PATCH, enough to exhaust PHP memory+ // on a group with tens of thousands of members. The+ // response's `members` list is rebuilt by our doRead()+ // override (id-only pluck), so the load is redundant here.+ // 2) Attach only the id delta we already know is new+ // (requestedUserIds minus previouslyAttachedIds) instead+ // of syncWithoutDetaching(). Laravel's syncWithoutDetaching+ // begins by SELECT-ing every pivot row for group_id to+ // figure out what already exists, defeating the point of+ // the bounded pre-check.+ $submittedValues = collect($value)->pluck('value')->all();+ $existingObjects = $object+ ->{$this->attribute}()+ ->getRelated()+ ->findMany($submittedValues)+ ->map(fn($o) => $o->getKey());++ if (($diff = collect($submittedValues)->diff($existingObjects))->count() > 0) {+ throw new SCIMException(+ sprintf('One or more %s are unknown: %s', $this->attribute, implode(',', $diff->all())),+ 500+ );+ }++ $toAttach = array_values(array_diff($requestedUserIds, $previouslyAttachedIds));+ if ($toAttach !== []) {+ $object->{$this->attribute}()->attach($toAttach);+ }$this->logGroupMembershipChangesForIds($object,@@ -337,14 +367,39 @@ class SnipeMutableCollection extends MutableCollection// one user id, list-value form targets an explicit list. Both// reduce to a small requestedUserIds set that we pre-check// against the pivot so we log only real detachments.- if ($path?->getValuePathFilter()?->getComparisonExpression() !== null) {- $requestedUserIds = [(int) $path->getValuePathFilter()->getComparisonExpression()->compareValue];+ $comparison = $path?->getValuePathFilter()?->getComparisonExpression();+ if ($comparison !== null) {+ $requestedUserIds = [(int) $comparison->compareValue];} else {$requestedUserIds = $this->userIdsFromMemberPayload($value);}$previouslyAttachedIds = $this->pivotFilterToAttached($object, $requestedUserIds);- parent::remove($value, $object, $path);+ // Inline vendor MutableCollection::remove() minus its trailing+ // $object->load($this->attribute) call. Same reason as add():+ // the full-membership hydration exhausts memory on large+ // groups and doRead() rebuilds the response list itself.+ if ($comparison !== null) {+ $attributes = $comparison->attributePath->attributeNames ?? [];+ $operator = $comparison->operator;++ if ($value !== null) {+ throw new SCIMException('Remove operation with filter requires a null value parameter', 400);+ }+ if (count($attributes) !== 1) {+ throw new SCIMException(sprintf('Filter must specify exactly one attribute, found %d attributes', count($attributes)), 400);+ }+ if ($operator !== 'eq') {+ throw new SCIMException(sprintf('Unsupported filter operator "%s" - only "eq" is supported', $operator), 400);+ }+ if ($attributes[0] !== 'value') {+ throw new SCIMException(sprintf('Cannot filter on "%s" - only filtering on "value" attribute is supported', $attributes[0]), 400);+ }++ $object->{$this->attribute}()->detach([$comparison->compareValue]);+ } else {+ $object->{$this->attribute}()->detach(collect($value)->pluck('value')->all());+ }$this->logGroupMembershipChangesForIds($object,@@ -387,7 +442,7 @@ class SnipeMutableCollection extends MutableCollection*/private function pivotFilterToAttached(Model $object, array $requestedUserIds): array{- if (! ($object instanceof Group || $object instanceof SCIMGroup) || $requestedUserIds === []) {+ if (!$object instanceof Group || $requestedUserIds === []) {return [];}@@ -410,7 +465,7 @@ class SnipeMutableCollection extends MutableCollection*/private function logGroupMembershipChangesForIds(Model $object, array $attachedIds, array $detachedIds): void{- if (! ($object instanceof Group || $object instanceof SCIMGroup)) {+ if (!$object instanceof Group) {return;}diff --git a/app/Models/User.php b/app/Models/User.phpindex 14de9742fd..8c71928864 100644--- a/app/Models/User.php+++ b/app/Models/User.php@@ -917,7 +917,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo// log entirely, so the pivot mutation is still visible.$detached = Group::find($groupId);$oldSnapshot = $newSnapshot;- $oldSnapshot[] = ['id' => $groupId, 'name' => $detached?->name ?? ('#'.$groupId)];+ $oldSnapshot[] = ['id' => $groupId, 'name' => $detached ? $detached->name : '#'.$groupId];usort($oldSnapshot, fn ($a, $b) => $a['id'] <=> $b['id']);$this->recordGroupsChange($oldSnapshot, $newSnapshot);diff --git a/phpstan-baseline.neon b/phpstan-baseline.neonindex 04f64537da..9b78f20913 100644--- a/phpstan-baseline.neon+++ b/phpstan-baseline.neon@@ -1896,12 +1896,6 @@ parameters:count: 1path: app/Http/Controllers/Api/UsersController.php- -- message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\Relation\:\:sync\(\)\.$#'- identifier: method.notFound- count: 2- path: app/Http/Controllers/Api/UsersController.php--message: '#^Method App\\Http\\Transformers\\AssetsTransformer\:\:transformAssets\(\) invoked with 3 parameters, 2 required\.$#'identifier: arguments.count@@ -2028,12 +2022,6 @@ parameters:count: 2path: app/Http/Controllers/AssetModelsController.php- -- message: '#^PHPDoc tag @param references unknown parameter\: \$modelId$#'- identifier: parameter.notFound- count: 6- path: app/Http/Controllers/AssetModelsController.php--message: '#^Property App\\Models\\AssetModel\:\:\$id \(int\) does not accept null\.$#'identifier: assign.propertyType@@ -3471,7 +3459,7 @@ parameters:-message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\Relation\:\:sync\(\)\.$#'identifier: method.notFound- count: 2+ count: 1path: app/Http/Controllers/Users/BulkUsersController.php-@@ -3522,12 +3510,6 @@ parameters:count: 1path: app/Http/Controllers/Users/UsersController.php- -- message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\Relation\:\:sync\(\)\.$#'- identifier: method.notFound- count: 2- path: app/Http/Controllers/Users/UsersController.php--message: '#^Method App\\Http\\Controllers\\Users\\UsersController\:\:edit\(\) should return Illuminate\\Contracts\\View\\View\|Illuminate\\Http\\RedirectResponse but return statement is missing\.$#'identifier: return.missing@@ -8157,7 +8139,7 @@ parameters:-message: '#^Access to an undefined property App\\Models\\Actionlog\:\:\$created_by\.$#'identifier: property.notFound- count: 5+ count: 6path: app/Models/User.php-@@ -8235,6 +8217,12 @@ parameters:-message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$id\.$#'identifier: property.notFound+ count: 2+ path: app/Models/User.php++ -+ message: '#^Access to an undefined property Illuminate\\Database\\Eloquent\\Model\:\:\$name\.$#'+ identifier: property.notFoundcount: 1path: app/Models/User.php@@ -8250,6 +8238,12 @@ parameters:count: 1path: app/Models/User.php+ -+ message: '#^Call to an undefined method Illuminate\\Database\\Eloquent\\Relations\\Relation\:\:sync\(\)\.$#'+ identifier: method.notFound+ count: 1+ path: app/Models/User.php+-message: '#^Call to an undefined method Illuminate\\Database\\Query\\Builder\:\:orWhereHas\(\)\.$#'identifier: method.notFounddiff --git a/resources/assets/js/snipeit.js b/resources/assets/js/snipeit.jsindex b0665aec37..a3a3570e7d 100755--- a/resources/assets/js/snipeit.js+++ b/resources/assets/js/snipeit.js@@ -370,7 +370,6 @@ $(function () {}});-// $('.datepicker').datepicker();// var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value// $.fn.bootstrapDP = datepicker;@@ -878,7 +877,7 @@ $(document).ready(function () {});// Auto-init eonasdan datetimepickers. bootstrap-datepicker has a native- // data-provide auto-init; eonasdan does not, so we do it ourselves.+ // data-provide auto-init. eonasdan does not, so we do it ourselves.// Options are read from data-attributes on the wrapper so blade components// can tune format/side-by-side without touching this JS.//