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
59afded1
Commit
59afded1
authored
Nov 18, 2019
by
Jo Sama
😱
Browse files
Add {operator,permission}group member management
parent
d563b454
Changes
1
Hide whitespace changes
Inline
Side-by-side
topdesk_client/client.py
View file @
59afded1
...
...
@@ -48,6 +48,18 @@ class Endpoints:
def
get_persons
(
self
):
return
self
.
_prepend_base_url
(
'persons/'
)
def
get_operators_operatorgroup
(
self
,
operator_id
):
return
urljoin
(
urljoin
(
self
.
_prepend_base_url
(
'operators/id/'
),
operator_id
+
'/'
),
'operatorgroups'
)
def
get_operators_permissiongroup
(
self
,
operator_id
):
return
urljoin
(
urljoin
(
self
.
_prepend_base_url
(
'operators/id/'
),
operator_id
+
'/'
),
'permissiongroups'
)
class
TopDeskClient
:
def
__init__
(
self
,
...
...
@@ -108,6 +120,9 @@ class TopDeskClient:
def
patch
(
self
,
url
,
**
kwargs
):
return
self
.
call
(
'PATCH'
,
url
,
**
kwargs
)
def
delete
(
self
,
url
,
**
kwargs
):
return
self
.
call
(
'DELETE'
,
url
,
**
kwargs
)
def
depaginate
(
self
,
url
,
page_size
=
100
):
offset
=
0
while
True
:
...
...
@@ -330,6 +345,30 @@ class TopDeskClient:
return
Branch
.
from_dict
(
r
.
json
())
return
None
def
_do_group_op
(
self
,
url_generator
,
operator_id
,
group_id
,
operation
):
url
=
url_generator
(
operator_id
)
r
=
operation
(
url
,
return_response
=
True
,
json
=
[{
'id'
:
group_id
}])
if
r
.
status_code
==
204
:
return
None
else
:
r
.
raise_for_status
()
return
r
def
add_operator_to_operator_group
(
self
,
operator
:
Operator
,
operator_group
:
OperatorGroup
):
return
self
.
_do_group_op
(
self
.
urls
.
get_operators_operatorgroup
,
operator
.
id
,
operator_group
.
id
,
self
.
post
)
def
add_operator_to_permission_group
(
self
,
operator
:
Operator
,
permission_group
:
PermissionGroup
):
return
self
.
_do_group_op
(
self
.
urls
.
get_operators_permissiongroup
,
operator
.
id
,
permission_group
.
id
,
self
.
post
)
def
remove_operator_from_operator_group
(
self
,
operator
:
Operator
,
operator_group
:
OperatorGroup
):
return
self
.
_do_group_op
(
self
.
urls
.
get_operators_operatorgroup
,
operator
.
id
,
operator_group
.
id
,
self
.
delete
)
def
remove_operator_from_permission_group
(
self
,
operator
:
Operator
,
permission_group
:
PermissionGroup
):
return
self
.
_do_group_op
(
self
.
urls
.
get_operators_permissiongroup
,
operator
.
id
,
permission_group
.
id
,
self
.
delete
)
def
get_client
(
config
):
return
TopDeskClient
(
**
config
)
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