Group::find('my-dn')->members()->recursive() returns groups, too? #674
Unanswered
nilskretschmer
asked this question in
Q&A
Replies: 1 comment
-
Hi @nilskretschmer! This is intended behaviour, as the LdapRecord/src/Models/ActiveDirectory/Group.php Lines 30 to 37 in db842db If you'd only like users, I'd suggest either extending the built in use LdapRecord\Models\Relations\HasMany;
use LdapRecord\Models\ActiveDirectory\User;
use LdapRecord\Models\ActiveDirectory\Group as BaseGroup;
class Group extends BaseGroup
{
/**
* The users relationship.
*/
public function users(): HasMany
{
return $this->hasMany(User::class, 'memberof')->using($this, 'member');
}
} Or; Filtering the results to only include use LdapRecord\Models\ActiveDirectory\User as LdapUser;
use LdapRecord\Models\ActiveDirectory\Group as LdapGroup;
$ldapUsers = LdapGroup::find(config('ldap.app.users.group'))->members()->recursive()->get()->filter(
fn (Model $model) => $model instanceof LdapUser
); Hope this helps! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
we notice an unexpected behavior in this otherwise great library:
Setup
We have an Active Directory with different User Groups. One User Group contains - let's say 5 Users. This group also contains a subgroup. The Subgroup also contains 3 users. Now we want to get all Users (members) of the base group and the subgroup. For this we use the
recursive()
-function on theLdapRecord\Models\ActiveDirectory\Group
-Model:This
config('ldap.app.users.group')
returns the DN of our base group.The Problem
The function call above returns all users of the base group and the subgroup correctly. But the query also returns the subgroup as an object itself. This leads to the unexpected problem that you assume to get users only, but instead, you retrieve subgroups, too.
Is this indended or is there something wrong with our query?
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions