def revoke_from_user(self, users: List[Union["User", str]]) -> None: """Revoke privilege from user. Args: users: list of `User` objects or names. """ if isinstance(users, str): users = [User(self.connection, name=users)] elif isinstance(users, User): users = [users] elif hasattr(users, '__iter__') and all([isinstance(el, str) for el in users]): # TODO use list_users(name=[users]) users = [User(self.connection, name=user) for user in users] for user in users: user.revoke_privilege(self.id)
def add_to_user(self, users: List[Union["User", str]]) -> None: """Add privilege to user. Args: users: list of `User` objects or names. """ if isinstance(users, str): users = [User(self.connection, name=users)] elif isinstance(users, User): users = [users] elif hasattr(users, '__iter__') and all(isinstance(el, str) for el in users): # TODO use list_users(name=[users]) users = [User(self.connection, name=user) for user in users] for user in users: user.grant_privilege(self.id)
def _disable_user_account(connection, username): # find user with a given username u = User(connection=connection, username=username) # remove this user from all user groups (it will not be removed from # user group "Everyone" because of the implementation of I-Server u.remove_from_all_user_groups() # add this user to user groups 'Inacative Users' when such group exists inactive_users_ug = get_user_group(connection=connection, name="Inactive Users") if inactive_users_ug: u.add_to_user_groups(user_groups=inactive_users_ug) # disable user u.alter(enabled=False)
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
def _create_new_user_account(connection, emp_username, emp_fullname, add_to_user_groups): # when user is created it is automatically added to user group "Everyone" # and is granted rights to Browse and Read this user group new_usr = User.create(connection=connection, username=emp_username, full_name=emp_fullname, trust_id=emp_username) # add user to user groups with provided names (during creation it is added to "Everyone" # noqa for user_group_name in add_to_user_groups: user_group_ = get_user_group(connection=connection, name=user_group_name) if user_group_: user_group_.add_users(users=new_usr)
def _init_variables(self, **kwargs) -> None: super()._init_variables(**kwargs) self.description = kwargs.get('description') self.enabled = kwargs.get('enabled') linked_user = kwargs.get("linked_user") self.linked_user = User.from_dict( linked_user, self.connection) if linked_user else None members = kwargs.get('members') self.members = [ ContactGroupMember.from_dict(member) for member in members ] if members else None memberships = kwargs.get('memberships') self._memberships = [ self.from_dict(m, self.connection) for m in memberships ] if memberships else None
def _init_variables(self, **kwargs) -> None: super()._init_variables(**kwargs) self.description = kwargs.get('description') self.enabled = kwargs.get('enabled') linked_user = kwargs.get("linked_user") self.linked_user = User.from_dict(linked_user, self.connection) if linked_user else None addresses = kwargs.get('contact_addresses') self.contact_addresses = [ ContactAddress.from_dict(address, self.connection) for address in addresses ] if addresses else None memberships = kwargs.get('memberships') self.memberships = [ ContactGroup.from_dict(m, self.connection) for m in memberships ] if memberships else None
def __init__(self, connection: Connection, certified: bool, date_certified: Optional[str] = None, certifier: Optional[dict] = None): self._connection = connection self._certified = certified self._date_certified = date_certified self._certifier = User.from_dict(certifier, self._connection) if certifier else None
}, { 'username': '******', 'fullName': 'Mark Jones' }, { 'username': '******', 'fullName': 'Steve Brown' }, { 'username': '******', 'fullName': 'James Davis' }, { 'username': '******', '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")
login_mode=1) # list all dossiers and documents within a project to which we have connection dossiers = list_dossiers(connection=conn) docs = list_documents(connection=conn) # get document and dossier from by name or id and publish them to a library of # an authenticated user doc = Document(connection=conn, name='Some Simple Document') doss = Dossier(connection=conn, name='Some Simple Dossier') doc.publish() doss.publish() # list all users and get 2 of them 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')
# Create connection to the target environment target_base_url = "https://<>/MicroStrategyLibrary/api" target_username = "******" target_password = "******" target_conn = Connection(target_base_url, target_username, target_password, project_name="MicroStrategy Tutorial", login_mode=1) # Make sure the current user have the following privileges: # 'Create package', id: 295 # 'Apply package', id: 296 # They can be granted by admin with the following commands: user = User(source_conn, username='******') Privilege(source_conn, id=295).add_to_user(user) Privilege(source_conn, id=296).add_to_user(user) # Or by name: user2 = User(target_conn, username='******') Privilege(target_conn, name='Create package').add_to_user(user2) Privilege(target_conn, name='Apply package').add_to_user(user2) # Create PackageConfig with information what object should be migrated and how. # The options are of type Enum with all possible values listed. dossier_id = 'some dossier id' report_id = 'some report id' package_settings = PackageSettings( PackageSettings.DefaultAction.USE_EXISTING,