-
Notifications
You must be signed in to change notification settings - Fork 66
Vb/member export plt 2099 #1925
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,5 +52,5 @@ Labelbox Python SDK Documentation | |
task | ||
task-queue | ||
user | ||
user-group-upload | ||
user-group-v2 | ||
webhook |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
User Group | ||
=============================================================================================== | ||
|
||
.. automodule:: labelbox.schema.user_group_v2 | ||
:members: | ||
:show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,14 @@ class UploadReport: | |
lines: List[UploadReportLine] | ||
|
||
|
||
class UserGroupUpload: | ||
@dataclass | ||
class Member: | ||
"""A member of a user group.""" | ||
|
||
email: str | ||
|
||
|
||
class UserGroupV2: | ||
"""Upload members to a user group.""" | ||
|
||
def __init__(self, client: Client): | ||
|
@@ -80,7 +87,7 @@ def upload_members( | |
For indicvidual email errors, the error message is available in the UploadReport. | ||
""" | ||
warnings.warn( | ||
"The upload_members for UserGroupUpload is in beta. The method name and signature may change in the future.”", | ||
"The upload_members for UserGroupV2 is in beta. The method name and signature may change in the future.”", | ||
) | ||
|
||
if len(emails) == 0: | ||
|
@@ -109,7 +116,7 @@ def upload_members( | |
"text/csv", | ||
) | ||
} | ||
query = """mutation ImportMembersToGroup( | ||
query = """mutation ImportMembersToGroupPyPi( | ||
$roleId: ID! | ||
$file: Upload! | ||
$where: WhereUniqueIdInput! | ||
|
@@ -183,6 +190,47 @@ def upload_members( | |
csv_report = file_data["importUsersAsCsvToGroup"]["csvReport"] | ||
return self._parse_csv_report(csv_report) | ||
|
||
def export_members(self, group_id: str) -> Optional[List[Member]]: | ||
warnings.warn( | ||
"The export_members for UserGroupV2 is in beta. The method name and signature may change in the future.", | ||
) | ||
|
||
if not group_id: | ||
raise ValueError("Group id is required") | ||
|
||
query = """query GetExportMembersAsCSVPyPi( | ||
$id: ID! | ||
) { | ||
userGroupV2(where: { id: $id }) { | ||
id | ||
membersAsCSV | ||
} | ||
} | ||
""" | ||
params = { | ||
"id": group_id, | ||
} | ||
|
||
result = self.client.execute(query, params) | ||
if result["userGroupV2"] is None: | ||
raise ResourceNotFoundError(message="The user group is not found.") | ||
data = result["userGroupV2"] | ||
|
||
return self._parse_members_csv(data["membersAsCSV"]) | ||
|
||
def _parse_members_csv(self, csv_data: str) -> List[Member]: | ||
csv_lines = csv_data.strip().split("\n") | ||
if not csv_lines: | ||
return [] | ||
|
||
members_list = [] | ||
# Skip header row | ||
for email in csv_lines[1:]: | ||
if email.strip(): # Skip empty lines | ||
members_list.append(Member(email=email.strip())) | ||
|
||
return members_list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a unit test for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
|
||
def _get_role_id(self, role_name: str) -> Optional[str]: | ||
role_id = None | ||
query = """query GetAvailableUserRolesPyPi { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
from labelbox.schema.user_group_v2 import Member, UserGroupV2 | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
return MagicMock() | ||
|
||
|
||
def test_parse_members_csv_empty(client): | ||
group = UserGroupV2(client) | ||
assert group._parse_members_csv("") == [] | ||
assert group._parse_members_csv("\n") == [] | ||
|
||
|
||
def test_parse_members_csv_header_only(client): | ||
group = UserGroupV2(client) | ||
assert group._parse_members_csv("email\n") == [] | ||
|
||
|
||
def test_parse_members_csv_single_member(client): | ||
group = UserGroupV2(client) | ||
result = group._parse_members_csv("email\ntest@example.com") | ||
assert len(result) == 1 | ||
assert isinstance(result[0], Member) | ||
assert result[0].email == "test@example.com" | ||
|
||
|
||
def test_parse_members_csv_multiple_members(client): | ||
group = UserGroupV2(client) | ||
csv_data = "email\ntest1@example.com\ntest2@example.com\ntest3@example.com" | ||
result = group._parse_members_csv(csv_data) | ||
assert len(result) == 3 | ||
assert [m.email for m in result] == [ | ||
"test1@example.com", | ||
"test2@example.com", | ||
"test3@example.com", | ||
] | ||
|
||
|
||
def test_parse_members_csv_handles_whitespace(client): | ||
group = UserGroupV2(client) | ||
csv_data = "email\n test@example.com \n\nother@example.com\n" | ||
result = group._parse_members_csv(csv_data) | ||
assert len(result) == 2 | ||
assert result[0].email == "test@example.com" | ||
assert result[1].email == "other@example.com" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed UserMemberUpload