コード例 #1
0
def list_security_roles_per_user(connection: "Connection",
                                 user_group_name: str = None,
                                 user_group_id: str = None,
                                 include_user_groups: bool = False):
    """List security roles for every user in a user group.
    It is possible to provide either name or id of user group.

    Args:
        connection: MicroStrategy connection object returned by
            `connection.Connection()`
        user_group_name (str): name of the user group
        user_group_id (str): id of the user group
        include_user_groups (bool): if True also user groups, which are inside
            provided user group, will be included in the result

    Returns:
        list of dicts where each of them is in given form:
        {
            'type' - type of object (it can be `user` or `user_group`)
            'id' - id of object
            'name' - name of object
            'username' - username of user (for user group it is None)
            'security_roles' - list of security roles which object has
        }
    """

    usrgrp = UserGroup(connection=connection,
                       name=user_group_name,
                       id=user_group_id)
    all_scrt_rls = []
    for member in usrgrp.list_members():
        if not member.get('full_name', None):
            if not include_user_groups:
                continue
            member_type = 'user_group'
            tmp_ug = UserGroup(connection=connection, id=member['id'])
            scrt_rls = tmp_ug.security_roles
        else:
            member_type = 'user'
            tmp_u = User(connection=connection, id=member['id'])
            scrt_rls = tmp_u.security_roles
        m = {
            'type': member_type,
            'id': member['id'],
            'name': member['name'],
            'username': member.get('username', None),
            'security_roles': scrt_rls
        }
        all_scrt_rls.append(m)
    return all_scrt_rls
コード例 #2
0
ファイル: privilege.py プロジェクト: drmehling/mstrio-py
    def revoke_from_user_group(self, groups: List[Union["UserGroup", str]]) -> None:
        """Revoke privilege from User Group.

        Args:
            groups: list of `UserGroup` objects or names.
        """
        if isinstance(groups, str):
            groups = [UserGroup(self.connection, name=groups)]
        elif isinstance(groups, UserGroup):
            groups = [groups]
        elif hasattr(groups, '__iter__') and all([isinstance(el, str) for el in groups]):
            # TODO use list_user_groups(name=[groups])
            groups = [UserGroup(self.connection, name=group) for group in groups]
        for group in groups:
            group.revoke_privilege(self.id)
コード例 #3
0
ファイル: privilege.py プロジェクト: MicroStrategy/mstrio-py
    def add_to_user_group(self, groups: List[Union["UserGroup", str]]) -> None:
        """Add privilege to User Group.

        Args:
            groups: list of `UserGroup` objects or names.
        """
        if isinstance(groups, str):
            groups = [UserGroup(self.connection, name=groups)]
        elif isinstance(groups, UserGroup):
            groups = [groups]
        elif hasattr(groups, '__iter__') and all(isinstance(el, str) for el in groups):
            # TODO use list_user_groups(name=[groups])
            groups = [UserGroup(self.connection, name=group) for group in groups]
        for group in groups:
            group.grant_privilege(self.id)
コード例 #4
0
    'fullName': 'Thomas Wilson'
}]
for u in users_array:
    User.create(connection=conn,
                username=u['username'],
                full_name=u['fullName'])

# create a single user and get users which name begins with "John" and have
# additional filter for initials
User.create(connection=conn, username="******", full_name="John Smith")
my_users = list_users(connection=conn, name_begins="John", initials="JS")

# get all user groups (you can also add additional filters as for users) and
# create a new one
user_groups_list = list_user_groups(connection=conn)
UserGroup.create(connection=conn, name="Special Users")

# get user, user group and add this user to this user group
user_ = User(connection=conn, name="John Smith")
user_group_ = UserGroup(connection=conn, name="Special Users")
user_group_.add_users(users=[user_.id])

# set custom permissions of the user for given objects
user_.set_custom_permissions(to_objects=['55AA293811EAE2F2EC7D0080EF25A592'],
                             object_type=3,
                             execute='grant',
                             use='deny',
                             control='default',
                             delete='grant',
                             write='deny',
                             read='default',
コード例 #5
0
ファイル: user_library.py プロジェクト: drmehling/mstrio-py
users = list_users(connection=conn)
user_1 = User(connection=conn, id='1234234534564567567867897890ABCD')
user_2 = User(connection=conn, id='9876876576546543543243213210DCBA')

# share one dossier/document to a given user(s) by passing user object(s)
# or id(s)
doss.publish(recipients=user_1)
doss.publish(recipients=['1234234534564567567867897890ABCD', '9876876576546543543243213210DCBA'])
# analogously we can take away dossier(s)/document(s) from the library of the
# given user(s)
doss.unpublish(recipients=[user_1, user_2])
doss.unpublish(recipients='1234234534564567567867897890ABCD')

# list all user groups and get one of them
user_groups_ = list_user_groups(connection=conn)
user_group_ = UserGroup(connection=conn, name='Data Scientists')

# add users to given user group
user_group_.add_users(users=[user_1, user_2])

# get documents with given ids to give to the user group and users which belong
# to it
docs_to_publish = list_documents(
    connection=conn,
    id=[
        '12340987234598763456876545677654', '98761234876523457654345665434567',
        '654356785432678943217890ABCDDCBA'
    ],
)
for doc in docs_to_publish:
    doc.publish(recipients=user_group_)
コード例 #6
0
def get_user_group(connection, name):
    try:
        user_group_ = UserGroup(connection=connection, name=name)
    except Exception:
        user_group_ = None
    return user_group_