Inheritance: extends Entry, use trait Adldap\Models\Traits\HasDescriptionTrait, use trait Adldap\Models\Traits\HasMemberOfTrait
Exemple #1
0
 /**
  * Execute the job.
  *
  * @return Role
  */
 public function handle()
 {
     $label = $this->group->getName();
     $name = str_slug($label);
     // We'll create the role if it doesn't exist already.
     $role = Role::firstOrCreate(compact('name', 'label'));
     // We'll double check that it was successfully retrieved / created.
     if ($role instanceof Role) {
         // Retrieve the members from the AD group.
         $members = $this->group->getMembers();
         foreach ($members as $member) {
             // Import users that may not already be apart of our local DB.
             $user = $this->dispatch(new ImportUser($member));
             // Make sure the user isn't already apart of the role.
             $exists = $role->users()->find($user->id);
             if (!$exists) {
                 // Attach the user to the role if they
                 // aren't currently a member.
                 $role->users()->save($user);
             }
         }
         return $role;
     }
     return false;
 }
Exemple #2
0
 /**
  * Validates if the specified group is the given parent instance.
  *
  * @param Group|string $group
  * @param Group        $parent
  *
  * @return bool
  */
 protected function validateGroup($group, Group $parent)
 {
     if ($group instanceof Group) {
         // We've been given a group instance, we'll compare their DNs.
         return $parent->getDn() === $group->getDn();
     }
     if (Utilities::explodeDn($group)) {
         // We've been given a DN, we'll compare it to the parents.
         return $parent->getDn() === $group;
     }
     if (!empty($group)) {
         // We've been given just a string, we'll
         // compare it to the parents name.
         return $parent->getCommonName() === $group;
     }
     return false;
 }