Skip to content

Commit

Permalink
Feature/mx 1660 ldap search endpoint (#350)
Browse files Browse the repository at this point in the history
# Changes
- updated ldap search from name and familyname to one single attribute
"displayname"

---------

Signed-off-by: vyvytranngoc <[email protected]>
Co-authored-by: Nicolas Drebenstedt <[email protected]>
  • Loading branch information
vyvytranngoc and cutoffthetop authored Dec 12, 2024
1 parent ddded85 commit 74bbb48
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changes

- updated ldap search from name and familyname to one single attribute "displayname"

### Deprecated

### Removed
Expand Down
16 changes: 6 additions & 10 deletions mex/common/ldap/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,38 +116,34 @@ def get_merged_ids_by_query_string(


def get_persons_by_name(
surname: str = "*",
given_name: str = "*",
display_name: str = "*",
**filters: str,
) -> Generator[LDAPPerson, None, None]:
"""Get all ldap persons matching the filters.
Args:
given_name: Given name of a person, defaults to non-null.
surname: Surname of a person, defaults to non-null.
display_name: Full name of the searched person, defaults to non-null.
**filters: Additional filters.
Returns:
Generator for LDAP persons.
"""
connector = LDAPConnector.get()
return connector.get_persons(surname, given_name, **filters)
return connector.get_persons(displayName=display_name, **filters)


def get_count_of_found_persons_by_name(
surname: str = "*",
given_name: str = "*",
display_name: str = "*",
**filters: str,
) -> int:
"""Get total count of found ldap persons.
Args:
given_name: Given name of a person, defaults to non-null.
surname: Surname of a person, defaults to non-null.
display_name: Full name of the searched person, defaults to non-null.
**filters: Additional filters.
Returns:
count of found persons.
"""
connector = LDAPConnector.get()
return len(list(connector.get_persons(surname, given_name, **filters)))
return len(list(connector.get_persons(displayName=display_name, **filters)))
6 changes: 2 additions & 4 deletions tests/ldap/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def test_get_merged_ids_by_query_string(

def test_get_persons_by_name_mocked(ldap_mocker: LDAPMocker) -> None:
ldap_mocker([[SAMPLE_PERSON_ATTRS]])
persons = get_persons_by_name(surname="Sample", given_name="Sam")
persons = get_persons_by_name(display_name="Sam Sample")
persons_list = list(persons)
expected = {
"company": "RKI",
Expand All @@ -204,7 +204,5 @@ def test_get_persons_by_name_mocked(ldap_mocker: LDAPMocker) -> None:

def test_get_count_of_found_persons_by_name_mocked(ldap_mocker: LDAPMocker) -> None:
ldap_mocker([[SAMPLE_PERSON_ATTRS]])
persons_count = get_count_of_found_persons_by_name(
surname="Sample", given_name="Sam"
)
persons_count = get_count_of_found_persons_by_name(display_name="Sam Sample")
assert persons_count == 1

0 comments on commit 74bbb48

Please sign in to comment.