zakird / pyad

Python Active Directory Tools | *Not actively maintained*
http://zakird.github.io/pyad/
176 stars 72 forks source link

Group User Check #121

Open sdiniz73 opened 5 years ago

sdiniz73 commented 5 years ago

Hello, has anyone managed to use "is member of"? I need to check if a user belongs to a group.

Thanks

dexxfm commented 4 years ago

Hello, has anyone managed to use "is member of"? I need to check if a user belongs to a group.

Thanks

I'm having the same issue.

dexxfm commented 4 years ago

Hello, has anyone managed to use "is member of"? I need to check if a user belongs to a group.

Thanks

I don't have push access, but i fixed that function:

def check_contains_member(self, check_member, recursive=False):
    """Checks whether a pyAD object is a member of the group.
        check_member expects a pyAD object to be checked.
        recursive expects True/False which determines whether the group membership will be searched recursively."""
    user_list = self.get_members(recursive=recursive, ignoreGroups=False)

    for checked_member in user_list:
        user = 'cn=' + check_member
        if user == checked_member.prefixed_cn:
            is_true = True
            break
        else:
            is_true = False

    if is_true == True:
        return True
    else:
        return False
BobSquarePants commented 4 years ago

@dexxfm Still give False every time :/

Andrewkha commented 4 years ago

I use a workaround - checking if the guid_str of the user object exists in the list of guid_str of all group members. The only issue is that get_members() is slow...

pdl_members = pdl_obj.get_members()
if candidate.ad_user.guid_str in [member.guid_str for member in pdl_members]: