Skip to content

Conversation

@paulnoirel
Copy link
Contributor

@paulnoirel paulnoirel commented Jan 12, 2026

Description

The current PR adds an optional user_group_roles to Organization.invite_user(...) so callers can invite a user (with org role NONE) and simultaneously assign one or more UserGroup role memberships, like in the UI.
The new parameter is similar to the existing project_role for consistency.

Guardrails

  • Requires org role NONE: passing user_group_roles with any other org role raises ValueError.
  • Dedupes exact duplicates: repeated entries with the same user_group.id + role.uid are deduped.
  • Rejects conflicts: if the same user_group.id appears with different roles, raises ValueError (prevents backend errors).

Example

from labelbox import Client, UserGroupRole
from labelbox.schema.user_group import UserGroup

invitee: str = "new.user@example.com"

client = Client("<API_KEY>")
organization = client.get_organization()
roles = client.get_roles()

# NOTE: user_group_roles requires org role NONE
org_role = roles["NONE"]

# Use an existing UserGroup id (e.g. from the UI / API)
user_group = UserGroup(client=client, id="<USER_GROUP_ID>")

invite = organization.invite_user(
    email=invitee,
    role=org_role,
    user_group_roles=[
        UserGroupRole(user_group=user_group, role=roles["REVIEWER"]),
    ],
)

Fixes # (PLT-3393)[https://labelbox.atlassian.net/browse/PLT-3393]

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Document change (fix typo or modifying any markdown files, code comments or anything in the examples folder only)

All Submissions

  • Have you followed the guidelines in our Contributing document?
  • Have you provided a description?
  • Are your changes properly formatted?

New Feature Submissions

  • Does your submission pass tests?
  • Have you added thorough tests for your new feature?
  • Have you commented your code, particularly in hard-to-understand areas?
  • Have you added a Docstring?

Changes to Core Features

  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you updated any code comments, as applicable?

Note

Enables assigning UserGroup memberships during user invites.

  • Adds user_group_roles param to Organization.invite_user(...) (requires org role NONE), building userGroupIds and userGroupWithRoleIds in the invite payload
  • Dedupes exact duplicate group+role entries and raises ValueError on conflicting roles for the same UserGroup
  • Introduces and exports UserGroupRole dataclass; updates type hints and imports
  • Adds unit tests covering deduplication, conflict detection, and payload formation
  • Minor formatting/whitespace changes elsewhere

Written by Cursor Bugbot for commit 5917322. This will update automatically on new commits. Configure here.

@paulnoirel paulnoirel force-pushed the pno/PLT-3393-invite-users-with-groups branch from 6702803 to 5917322 Compare January 12, 2026 15:38
@paulnoirel paulnoirel changed the title Add support of groups in invte Add support of groups to invite_user() Jan 12, 2026
@paulnoirel paulnoirel marked this pull request as ready for review January 12, 2026 15:52
@paulnoirel paulnoirel requested a review from a team as a code owner January 12, 2026 15:52
@paulnoirel paulnoirel changed the title Add support of groups to invite_user() [PLT-3393] Add support of groups to invite_user() Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants