Beispiel #1
0
    def test_update_datasource_default_permission(self):
        response_xml = read_xml_asset(UPDATE_DATASOURCE_DEFAULT_PERMISSIONS_XML)
        with requests_mock.mock() as m:
            m.put(self.baseurl + '/b4065286-80f0-11ea-af1b-cb7191f48e45/default-permissions/datasources',
                  text=response_xml)
            project = TSC.ProjectItem('test-project')
            project._id = 'b4065286-80f0-11ea-af1b-cb7191f48e45'

            group = TSC.GroupItem('test-group')
            group._id = 'b4488bce-80f0-11ea-af1c-976d0c1dab39'

            capabilities = {TSC.Permission.Capability.ExportXml: TSC.Permission.Mode.Deny}

            rules = [TSC.PermissionsRule(
                grantee=group,
                capabilities=capabilities
            )]

            new_rules = self.server.projects.update_datasource_default_permissions(project, rules)

        self.assertEquals('b4488bce-80f0-11ea-af1c-976d0c1dab39', new_rules[0].grantee.id)

        updated_capabilities = new_rules[0].capabilities
        self.assertEquals(4, len(updated_capabilities))
        self.assertEquals('Deny', updated_capabilities['ExportXml'])
        self.assertEquals('Allow', updated_capabilities['Read'])
        self.assertEquals('Allow', updated_capabilities['Write'])
        self.assertEquals('Allow', updated_capabilities['Connect'])
Beispiel #2
0
    def test_delete_permission(self):
        with open(asset(POPULATE_PERMISSIONS_XML), 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl + '/0448d2ed-590d-4fa0-b272-a2a8a24555b5/permissions', text=response_xml)

            single_group = TSC.GroupItem('Group1')
            single_group._id = 'c8f2773a-c83a-11e8-8c8f-33e6d787b506'

            single_project = TSC.ProjectItem('Project3')
            single_project._id = '0448d2ed-590d-4fa0-b272-a2a8a24555b5'

            self.server.projects.populate_permissions(single_project)
            permissions = single_project.permissions

            capabilities = {}

            for permission in permissions:
                if permission.grantee.tag_name == "group":
                    if permission.grantee.id == single_group._id:
                        capabilities = permission.capabilities

            rules = TSC.PermissionsRule(
                grantee=single_group,
                capabilities=capabilities
            )

            endpoint = '{}/permissions/groups/{}'.format(single_project._id, single_group._id)
            m.delete('{}/{}/Read/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/Write/Allow'.format(self.baseurl, endpoint), status_code=204)
            self.server.projects.delete_permission(item=single_project, rules=rules)
    def test_delete_permission(self) -> None:
        with open(asset(POPULATE_PERMISSIONS_XML), "rb") as f:
            response_xml = f.read().decode("utf-8")
        with requests_mock.mock() as m:
            m.get(self.baseurl +
                  "/0448d2ed-590d-4fa0-b272-a2a8a24555b5/permissions",
                  text=response_xml)

            single_group = TSC.GroupItem("Group1")
            single_group._id = "c8f2773a-c83a-11e8-8c8f-33e6d787b506"

            single_project = TSC.ProjectItem("Project3")
            single_project._id = "0448d2ed-590d-4fa0-b272-a2a8a24555b5"

            self.server.projects.populate_permissions(single_project)
            permissions = single_project.permissions

            capabilities = {}

            for permission in permissions:
                if permission.grantee.tag_name == "group":
                    if permission.grantee.id == single_group._id:
                        capabilities = permission.capabilities

            rules = TSC.PermissionsRule(grantee=single_group.to_reference(),
                                        capabilities=capabilities)

            endpoint = "{}/permissions/groups/{}".format(
                single_project._id, single_group._id)
            m.delete("{}/{}/Read/Allow".format(self.baseurl, endpoint),
                     status_code=204)
            m.delete("{}/{}/Write/Allow".format(self.baseurl, endpoint),
                     status_code=204)
            self.server.projects.delete_permission(item=single_project,
                                                   rules=rules)
    def test_update_datasource_default_permission(self) -> None:
        response_xml = read_xml_asset(
            UPDATE_DATASOURCE_DEFAULT_PERMISSIONS_XML)
        with requests_mock.mock() as m:
            m.put(
                self.baseurl +
                "/b4065286-80f0-11ea-af1b-cb7191f48e45/default-permissions/datasources",
                text=response_xml,
            )
            project = TSC.ProjectItem("test-project")
            project._id = "b4065286-80f0-11ea-af1b-cb7191f48e45"

            group = TSC.GroupItem("test-group")
            group._id = "b4488bce-80f0-11ea-af1c-976d0c1dab39"

            capabilities = {
                TSC.Permission.Capability.ExportXml: TSC.Permission.Mode.Deny
            }

            rules = [
                TSC.PermissionsRule(grantee=group.to_reference(),
                                    capabilities=capabilities)
            ]

            new_rules = self.server.projects.update_datasource_default_permissions(
                project, rules)

        self.assertEqual("b4488bce-80f0-11ea-af1c-976d0c1dab39",
                         new_rules[0].grantee.id)

        updated_capabilities = new_rules[0].capabilities
        self.assertEqual(4, len(updated_capabilities))
        self.assertEqual("Deny", updated_capabilities["ExportXml"])
        self.assertEqual("Allow", updated_capabilities["Read"])
        self.assertEqual("Allow", updated_capabilities["Write"])
        self.assertEqual("Allow", updated_capabilities["Connect"])
def main():
    parser = argparse.ArgumentParser(
        description='Add workbook default permission for a given project')
    parser.add_argument('--server', '-s', required=True, help='Server address')
    parser.add_argument('--username',
                        '-u',
                        required=True,
                        help='Username to sign into server')
    parser.add_argument(
        '--site',
        '-S',
        default=None,
        help='Site to sign into - default site if not provided')
    parser.add_argument('-p',
                        default=None,
                        help='Password to sign into server')

    parser.add_argument('--logging-level',
                        '-l',
                        choices=['debug', 'info', 'error'],
                        default='error',
                        help='desired logging level (set to error by default)')

    args = parser.parse_args()

    if args.p is None:
        password = getpass.getpass("Password: "******"sample_project")
        project = server.projects.create(project)

        # Query for existing workbook default-permissions
        server.projects.populate_workbook_default_permissions(project)
        default_permissions = project.default_workbook_permissions[
            0]  # new projects have 1 grantee group

        # Add "ExportXml (Allow)" workbook capability to "All Users" default group if it does not already exist
        if TSC.Permission.Capability.ExportXml not in default_permissions.capabilities:
            new_capabilities = {
                TSC.Permission.Capability.ExportXml: TSC.Permission.Mode.Allow
            }

            # Each PermissionRule in the list contains a grantee and a dict of capabilities
            new_rules = [
                TSC.PermissionsRule(grantee=default_permissions.grantee,
                                    capabilities=new_capabilities)
            ]

            new_default_permissions = server.projects.update_workbook_default_permissions(
                project, new_rules)

            # Print result from adding a new default permission
            for permission in new_default_permissions:
                grantee = permission.grantee
                capabilities = permission.capabilities
                print("\nCapabilities for {0} {1}:".format(
                    grantee.tag_name, grantee.id))

                for capability in capabilities:
                    print("\t{0} - {1}".format(capability,
                                               capabilities[capability]))
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser(
        description="Add workbook default permissions for a given project.")
    # Common options; please keep those in sync across all samples
    parser.add_argument("--server", "-s", required=True, help="server address")
    parser.add_argument("--site", "-S", help="site name")
    parser.add_argument(
        "--token-name",
        "-p",
        required=True,
        help="name of the personal access token used to sign into the server")
    parser.add_argument(
        "--token-value",
        "-v",
        required=True,
        help="value of the personal access token used to sign into the server")
    parser.add_argument(
        "--logging-level",
        "-l",
        choices=["debug", "info", "error"],
        default="error",
        help="desired logging level (set to error by default)",
    )
    # Options specific to this sample
    # This sample has no additional options, yet. If you add some, please add them here

    args = parser.parse_args()

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    # Sign in to server
    tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name,
                                               args.token_value,
                                               site_id=args.site)
    server = TSC.Server(args.server, use_server_version=True)
    with server.auth.sign_in(tableau_auth):

        # Create a sample project
        project = TSC.ProjectItem("sample_project")
        project = server.projects.create(project)

        # Query for existing workbook default-permissions
        server.projects.populate_workbook_default_permissions(project)
        default_permissions = project.default_workbook_permissions[
            0]  # new projects have 1 grantee group

        # Add "ExportXml (Allow)" workbook capability to "All Users" default group if it does not already exist
        if TSC.Permission.Capability.ExportXml not in default_permissions.capabilities:
            new_capabilities = {
                TSC.Permission.Capability.ExportXml: TSC.Permission.Mode.Allow
            }

            # Each PermissionRule in the list contains a grantee and a dict of capabilities
            new_rules = [
                TSC.PermissionsRule(grantee=default_permissions.grantee,
                                    capabilities=new_capabilities)
            ]

            new_default_permissions = server.projects.update_workbook_default_permissions(
                project, new_rules)

            # Print result from adding a new default permission
            for permission in new_default_permissions:
                grantee = permission.grantee
                capabilities = permission.capabilities
                print("\nCapabilities for {0} {1}:".format(
                    grantee.tag_name, grantee.id))

                for capability in capabilities:
                    print("\t{0} - {1}".format(capability,
                                               capabilities[capability]))
Beispiel #7
0
    def test_delete_workbook_default_permission(self):
        with open(asset(POPULATE_WORKBOOK_DEFAULT_PERMISSIONS_XML), 'rb') as f:
            response_xml = f.read().decode('utf-8')

        with requests_mock.mock() as m:
            m.get(self.baseurl + '/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb/default-permissions/workbooks',
                  text=response_xml)

            single_group = TSC.GroupItem('Group1')
            single_group._id = 'c8f2773a-c83a-11e8-8c8f-33e6d787b506'

            single_project = TSC.ProjectItem('test', '1d0304cd-3796-429f-b815-7258370b9b74')
            single_project.owner_id = 'dd2239f6-ddf1-4107-981a-4cf94e415794'
            single_project._id = '9dbd2263-16b5-46e1-9c43-a76bb8ab65fb'

            self.server.projects.populate_workbook_default_permissions(single_project)
            permissions = single_project.default_workbook_permissions

            capabilities = {
                # View
                TSC.Permission.Capability.Read: TSC.Permission.Mode.Allow,
                TSC.Permission.Capability.ExportImage: TSC.Permission.Mode.Allow,
                TSC.Permission.Capability.ExportData: TSC.Permission.Mode.Allow,
                TSC.Permission.Capability.ViewComments: TSC.Permission.Mode.Allow,
                TSC.Permission.Capability.AddComment: TSC.Permission.Mode.Allow,

                # Interact/Edit
                TSC.Permission.Capability.Filter: TSC.Permission.Mode.Allow,
                TSC.Permission.Capability.ViewUnderlyingData: TSC.Permission.Mode.Deny,
                TSC.Permission.Capability.ShareView: TSC.Permission.Mode.Allow,
                TSC.Permission.Capability.WebAuthoring: TSC.Permission.Mode.Allow,

                # Edit
                TSC.Permission.Capability.Write: TSC.Permission.Mode.Allow,
                TSC.Permission.Capability.ExportXml: TSC.Permission.Mode.Allow,
                TSC.Permission.Capability.ChangeHierarchy: TSC.Permission.Mode.Allow,
                TSC.Permission.Capability.Delete: TSC.Permission.Mode.Deny,
                TSC.Permission.Capability.ChangePermissions: TSC.Permission.Mode.Allow
            }

            rules = TSC.PermissionsRule(
                grantee=single_group,
                capabilities=capabilities
            )

            endpoint = '{}/default-permissions/workbooks/groups/{}'.format(single_project._id, single_group._id)
            m.delete('{}/{}/Read/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/ExportImage/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/ExportData/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/ViewComments/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/AddComment/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/Filter/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/ViewUnderlyingData/Deny'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/ShareView/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/WebAuthoring/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/Write/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/ExportXml/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/ChangeHierarchy/Allow'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/Delete/Deny'.format(self.baseurl, endpoint), status_code=204)
            m.delete('{}/{}/ChangePermissions/Allow'.format(self.baseurl, endpoint), status_code=204)
            self.server.projects.delete_workbook_default_permissions(item=single_project, rule=rules)