Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added remove_role_member #365

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/sempy_labs/_helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,8 @@ def get_capacity_id(workspace: Optional[str] = None) -> UUID:
"""

if workspace is None:
capacity_id = _get_x_id(name="trident.capacity.id")
capacity_id = _get_fabric_context_setting(name="trident.capacity.id")
else:

workspace = fabric.resolve_workspace_name(workspace)
filter_condition = urllib.parse.quote(workspace)
dfW = fabric.list_workspaces(filter=f"name eq '{filter_condition}'")
Expand Down
31 changes: 30 additions & 1 deletion src/sempy_labs/tom/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4529,7 +4529,7 @@ def set_value_filter_behavior(self, value_filter_behavior: str = "Automatic"):

def add_role_member(self, role_name: str, member: str | List[str]):
"""
Adds a external model role member (AzureAD) to a role.
Adds an external model role member (AzureAD) to a role.

Parameters
----------
Expand Down Expand Up @@ -4561,6 +4561,35 @@ def add_role_member(self, role_name: str, member: str | List[str]):
f"{icons.yellow_dot} '{m}' is already a member in the '{role_name}' role."
)

def remove_role_member(self, role_name: str, member: str | List[str]):
"""
Removes an external model role member (AzureAD) from a role.

Parameters
----------
role_name : str
The role name.
member : str | List[str]
The email address(es) of the member(s) to remove.
"""

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

role = self.model.Roles[role_name]
current_members = {m.MemberName: m.Name for m in role.Members}
for m in member:
name = current_members.get(m)
if name is not None:
role.Members.Remove(role.Members[name])
print(
f"{icons.green_dot} The '{m}' member has been removed from the '{role_name}' role."
)
else:
print(
f"{icons.yellow_dot} '{m}' is not a member of the '{role_name}' role."
)

def close(self):

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