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
16 changes: 15 additions & 1 deletion tableauserverclient/models/workbook_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ class as arguments. The workbook item specifies the project.
User-defined description of the workbook.

encrypt_extracts : bool | None
Indicates whether extracts are encrypted.
Assign this before publishing to send ``encryptExtracts``. ``True``
encrypts the workbook's extracts and ``False`` leaves them unencrypted.
``None`` omits the attribute. A value read from the server is kept on
the item but is not sent on publish until this property is assigned.
Assign ``None`` to omit it again after a previous assignment. The
server rejects ``false`` on a site that enforces encryption (409037)
and ``true`` on a site where encryption is disabled (409036).

has_extracts : bool | None
Indicates whether the workbook has extracts.
Expand Down Expand Up @@ -169,6 +175,7 @@ def __init__(
self._owner: UserItem | None = None
self._location: LocationItem | None = None
self._encrypt_extracts: bool | None = None
self._encrypt_extracts_assigned = False
self._default_view_id: str | None = None
self._share_description: str | None = None
self._last_published_at: datetime.datetime | None = None
Expand Down Expand Up @@ -357,6 +364,13 @@ def location(self) -> LocationItem | None:
def encrypt_extracts(self) -> bool | None:
return self._encrypt_extracts

@encrypt_extracts.setter
def encrypt_extracts(self, value: bool | None) -> None:
if value is not None and not isinstance(value, bool):
raise ValueError("Boolean expected for encrypt_extracts flag.")
self._encrypt_extracts = value
self._encrypt_extracts_assigned = True

@property
def default_view_id(self) -> str | None:
return self._default_view_id
Expand Down
2 changes: 2 additions & 0 deletions tableauserverclient/server/request_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,8 @@ def _generate_xml(
workbook_element.attrib["name"] = workbook_item.name
if workbook_item.show_tabs:
workbook_element.attrib["showTabs"] = str(workbook_item.show_tabs).lower()
if workbook_item._encrypt_extracts_assigned and workbook_item.encrypt_extracts is not None:
workbook_element.attrib["encryptExtracts"] = str(workbook_item.encrypt_extracts).lower()
project_element = ET.SubElement(workbook_element, "project")
project_element.attrib["id"] = str(workbook_item.project_id)

Expand Down
39 changes: 39 additions & 0 deletions test/test_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,45 @@ def test_publish_file_object_of_unknown_type_raises_exception(server: TSC.Server
server.workbooks.publish(new_workbook, file_object, server.PublishMode.CreateNew)


def test_publish_sends_encrypt_extracts_when_set(server: TSC.Server) -> None:
new_workbook = TSC.WorkbookItem(name="Sample", show_tabs=False, project_id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760")
omitted = RequestFactory.Workbook._generate_xml(new_workbook)
assert "encryptExtracts" not in fromstring(omitted).find("workbook").attrib

new_workbook.encrypt_extracts = True
encrypted = RequestFactory.Workbook._generate_xml(new_workbook)
assert fromstring(encrypted).find("workbook").get("encryptExtracts") == "true"

new_workbook.encrypt_extracts = False
plain = RequestFactory.Workbook._generate_xml(new_workbook)
assert fromstring(plain).find("workbook").get("encryptExtracts") == "false"

new_workbook.encrypt_extracts = None
cleared = RequestFactory.Workbook._generate_xml(new_workbook)
assert "encryptExtracts" not in fromstring(cleared).find("workbook").attrib

with pytest.raises(ValueError):
new_workbook.encrypt_extracts = "true" # type: ignore[assignment]


def test_publish_does_not_send_encrypt_extracts_read_from_the_server(server: TSC.Server) -> None:
response = """
<tsResponse xmlns="http://tableau.com/api">
<workbook id="wb-1" name="Sample" encryptExtracts="true">
<project id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760"/>
</workbook>
</tsResponse>
"""
fetched = TSC.WorkbookItem.from_response(response, server.namespace)[0]
assert fetched.encrypt_extracts is True
omitted = RequestFactory.Workbook._generate_xml(fetched)
assert "encryptExtracts" not in fromstring(omitted).find("workbook").attrib

fetched.encrypt_extracts = False
chosen = RequestFactory.Workbook._generate_xml(fetched)
assert fromstring(chosen).find("workbook").get("encryptExtracts") == "false"


def test_publish_multi_connection(server: TSC.Server) -> None:
new_workbook = TSC.WorkbookItem(name="Sample", show_tabs=False, project_id="ee8c6e70-43b6-11e6-af4f-f7b0d8e20760")
connection1 = TSC.ConnectionItem()
Expand Down