Delete default permissions methods for project (for WB, DS, Flow etc) not working for TSC
Describe the bug I am using the TSC methods to delete the default permissions method for WB, DS etc and it is throwing an error message. Only the delete project permissions method is working but the delete permissions method for WB, DS and Flow for a project is failing.
Versions I tried it for both 0.24 and 0.25 (latest) and it fails.
To Reproduce Use the following code. You will have to uncomment or comment certain lines based on what methods you want to call.
import hvac import sys import argparse import getpass import os import re import smtplib import tableauserverclient as TSC import csv import docopt from configparser import ConfigParser import logging.config def main(): print('Hello World') tabuname = 'abcd' tabuserpwd = 'xxxx' tabsite = 'Test' tabserver = 'https://server.com/' tableau_auth = TSC.TableauAuth(tabuname, tabuserpwd, tabsite) server = TSC.Server(tabserver, use_server_version=False) server.add_http_options({'verify': False}) # change the REST API version to match the server server.use_server_version() print(f'Server: {tabserver} : username: {tabuname} site: {tabsite} (blank means default) tabuserpwd:{tabuserpwd} ') with server.auth.sign_in(tableau_auth): # Loop through and find out the schedules print(f'TabServer Logged in...') #exit() #tabserver = 'https://10ax.online.tableau.com/' #tableau_auth = TSC.PersonalAccessTokenAuth('Nirav2023-05', 'PATTOKEN') #server = TSC.Server(tabserver, use_server_version=False) #server.add_http_options({'verify': True}) ## change the REST API version to match the server #server.use_server_version() with server.auth.sign_in(tableau_auth): print(f'Start:Projects metadata collection') projs = list(TSC.Pager(server.projects)) WBs = list(TSC.Pager(server.workbooks)) DSs = list(TSC.Pager(server.datasources)) #users = list(TSC.Pager(server.users)) for wb in WBs: if wb.name == 'dsNirav2_WB': wbFound = wb print(f'TabCloud wbFound.name={wbFound.name}, project={wbFound.project_name}') for proj in projs: if proj.name == 'xNiravTest1': project1 = proj if proj.name == 'xNiravTest2': project2 = proj print(f'Project1={project1.name}, Project2={project2.name}') # Delete existing permissions of Project2 first # #server.projects.populate_workbook_default_permissions(project1) #tgtpermissions = project1.default_workbook_permissions server.projects.populate_permissions(project1) tgtpermissions = project1.permissions #server.projects.populate_datasource_default_permissions(project1) #tgtpermissions = project1.default_datasource_permissions print(f'tgtpermissions:{tgtpermissions}', {len(tgtpermissions)}) for permission in tgtpermissions: grantee = permission.grantee capabilities = permission.capabilities tgt_del_rules = [TSC.PermissionsRule(grantee, capabilities)] print(f'grantee={grantee} , capabilities={capabilities}') server.projects.delete_permission(project1, tgt_del_rules) #server.projects.delete_workbook_default_permissions(project1, tgt_del_rules) #server.projects.delete_datasource_default_permissions(project1, tgt_del_rules)
Results What are the results or error messages received? When I call the delete_workbook_default_permissions or delete_datasource_default_permissions etc. Then I get the following error message : 'list' object has no attribute 'capabilities'
NOTE: Be careful not to post user names, passwords, auth tokens or any other private or sensitive information.
Forgot to add. These methods do not work for both the on-prem as well as TabCloud. The server names, username and the pwd or the personal access token are all imaginary. Please replace them with the right credentials for your environment to try it out. Thanks.
It looks like your problem is that projects.delete_permission takes a list of rules, and delete_x_default_permissions takes only one rule. We should add typings for these methods; currently the only hint there is the names of the parameters:
server.projects.delete_permission(self, item, rules) server.projects.delete_datasource_default_permissions(self, item, rule)
How should the "rule" be supplied (as opposed to "rules") for the delete_datasource_default_permissions? The rules is an instantiation of [TSC.PermissionsRule(grantee, capabilities)], where capabilities is a dictionary and grantee is UserItem or GroupItem. Reducing capabilities to one capability at a time will still require a dictionary but with only one capability? Not sure how to make it work. Can you please elaborate?
Either the documentation or the code is wrong. (and based on the implementation "update_permission", I guess it's the code)
The documentation clearly states:
Parameters
| Name | Description |
|---|---|
| item | A project object. |
| rules | A list of PermissionsRule objects or a single PermissionsRule object. |
While in the code, the method header does not use a "Sequence" when compared to the update method.
def update_default_permissions(
self, resource: BaseItem, permissions: Sequence[PermissionsRule], content_type: Resource
) -> List[PermissionsRule]:
# vs
def delete_default_permission(self, resource: BaseItem, rule: PermissionsRule, content_type: Resource) -> None:
The docs were wrong. I have opened a pull request to correct the error.