Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

username as default self-hosted field for current_user() #1200

Merged
merged 3 commits into from
Nov 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3828,15 +3828,15 @@ def backup_download(self, filename: str = None):
return None

def current_user(self, field: Optional[str] = None) -> str:
"""Returns the username or emailAddress of the current user. For anonymous
users it will return a value that evaluates as False.
"""Return the `accountId` (Cloud) else `username` of the current user.
For anonymous users it will return a value that evaluates as False.

Args:
field (Optional[str]): the name of the identifier field.
Defaults to "accountId" for Jira Cloud, else "key"
Defaults to "accountId" for Jira Cloud, else "username"

Returns:
str
str: User's `accountId` (Cloud) else `username`.
"""
if not hasattr(self, "_myself"):

Expand All @@ -3847,7 +3847,9 @@ def current_user(self, field: Optional[str] = None) -> str:
self._myself = r_json

if field is None:
field = "accountId" if self._is_cloud else "key"
# Note: For Self-Hosted 'displayName' can be changed,
# but 'name' and 'key' cannot, so should be identifying properties.
field = "accountId" if self._is_cloud else "name"

return self._myself[field]

Expand Down