Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
it-bott-integrasjoner
topdesk-client
Commits
19cea5ff
Commit
19cea5ff
authored
Sep 17, 2019
by
Jo Sama
😱
Browse files
Make get_operator() work if no operator id
parent
19644768
Changes
1
Hide whitespace changes
Inline
Side-by-side
topdesk_client/client.py
View file @
19cea5ff
...
...
@@ -101,25 +101,33 @@ class TopDeskClient:
params
[
'$fields'
]
=
','
.
join
(
fields
)
def
get_operator
(
self
,
identity
):
if
isinstance
(
identity
,
Operator
):
url
=
self
.
urls
.
get_operator
(
ident
ity
.
id
)
def
_get_operator_by_id
(
ident
):
url
=
self
.
urls
.
get_operator
(
ident
)
r
=
self
.
get
(
url
,
return_response
=
True
)
if
r
.
status_code
==
200
:
return
Operator
.
from_dict
(
r
.
json
())
else
:
return
None
else
:
def
_get_operator_by_username
(
name
):
url
=
self
.
urls
.
get_operators
()
operators
=
[
Operator
.
from_dict
(
x
)
for
x
in
self
.
get
(
url
,
params
=
{
'topdesk_login_name'
:
identity
})]
f
=
filter
(
lambda
x
:
x
.
user_name
.
lower
()
==
identity
,
params
=
{
'topdesk_login_name'
:
name
})]
f
=
filter
(
lambda
x
:
x
.
user_name
.
lower
()
==
name
,
operators
)
try
:
return
next
(
f
)
except
StopIteration
:
return
None
if
isinstance
(
identity
,
Operator
)
and
identity
.
id
:
return
_get_operator_by_id
(
identity
.
id
)
elif
isinstance
(
identity
,
Operator
):
return
_get_operator_by_username
(
identity
.
user_name
)
else
:
return
_get_operator_by_username
(
identity
)
def
create_operator
(
self
,
operator
):
url
=
self
.
urls
.
get_operators
()
# TODO: Remove password setting when proper auth arrives
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment