Skip to content

Commit ee429b4

Browse files
feat: export/import users across workspaces (#361)
* feat: export users across workspaces * Import users with roles * Small fixes * Cleanup * Fix little things * refactor: Use enum for user file format detection - Replace string literals with UserFileFormat enum for better type safety - Add TODO comment about potential --continue-on-error feature for user imports - Addresses PR review feedback 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent fbcb82c commit ee429b4

File tree

9 files changed

+1985
-15
lines changed

9 files changed

+1985
-15
lines changed

src/preset_cli/api/clients/preset.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class Role(int, Enum):
3131

3232

3333
class PresetClient: # pylint: disable=too-few-public-methods
34-
3534
"""
3635
A client for the Preset API.
3736
"""
@@ -158,7 +157,7 @@ def export_users(self, workspace_url: URL) -> Iterator[UserType]:
158157
{
159158
"id": 0,
160159
"username": payload["user"]["username"],
161-
"role": [], # TODO (betodealmeida)
160+
"role": [payload["workspace_role"]["name"].lower()],
162161
"first_name": payload["user"]["first_name"],
163162
"last_name": payload["user"]["last_name"],
164163
"email": payload["user"]["email"].lower(),

src/preset_cli/api/clients/superset.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,20 @@ class OwnershipType(TypedDict):
231231

232232

233233
class SupersetClient: # pylint: disable=too-many-public-methods
234-
235234
"""
236235
A client for running queries against Superset.
237236
"""
238237

239-
def __init__(self, baseurl: Union[str, URL], auth: Auth):
238+
def __init__(
239+
self,
240+
baseurl: Union[str, URL],
241+
auth: Auth,
242+
preset_baseurl: Union[str, URL] = "https://api.app.preset.io/",
243+
):
240244
# convert to URL if necessary
241245
self.baseurl = URL(baseurl)
242246
self.auth = auth
247+
self.preset_baseurl = URL(preset_baseurl)
243248

244249
self.session = auth.session
245250
self.session.headers.update(auth.get_headers())
@@ -360,9 +365,11 @@ def get_data( # pylint: disable=too-many-locals, too-many-arguments
360365

361366
# and order bys
362367
processed_orderbys = [
363-
(orderby, not order_desc)
364-
if orderby in metric_names
365-
else (convert_to_adhoc_metric(orderby), not order_desc)
368+
(
369+
(orderby, not order_desc)
370+
if orderby in metric_names
371+
else (convert_to_adhoc_metric(orderby), not order_desc)
372+
)
366373
for orderby in (order_by or [])
367374
]
368375

@@ -796,8 +803,7 @@ def _export_users_preset(self) -> Iterator[UserType]:
796803
"""
797804
Return all users from a Preset workspace.
798805
"""
799-
# TODO (betodealmeida): remove hardcoded Manager URL
800-
client = PresetClient("https://api.app.preset.io/", self.auth)
806+
client = PresetClient(self.preset_baseurl, self.auth)
801807
return client.export_users(self.baseurl)
802808

803809
def _export_users_superset(self) -> Iterator[UserType]:

0 commit comments

Comments
 (0)