Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions tableauserverclient/models/group_item.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Callable, Optional, TYPE_CHECKING

from defusedxml.ElementTree import fromstring
from typing_extensions import Self

from .exceptions import UnpopulatedPropertyError
from .property_decorators import property_not_empty, property_is_enum
Expand Down Expand Up @@ -157,3 +158,8 @@ def from_response(cls, resp, ns) -> list["GroupItem"]:
@staticmethod
def as_reference(id_: str) -> ResourceReference:
return ResourceReference(id_, GroupItem.tag_name)

def to_reference(self: Self) -> ResourceReference:
if self.id is None:
raise ValueError("UserItem must have id to be converted to reference")
return ResourceReference(self.id, self.tag_name)
6 changes: 6 additions & 0 deletions tableauserverclient/models/groupset_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import xml.etree.ElementTree as ET

from defusedxml.ElementTree import fromstring
from typing_extensions import Self

from tableauserverclient.models.group_item import GroupItem
from tableauserverclient.models.reference_item import ResourceReference
Expand Down Expand Up @@ -51,3 +52,8 @@ def get_group(group_xml: ET.Element) -> GroupItem:
@staticmethod
def as_reference(id_: str) -> ResourceReference:
return ResourceReference(id_, GroupSetItem.tag_name)

def to_reference(self: Self) -> ResourceReference:
if self.id is None:
raise ValueError("UserItem must have id to be converted to reference")
return ResourceReference(self.id, self.tag_name)
18 changes: 12 additions & 6 deletions tableauserverclient/models/reference_item.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from typing_extensions import Self


class ResourceReference:
def __init__(self, id_, tag_name):
def __init__(self, id_: str | None, tag_name: str) -> None:
self.id = id_
self.tag_name = tag_name

def __str__(self):
def __str__(self) -> str:
return f"<ResourceReference id={self._id} tag={self._tag_name}>"

__repr__ = __str__
Expand All @@ -13,18 +16,21 @@ def __eq__(self, other: object) -> bool:
return False
return (self.id == other.id) and (self.tag_name == other.tag_name)

def __hash__(self: Self) -> int:
return hash((self.id, self.tag_name))

@property
def id(self):
def id(self) -> str | None:
return self._id

@id.setter
def id(self, value):
def id(self, value: str | None) -> None:
self._id = value

@property
def tag_name(self):
def tag_name(self) -> str:
return self._tag_name

@tag_name.setter
def tag_name(self, value):
def tag_name(self, value: str) -> None:
self._tag_name = value
6 changes: 6 additions & 0 deletions tableauserverclient/models/user_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional, TYPE_CHECKING

from defusedxml.ElementTree import fromstring
from typing_extensions import Self

from tableauserverclient.datetime_helpers import parse_datetime
from tableauserverclient.models.site_item import SiteAuthConfiguration
Expand Down Expand Up @@ -377,6 +378,11 @@ def _parse_xml(cls, element_name, resp, ns):
def as_reference(id_) -> ResourceReference:
return ResourceReference(id_, UserItem.tag_name)

def to_reference(self: Self) -> ResourceReference:
if self.id is None:
raise ValueError("UserItem must have id to be converted to reference")
return ResourceReference(self.id, self.tag_name)

@staticmethod
def _parse_element(user_xml, ns):
id = user_xml.get("id", None)
Expand Down
5 changes: 4 additions & 1 deletion tableauserverclient/server/request_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,10 @@ def add_req(self, rules: Iterable[PermissionsRule]) -> bytes:
for rule in rules:
grantee_capabilities_element = ET.SubElement(permissions_element, "granteeCapabilities")
grantee_element = ET.SubElement(grantee_capabilities_element, rule.grantee.tag_name)
grantee_element.attrib["id"] = rule.grantee.id
if rule.grantee.id is not None:
grantee_element.attrib["id"] = rule.grantee.id
else:
raise ValueError("Grantee must have an ID")

capabilities_element = ET.SubElement(grantee_capabilities_element, "capabilities")
self._add_all_capabilities(capabilities_element, rule.capabilities)
Expand Down
Loading