Skip to content

Commit

Permalink
Merge pull request #9 from savannabits/development
Browse files Browse the repository at this point in the history
Enhancement: Sync GUID for a user before sync
  • Loading branch information
coolsam726 authored Oct 23, 2023
2 parents bd05355 + c09f2ec commit 36f6ea2
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Services/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
use LdapRecord\Laravel\Commands\ImportLdapUsers;
use Savannabits\Saas\Ldap\Staff;
use Savannabits\Saas\Ldap\Student;

class Users
{
Expand All @@ -21,6 +23,25 @@ public static function make(): static
*/
public function syncUser(string $username, string $provider, ?bool $skipLdapImport = false)
{
$user = \App\Models\User::whereUsername($username)->first();

if ($user) {
\Log::info("User exists. Setting GUID");
if ($provider ==='staff') {
$staff = Staff::query()->where('samaccountname','=', $user->username)->first();
if ($staff) {
\Log::info("AD User found. Updating");
$user->update(['guid' => $staff->getConvertedGuid()]);
}
} else {
$student = Student::query()->where('samaccountname','=', $user->username)->first();
if ($student) {
\Log::info("AD Student User found. Updating");
$user->update(['guid' => $student->getConvertedGuid()]);
}
}
}

if (! $skipLdapImport) {
$res = Artisan::call('ldap:import', [
'provider' => $provider,
Expand All @@ -35,7 +56,6 @@ public function syncUser(string $username, string $provider, ?bool $skipLdapImpo
throw new Exception('The options given could not be used for the import.');
}
}
$user = \App\Models\User::whereUsername($username)->first();
// Sync with DataService
if ($provider === 'staff') {
$staff = Webservice::make()->fetchStaff($username);
Expand Down

0 comments on commit 36f6ea2

Please sign in to comment.