Commit 59afded1 authored by Jo Sama's avatar Jo Sama 😱
Browse files

Add {operator,permission}group member management

parent d563b454
......@@ -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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment