Skip to content

Commit

Permalink
Merge branch 'm-kovalsky/add_role_member'
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kovalsky committed Dec 10, 2024
2 parents 381a44a + 02b1dd8 commit 6cb779e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/sempy_labs/tom/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4515,6 +4515,36 @@ def set_value_filter_behavior(self, value_filter_behavior: str = "Automatic"):
TOM.ValueFilterBehaviorType, value_filter_behavior
)

def add_role_member(self, role_name: str, member: str | List[str]):
"""
Adds a external model role member (AzureAD) to a role.
Parameters
----------
role_name : str
The role name.
member : str | List[str]
The email address(es) of the member(s) to add.
"""

import Microsoft.AnalysisServices.Tabular as TOM

if isinstance(member, str):
member = [member]

role = self.model.Roles[role_name]
current_members = [m.MemberName for m in role.Members]

for m in member:
if m not in current_members:
rm = TOM.ExternalModelRoleMember()
rm.IdentityProvider = "AzureAD"
rm.MemberName = m
role.Members.Add(rm)
print(f"{icons.green_dot} '{m}' has been added as a member of the '{role_name}' role.")
else:
print(f"{icons.yellow_dot} '{m}' is already a member in the '{role_name}' role.")

def close(self):

if not self._readonly and self.model is not None:
Expand Down

0 comments on commit 6cb779e

Please sign in to comment.