Skip to content

A free open source IT asset/license management system

Update LdapSync.php

Fiala06bdb0e6c2a3a2
diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php
index 2338cebf75..2987b2af5c 100644
--- a/app/Console/Commands/LdapSync.php
+++ b/app/Console/Commands/LdapSync.php
@@ -424,8 +424,12 @@ class LdapSync extends Command
$item['note'] = $item['createorupdate'];
$item['status'] = 'success';
if ($item['createorupdate'] === 'created' && $ldap_default_group) {
- $user->groups()->attach($ldap_default_group);
+ // Check if the relationship already exists
+ if (!$user->groups()->where('group_id', $ldap_default_group)->exists()) {
+ $user->groups()->attach($ldap_default_group);
+ }
}
+
//updates assets location based on user's location
Asset::where('assigned_to', '=', $user->id)->update(['location_id' => $user->location_id]);