Skip to content

Commit

Permalink
Enterprise.move_workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mesozoic committed Nov 12, 2024
1 parent 8c331aa commit 5bb22bc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pyairtable/api/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class _urls(UrlBuilder):
#: URL for moving user groups between enterprise accounts.
move_groups = meta / "moveGroups"

#: URL for moving workspaces between enterprise accounts.
move_workspaces = meta / "moveWorkspaces"

def user(self, user_id: str) -> Url:
"""
URL for retrieving information about a single user.
Expand Down Expand Up @@ -469,6 +472,32 @@ def move_groups(
)
return MoveGroupsResponse.from_api(response, self.api, context=self)

def move_workspaces(
self,
workspace_ids: Iterable[str],
target: Union[str, Self],
) -> "MoveWorkspacesResponse":
"""
Move one or more workspaces from the current enterprise account
into a different enterprise account within the same organization.
See `Move workspaces <https://airtable.com/developers/web/api/move-workspaces>`__.
Args:
workspace_ids: The list of workspace IDs.
target: The ID of the target enterprise, or an instance of :class:`~pyairtable.Enterprise`.
"""
if isinstance(target, Enterprise):
target = target.id
response = self.api.post(
self.urls.move_workspaces,
json={
"workspaceIds": workspace_ids,
"targetEnterpriseAccountId": target,
},
)
return MoveWorkspacesResponse.from_api(response, self.api, context=self)


class UserRemoved(AirtableModel):
"""
Expand Down Expand Up @@ -573,6 +602,15 @@ class MoveGroupsResponse(AirtableModel):
errors: List[MoveError] = pydantic.Field(default_factory=list)


class MoveWorkspacesResponse(AirtableModel):
"""
Returned by `Move workspaces <https://airtable.com/developers/web/api/move-workspaces>`__.
"""

moved_workspaces: List[NestedId] = pydantic.Field(default_factory=list)
errors: List[MoveError] = pydantic.Field(default_factory=list)


rebuild_models(vars())


Expand Down
3 changes: 3 additions & 0 deletions scripts/find_model_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"pyairtable.api.enterprise:DeleteUsersResponse.Error": "operations:delete-users-by-email:response:schema:@errors:items",
"pyairtable.api.enterprise:ManageUsersResponse": "operations:manage-user-membership:response:schema",
"pyairtable.api.enterprise:ManageUsersResponse.Error": "operations:manage-user-membership:response:schema:@errors:items",
"pyairtable.api.enterprise:MoveError": "operations:move-workspaces:response:schema:@errors:items",
"pyairtable.api.enterprise:MoveGroupsResponse": "operations:move-user-groups:response:schema",
"pyairtable.api.enterprise:MoveWorkspacesResponse": "operations:move-workspaces:response:schema",
"pyairtable.models.audit:AuditLogResponse": "operations:audit-log-events:response:schema",
"pyairtable.models.audit:AuditLogEvent": "operations:audit-log-events:response:schema:@events:items",
"pyairtable.models.audit:AuditLogEvent.Context": "operations:audit-log-events:response:schema:@events:items:@context",
Expand Down
17 changes: 17 additions & 0 deletions tests/test_api_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,20 @@ def test_move_groups(api, enterprise, enterprise_mocks):
"groupIds": group_ids,
}
assert set(m.id for m in result.moved_groups) == set(group_ids)


def test_move_workspaces(api, enterprise, enterprise_mocks):
other_id = fake_id("ent")
workspace_ids = [fake_id("wsp") for _ in range(3)]
enterprise_mocks.move_workspaces_json["movedWorkspaces"] = [
{"id": workspace_id} for workspace_id in workspace_ids
]
for target in [other_id, api.enterprise(other_id)]:
enterprise_mocks.move_workspaces.reset()
result = enterprise.move_workspaces(workspace_ids, target)
assert enterprise_mocks.move_workspaces.call_count == 1
assert enterprise_mocks.move_workspaces.last_request.json() == {
"targetEnterpriseAccountId": other_id,
"workspaceIds": workspace_ids,
}
assert set(m.id for m in result.moved_workspaces) == set(workspace_ids)

0 comments on commit 5bb22bc

Please sign in to comment.