A free open source IT asset/license management system
Fix to SCIM companies, and some PHP errors around inheritance
Brady Wetherington1afde946d216
diff --git a/app/Models/SCIMUser.php b/app/Models/SCIMUser.phpindex 125f3dd737..50a7fd6a49 100644--- a/app/Models/SCIMUser.php+++ b/app/Models/SCIMUser.php@@ -2,6 +2,8 @@namespace App\Models;+use Illuminate\Database\Eloquent\Relations\BelongsToMany;+class SCIMUser extends User{protected $table = 'users';@@ -21,4 +23,9 @@ class SCIMUser extends Userreturn $this->belongsToMany(\App\Models\Group::class, 'users_groups', 'user_id', 'group_id');}+ public function companies(): BelongsToMany+ {+ return $this->belongsToMany(Company::class, 'company_user', 'user_id', 'company_id');+ }+}\ No newline at end of filediff --git a/app/Models/SnipeSCIMConfig.php b/app/Models/SnipeSCIMConfig.phpindex 34c3f4e5aa..48df783925 100644--- a/app/Models/SnipeSCIMConfig.php+++ b/app/Models/SnipeSCIMConfig.php@@ -166,6 +166,39 @@ class SnipeMutableCollection extends MutableCollection}}+class MappedTable extends Attribute+{+ public function __construct(+ private string $scim_attribute_name,+ private string $relationship_name,+ private string $relationship_class,+ private string $relationship_id_field,+ private string $relationship_field+ ) {+ parent::__construct($this->scim_attribute_name);+ }++ protected function doRead(&$object, $attributes = [])+ {+ return $object->{$this->relationship_name}?->{$this->relationship_field};+ }++ public function add($value, Model &$object)+ {+ $object->{$this->relationship_id_field} = $value ? $this->relationship_class::firstOrCreate([$this->relationship_field => $value])->id : null;+ }++ public function replace($value, Model &$object, $path = null, $removeIfNotSet = false)+ {+ $object->{$this->relationship_id_field} = $value ? $this->relationship_class::firstOrCreate([$this->relationship_field => $value])->id : null;+ }++ public function patch($operation, $value, Model &$object, ?Path $path = null, $removeIfNotSet = false)+ {+ $object->{$this->relationship_id_field} = $value ? $this->relationship_class::firstOrCreate([$this->relationship_field => $value])->id : null;+ }+}+// Company is stored only in the company_user pivot, not company_id. Read from the pivot// and sync it on write. For new users (not yet saved) defer the sync via a saved() callback.class SCIMCompanyAttribute extends MappedTable@@ -210,39 +243,6 @@ class EloquentWithRemove extends Eloquent}}-class MappedTable extends Attribute-{- public function __construct(- private string $scim_attribute_name,- private string $relationship_name,- private string $relationship_class,- private string $relationship_id_field,- private string $relationship_field)- {- parent::__construct($this->scim_attribute_name);- }-- protected function doRead(&$object, $attributes = [])- {- return $object->{$this->relationship_name}?->{$this->relationship_field};- }-- public function add($value, Model &$object)- {- $object->{$this->relationship_id_field} = $value ? $this->relationship_class::firstOrCreate([$this->relationship_field => $value])->id : null;- }-- public function replace($value, Model &$object, $path = null, $removeIfNotSet = false)- {- $object->{$this->relationship_id_field} = $value ? $this->relationship_class::firstOrCreate([$this->relationship_field => $value])->id : null;- }-- public function patch($operation, $value, Model &$object, ?Path $path = null, $removeIfNotSet = false)- {- $object->{$this->relationship_id_field} = $value ? $this->relationship_class::firstOrCreate([$this->relationship_field => $value])->id : null;- }-}-class UpdatableComplex extends Complex{public function doWrite($operation, $subop, $value, Model &$object, ?Path $path = null, $removeIfNotSet = false)