Skip to content

Commit d3dbe91

Browse files
committed
Merge branch 'm-kovalsky/1040'
2 parents ae642b2 + a73a3e8 commit d3dbe91

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

src/sempy_labs/admin/_domains.py

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def assign_domain_workspaces_by_capacities(
409409

410410

411411
@log
412-
def assign_domain_workspaces(domain: str | UUID, workspace_names: str | List[str]):
412+
def assign_domain_workspaces(domain: str | UUID, workspace: str | UUID | List[str | UUID], **kwargs):
413413
"""
414414
Assigns workspaces to the specified domain by workspace.
415415
@@ -421,33 +421,46 @@ def assign_domain_workspaces(domain: str | UUID, workspace_names: str | List[str
421421
----------
422422
domain : str | uuid.UUID
423423
The domain name or ID.
424-
workspace_names : str | List[str]
425-
The Fabric workspace(s).
424+
workspace : str | uuid.UUID | List[str | uuid.UUID]
425+
The Fabric workspace name or IDs.
426426
"""
427427

428428
domain_id = resolve_domain_id(domain)
429429

430-
if isinstance(workspace_names, str):
431-
workspace_names = [workspace_names]
430+
if "workspace_names" in kwargs:
431+
workspace = kwargs["workspace_names"]
432+
print(
433+
f"{icons.warning} The 'workspace_names' parameter is deprecated. Please use 'workspace' instead."
434+
)
432435

433-
dfW = list_workspaces()
436+
if isinstance(workspace, str):
437+
workspace = [workspace]
438+
workspace_list = []
434439

435-
# Check for invalid capacities
436-
invalid_workspaces = [
437-
name for name in workspace_names if name not in dfW["Name"].values
438-
]
440+
for w in workspace:
441+
if _is_valid_uuid(w):
442+
workspace_list.append(w)
443+
else:
444+
dfW = list_workspaces(workspace=w)
445+
if not dfW.empty:
446+
workspace_list.append(dfW["Id"].iloc[0])
439447

440-
if len(invalid_workspaces) == 1:
441-
raise ValueError(
442-
f"{icons.red_dot} The {invalid_workspaces} workspace is not valid."
443-
)
444-
elif len(invalid_workspaces) > 1:
445-
raise ValueError(
446-
f"{icons.red_dot} The {invalid_workspaces} workspaces are not valid."
447-
)
448-
449-
dfW_filt = dfW[dfW["Name"].isin(workspace_names)]
450-
workspace_list = list(dfW_filt["Id"])
448+
# Check for invalid capacities
449+
#invalid_workspaces = [
450+
# name for name in workspace_names if name not in dfW["Name"].values
451+
#]
452+
453+
#if len(invalid_workspaces) == 1:
454+
# raise ValueError(
455+
# f"{icons.red_dot} The {invalid_workspaces} workspace is not valid."
456+
# )
457+
#elif len(invalid_workspaces) > 1:
458+
# raise ValueError(
459+
# f"{icons.red_dot} The {invalid_workspaces} workspaces are not valid."
460+
# )
461+
462+
#dfW_filt = dfW[dfW["Name"].isin(workspace_names)]
463+
#workspace_list = list(dfW_filt["Id"])
451464

452465
payload = {"workspacesIds": workspace_list}
453466

@@ -459,7 +472,7 @@ def assign_domain_workspaces(domain: str | UUID, workspace_names: str | List[str
459472
)
460473

461474
print(
462-
f"{icons.green_dot} The {workspace_names} workspaces have been assigned to the '{domain}' domain."
475+
f"{icons.green_dot} The {workspace} workspaces have been assigned to the '{domain}' domain."
463476
)
464477

465478

0 commit comments

Comments
 (0)