In the Strategy environment, it is a common administrative task to clean up the data associated with users who have departed or have been disabled. This includes removing their addresses from the system to maintain data hygiene and security. The manual process of doing this can be time-consuming and prone to errors.
The necessity for this script arises from the need to maintain a clean and secure database by removing the data of users who are no longer active in the system. This automated process helps in reducing the administrative burden and potential errors associated with manual data cleanup.
To automate this process, follow the steps below:
1. Connect to Your Environment: Initialize the connection to your Strategy environment.
2. Navigate to Administration: Access the administration panel to manage scripts and workflows.
3. Access Scripts Section: Go to the scripts section where you can create or modify scripts.
4. Select Your Environment: Choose the appropriate environment where the script will be executed.
5. Open Gallery Tab: In the right section of the interface, select the Gallery tab to view available workflows and scripts.
6. Expand Administration Workflows: Find and expand the Administration Workflows section to access various administrative scripts.
7. Script Initialization: Double-click on the script titled "delete addresses from departed users" to open it.
8. Script Execution: Click "Run" to execute the script, which will then remove the addresses of all disabled users and print a message for each address removed successfully.

Here is the Python script in WorkStation that facilitates this operation:
"""Remove each address from every departed user (those which are disabled).
For each successfully removed address a message will be printed.
"""
from typing import List
from mstrio.connection import Connection, get_connection
from mstrio.users_and_groups import list_users
def delete_addresses_from_departed_users(connection: "Connection") -> List[dict]:
"""Remove each address from every departed user (those which are disabled).
For each successfully removed address a message will be printed.
Args:
connection: Strategy connection object returned by
`connection.Connection()`
"""
# get all users that are disabled
all_users = list_users(connection=connection)
users_ = [u for u in all_users if not u.enabled]
removed_addresses = []
for user_ in users_:
# remove all email addresses from the given user
if user_.addresses:
for address in user_.addresses:
user_.remove_address(id=address['id'])
removed_addresses.append(
{
'user_id': user_.id, 'username': user_.username, 'address': address
}
)
return removed_addresses
# connect to environment without providing user credentials
# variable `workstationData` is stored within Workstation
conn = get_connection(workstationData, 'Strategy Tutorial')
# execute deletion of addresses from departed users
delete_addresses_from_departed_users(conn)