Skip to content

Commit

Permalink
Adding project permissions handling for databases and tables
Browse files Browse the repository at this point in the history
  • Loading branch information
TrimPeachu committed Sep 17, 2024
1 parent 8eb95f2 commit 40bc833
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
40 changes: 24 additions & 16 deletions tableauserverclient/models/project_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class ProjectItem(object):
ERROR_MSG = "Project item must be populated with permissions first."

class ContentPermissions:
LockedToProject: str = "LockedToProject"
ManagedByOwner: str = "ManagedByOwner"
Expand Down Expand Up @@ -44,6 +46,8 @@ def __init__(
self._default_datarole_permissions = None
self._default_metric_permissions = None
self._default_virtualconnection_permissions = None
self._default_database_permissions = None
self._default_table_permissions = None

@property
def content_permissions(self):
Expand All @@ -57,59 +61,63 @@ def content_permissions(self, value: Optional[str]) -> None:
@property
def permissions(self):
if self._permissions is None:
error = "Project item must be populated with permissions first."
raise UnpopulatedPropertyError(error)
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._permissions()

@property
def default_datasource_permissions(self):
if self._default_datasource_permissions is None:
error = "Project item must be populated with permissions first."
raise UnpopulatedPropertyError(error)
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._default_datasource_permissions()

@property
def default_workbook_permissions(self):
if self._default_workbook_permissions is None:
error = "Project item must be populated with permissions first."
raise UnpopulatedPropertyError(error)
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._default_workbook_permissions()

@property
def default_flow_permissions(self):
if self._default_flow_permissions is None:
error = "Project item must be populated with permissions first."
raise UnpopulatedPropertyError(error)
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._default_flow_permissions()

@property
def default_lens_permissions(self):
if self._default_lens_permissions is None:
error = "Project item must be populated with permissions first."
raise UnpopulatedPropertyError(error)
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._default_lens_permissions()

@property
def default_datarole_permissions(self):
if self._default_datarole_permissions is None:
error = "Project item must be populated with permissions first."
raise UnpopulatedPropertyError(error)
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._default_datarole_permissions()

@property
def default_metric_permissions(self):
if self._default_metric_permissions is None:
error = "Project item must be populated with permissions first."
raise UnpopulatedPropertyError(error)
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._default_metric_permissions()

@property
def default_virtualconnection_permissions(self):
if self._default_virtualconnection_permissions is None:
error = "Project item must be populated with permissions first."
raise UnpopulatedPropertyError(error)
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._default_virtualconnection_permissions()

@property
def default_database_permissions(self):
if self._default_database_permissions is None:
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._default_database_permissions()

@property
def default_table_permissions(self):
if self._default_table_permissions is None:
raise UnpopulatedPropertyError(self.ERROR_MSG)
return self._default_table_permissions()

@property
def id(self) -> Optional[str]:
return self._id
Expand Down
24 changes: 24 additions & 0 deletions tableauserverclient/server/endpoint/projects_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ def populate_lens_default_permissions(self, item):
def populate_virtualconnection_default_permissions(self, item):
self._default_permissions.populate_default_permissions(item, Resource.VirtualConnection)

@api(version="3.23")
def populate_database_default_permissions(self, item):
self._default_permissions.populate_default_permissions(item, Resource.Database)

@api(version="3.23")
def populate_table_default_permissions(self, item):
self._default_permissions.populate_default_permissions(item, Resource.Table)

@api(version="2.1")
def update_workbook_default_permissions(self, item, rules):
return self._default_permissions.update_default_permissions(item, rules, Resource.Workbook)
Expand Down Expand Up @@ -141,6 +149,14 @@ def update_lens_default_permissions(self, item, rules):
def update_virtualconnection_default_permissions(self, item, rules):
return self._default_permissions.update_default_permissions(item, rules, Resource.VirtualConnection)

@api(version="3.23")
def update_database_default_permissions(self, item, rules):
return self._default_permissions.update_default_permissions(item, rules, Resource.Database)

@api(version="3.23")
def update_table_default_permissions(self, item, rules):
return self._default_permissions.update_default_permissions(item, rules, Resource.Table)

@api(version="2.1")
def delete_workbook_default_permissions(self, item, rule):
self._default_permissions.delete_default_permission(item, rule, Resource.Workbook)
Expand Down Expand Up @@ -169,6 +185,14 @@ def delete_lens_default_permissions(self, item, rule):
def delete_virtualconnection_default_permissions(self, item, rule):
self._default_permissions.delete_default_permission(item, rule, Resource.VirtualConnection)

@api(version="3.23")
def delete_database_default_permissions(self, item, rule):
self._default_permissions.delete_default_permission(item, rule, Resource.Database)

@api(version="3.23")
def delete_table_default_permissions(self, item, rule):
self._default_permissions.delete_default_permission(item, rule, Resource.Table)

def filter(self, *invalid, page_size: Optional[int] = None, **kwargs) -> QuerySet[ProjectItem]:
"""
Queries the Tableau Server for items using the specified filters. Page
Expand Down

0 comments on commit 40bc833

Please sign in to comment.