|
16 | 16 |
|
17 | 17 | @dataclass
|
18 | 18 | class UploadReportLine:
|
| 19 | + """A single line in the CSV report of the upload members mutation. |
| 20 | + Both errors and successes are reported here. |
| 21 | +
|
| 22 | + Example output when using dataclasses.asdict(): |
| 23 | + >>> { |
| 24 | + >>> 'lines': [ |
| 25 | + >>> { |
| 26 | + >>> 'email': '...', |
| 27 | + >>> 'result': 'Not added', |
| 28 | + >>> 'error': 'User not found in the current organization' |
| 29 | + >>> }, |
| 30 | + >>> { |
| 31 | + >>> 'email': '...', |
| 32 | + >>> 'result': 'Not added', |
| 33 | + >>> 'error': 'Member already exists in group' |
| 34 | + >>> }, |
| 35 | + >>> { |
| 36 | + >>> 'email': '...', |
| 37 | + >>> 'result': 'Added', |
| 38 | + >>> 'error': '' |
| 39 | + >>> } |
| 40 | + >>> ] |
| 41 | + >>> } |
| 42 | + """ |
19 | 43 | email: str
|
20 | 44 | result: str
|
21 | 45 | error: Optional[str] = None
|
22 | 46 |
|
23 | 47 |
|
24 | 48 | @dataclass
|
25 | 49 | class UploadReport:
|
| 50 | + """The report of the upload members mutation.""" |
26 | 51 | lines: List[UploadReportLine]
|
27 | 52 |
|
28 | 53 |
|
29 | 54 | class UserGroupUpload:
|
| 55 | + """Upload members to a user group.""" |
| 56 | + |
30 | 57 | def __init__(self, client: Client):
|
31 | 58 | self.client = client
|
32 | 59 |
|
33 | 60 | def upload_members(
|
34 | 61 | self, group_id: str, role: str, emails: List[str]
|
35 | 62 | ) -> Optional[UploadReport]:
|
| 63 | + """Upload members to a user group. |
| 64 | +
|
| 65 | + Args: |
| 66 | + group_id: A valid ID of the user group. |
| 67 | + role: The name of the role to assign to the uploaded members as it appears in the UI on the Import Members popup. |
| 68 | + emails: The list of emails of the members to upload. |
| 69 | +
|
| 70 | + Returns: |
| 71 | + UploadReport: The report of the upload members mutation. |
| 72 | +
|
| 73 | + Raises: |
| 74 | + ResourceNotFoundError: If the role is not found. |
| 75 | + LabelboxError: If the upload fails. |
| 76 | +
|
| 77 | + For indicvidual email errors, the error message is available in the UploadReport. |
| 78 | + """ |
36 | 79 | if len(emails) == 0:
|
37 | 80 | print("No emails to upload.")
|
38 | 81 | return None
|
|
0 commit comments