Commit 5983b0b8 authored by Jo Sama's avatar Jo Sama 😱
Browse files

Allow str as identifier in group membership ops

parent da0a42c3
......@@ -3,7 +3,7 @@ import requests
import uuid
import json
from typing import Optional, List, Iterator
from typing import Optional, List, Iterator, Union
from urllib.parse import urljoin, urlparse
from .models import (Branch, BranchReference, Operator, OperatorGroup, PermissionGroup,
......@@ -390,18 +390,36 @@ class TopDeskClient:
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)
@staticmethod
def _select_group_id_by_type(group: Union[OperatorGroup, PermissionGroup, str]):
if isinstance(group, str):
return str
else:
return group.id
def add_operator_to_operator_group(self, operator: Operator, operator_group: Union[OperatorGroup, str]):
return self._do_group_op(self.urls.get_operators_operatorgroup,
operator.id,
self._select_group_id_by_type(operator_group),
self.post)
def add_operator_to_permission_group(self, operator: Operator, permission_group: Union[PermissionGroup, str]):
return self._do_group_op(self.urls.get_operators_permissiongroup,
operator.id,
self._select_group_id_by_type(permission_group),
self.post)
def remove_operator_from_operator_group(self, operator: Operator, operator_group: Union[OperatorGroup, str]):
return self._do_group_op(self.urls.get_operators_operatorgroup,
operator.id,
self._select_group_id_by_type(operator_group),
self.delete)
def remove_operator_from_permission_group(self, operator: Operator, permission_group: Union[PermissionGroup, str]):
return self._do_group_op(self.urls.get_operators_permissiongroup,
operator.id,
self._select_group_id_by_type(permission_group),
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