EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB486758: How to Purge Addresses from Departed Users in MicroStrategy Workstation Using a Python Script


Rainiero Leon

Support Engineer • MicroStrategy


This article details the process of utilizing a Python script within the MicroStrategy Workstation to remove the addresses of users who have been disabled in the system. The script leverages the mstrio-py library to facilitate the manipulation of user data, ensuring a streamlined administration workflow.

Symptom

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.
 

Cause

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.
 

Solution

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.

ka0PW00000029jxYAA_0EMPW000006Rbo2.jpeg

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)


Customization Warning:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.


Comment

0 comments

Details

Knowledge Article

Published:

May 31, 2024

Last Updated:

May 31, 2024