Skip to content

Commit

Permalink
add User.longname attribute
Browse files Browse the repository at this point in the history
Signed-off-by: flashdagger <flashdagger@googlemail.com>
  • Loading branch information
flashdagger committed Nov 13, 2023
1 parent d527f90 commit 6266470
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
21 changes: 21 additions & 0 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ def test_user_fullname_attribute_given_firstname_and_lastname(client):
assert user.fullname == "Max Headroom"


def test_user_fullname_attribute_given_email_only(client):
user = client.users(
123, info={"id": 123, "firstname": "", "lastname": "", "email": "max@head.room"}
)
assert user.fullname == "max@head.room"


def test_user_longname_attribute(client):
user = client.users(
123,
info={
"id": 123,
"firstname": "Max",
"lastname": "Headroom",
"organization_id": 123,
},
)
client.organizations(123, info={"id": 123, "name": "Network 23"})
assert user.longname == "Max Headroom (Network 23)"


def test_user_groups_attribute(client):
user = client.users(
123,
Expand Down
15 changes: 10 additions & 5 deletions zammadoo/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ class User(NamedResource):

@property
def fullname(self) -> str:
"""users firstname and lastname combined"""
firstname, lastname = self["firstname"], self["lastname"]
return (
f"{firstname or ''}{' ' if firstname and lastname else ''}{lastname or ''}"
)
"""users firstname and lastname combined, or email"""
fullname = " ".join(filter(bool, (self["firstname"], self["lastname"])))
return fullname or self["email"]

@property
def longname(self) -> str:
"""users fullname with organization"""
fullname = self.fullname
organization = self.organization
return f"{fullname} ({organization.name})" if organization else fullname

@property
def name(self) -> str:
Expand Down

0 comments on commit 6266470

Please sign in to comment.