Skip to content

Get invitations #1962

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 3 commits into from
Apr 3, 2025
Merged

Get invitations #1962

merged 3 commits into from
Apr 3, 2025

Conversation

paulnoirel
Copy link
Contributor

@paulnoirel paulnoirel commented Mar 28, 2025

Description

This PR addresses a request from Schneider Electric to be able to retrieve the list of pending invitations.

Notes:

This PR fixes a bug when a project is deleted after an invite was sent. To prevent an exception, deleted projects are not listed in invite.project_roles

Functions

Organization.get_invites(self) -> PaginatedCollection
Organization.get_project_invites(project_id: str) -> PaginatedCollection:
Invite.cancel() -> bool

Invite.get_invites(client: "Client") -> PaginatedCollection
Invite.get_project_invites(client: "Client", project_id: str) -> PaginatedCollection:

Example:

import uuid
import labelbox as lb

client = lb.Client(API_KEY)

# Data
test_email = f"test-{uuid.uuid4()}@labelbox.com"
project = client.create_project(
    name=f"test-project1-{uuid.uuid4()}", media_type=lb.MediaType.Image
)

org = client.get_organization()
roles = client.get_roles()
project_role = lb.ProjectRole(project=project, role=roles["LABELER"])

invite_temp = org.invite_user(
  email=test_email
  role=roles["NONE"],
  project_roles=[project_role]
)

# At this stage invite_temp.uid == "invited" as per mutation
invite = next(
    invite for invite in org.get_invites() if invite.email == test_email
)

invite_project = next(
    invite for invite in org.get_project_invites(project.uid) if invite.email == test_email
)

cancel_inv_org = invite.cancel() # True
cancel_inv_proj_org = invite_project.cancel() # Exception "Unable to find pending invite with ID xxxx"

Fixes # (issue)

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?

@paulnoirel paulnoirel marked this pull request as ready for review March 28, 2025 22:09
@paulnoirel paulnoirel requested a review from a team as a code owner March 28, 2025 22:09
@paulnoirel paulnoirel force-pushed the pno/PLT-2480_get_invites branch from 4e7200e to 3e47710 Compare April 3, 2025 14:53
@paulnoirel paulnoirel requested a review from mihhail-m April 3, 2025 14:53
)

# Add a small delay to ensure invite is created
time.sleep(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might make it finicky is their any way we could make this behave more sync? Worse case a retry loop

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple one something like time.sleep 5 seconds check if not there retry again up to 3 times

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only mention because ive fix test with this sort of logic. Its annoying when they become finicky

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I've removed the pause completely.

@paulnoirel paulnoirel force-pushed the pno/PLT-2480_get_invites branch from 7e37cc8 to 7af08b9 Compare April 3, 2025 15:35
@paulnoirel paulnoirel requested a review from Gabefire April 3, 2025 17:31
@paulnoirel paulnoirel merged commit cca1079 into develop Apr 3, 2025
17 of 26 checks passed
@paulnoirel paulnoirel deleted the pno/PLT-2480_get_invites branch April 3, 2025 17:33
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.

3 participants