Sample: Changing Default Users for Custom View
This sample illustrates how to change the default users for a custom view
Both the Python and C# transformer classes inherit from a base class that handles the core functionality, then create versions for IPublishableCustomView
.
To implement the tag addition in Python, you can utilize the following transformer class:
from tableau_migration import (
ContentTransformerBase,
IContentReference,
IPublishableCustomView
)
class CustomViewDefaultUsersTransformer(ContentTransformerBase[IPublishableCustomView]):
#Pass in list of users retrieved from Users API
default_users = []
def transform(self, itemToTransform: IPublishableCustomView) -> IPublishableCustomView:
itemToTransform.default_users = self.default_users
return itemToTransform
Registration
For detailed instructions on registering the transformer, refer to the documentation.
plan_builder.transformers.add(CustomViewDefaultUsersTransformer)
In C#, the transformer class for adding tags is implemented as shown below:
public class CustomViewExcludeDefaultUserTransformer(
ISharedResourcesLocalizer localizer,
ILogger<CustomViewExcludeDefaultUserTransformer> logger)
: ContentTransformerBase<IPublishableCustomView>(localizer, logger)
{
public IList<string> ExcludeUsernames { get; } = new List<string>() {"User1", "User2"};
private readonly ILogger<CustomViewExcludeDefaultUserTransformer>? _logger = logger;
public override async Task<IPublishableCustomView?> TransformAsync(IPublishableCustomView itemToTransform, CancellationToken cancel)
{
var newDefaultUsers = itemToTransform.DefaultUsers.Where(user => !ExcludeUsernames.Contains(user.Name)).ToList();
itemToTransform.DefaultUsers = newDefaultUsers;
_logger?.LogInformation(
@"Excluding default users {newDefaultUsers}",
newDefaultUsers);
return await Task.FromResult(itemToTransform);
}
}
Registration
To register the transformer in C#, follow the guidance provided in the documentation.
_planBuilder.Transformers.Add<CustomViewExcludeDefaultUserTransformer, IPublishableCustomView>();
Dependency Injection
Learn more about dependency injection here.
services.AddScoped<CustomViewExcludeDefaultUserTransformer>();