class User(DbObject): """ A User is a registered Labelbox user (for example you) associated with data they create or import and an Organization they belong to. """ updated_at = Field.DateTime("updated_at") created_at = Field.DateTime("created_at") email = Field.String("email") name = Field.String("nickname") nickname = Field.String("name") intercom_hash = Field.String("intercom_hash") picture = Field.String("picture") is_viewer = Field.Boolean("is_viewer") is_external_user = Field.Boolean("is_external_user") # Relationships organization = Relationship.ToOne("Organization") created_tasks = Relationship.ToMany("Task", False, "created_tasks") projects = Relationship.ToMany("Project", False)
class Label(DbObject, Updateable, BulkDeletable): """ Label represents an assessment on a DataRow. For example one label could contain 100 bounding boxes (annotations). """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.reviews.supports_filtering = False label = Field.String("label") seconds_to_label = Field.Float("seconds_to_label") agreement = Field.Float("agreement") benchmark_agreement = Field.Float("benchmark_agreement") is_benchmark_reference = Field.Boolean("is_benchmark_reference") project = Relationship.ToOne("Project") data_row = Relationship.ToOne("DataRow") reviews = Relationship.ToMany("Review", False) created_by = Relationship.ToOne("User", False, "created_by") @staticmethod def bulk_delete(labels): """ Deletes all the given Labels. Args: labels (list of Label): The Labels to delete. """ BulkDeletable._bulk_delete(labels, False) def create_review(self, **kwargs): """ Creates a Review for this label. Kwargs: Review attributes. At a minimum a `Review.score` field value must be provided. """ kwargs[Entity.Review.label.name] = self kwargs[Entity.Review.project.name] = self.project() return self.client._create(Entity.Review, kwargs) def create_benchmark(self): """ Creates a Benchmark for this Label. Returns: The newly created Benchmark. """ label_id_param = "labelId" query_str = """mutation CreateBenchmarkPyApi($%s: ID!) { createBenchmark(data: {labelId: $%s}) {%s}} """ % ( label_id_param, label_id_param, query.results_query_part(Entity.Benchmark)) res = self.client.execute(query_str, {label_id_param: self.uid}) return Entity.Benchmark(self.client, res["createBenchmark"])
class User(DbObject): """ A User is a registered Labelbox user (for example you) associated with data they create or import and an Organization they belong to. Attributes: updated_at (datetime) created_at (datetime) email (str) name (str) nickname (str) intercom_hash (str) picture (str) is_viewer (bool) is_external_viewer (bool) organization (Relationship): `ToOne` relationship to Organization created_tasks (Relationship): `ToMany` relationship to Task projects (Relationship): `ToMany` relationship to Project """ updated_at = Field.DateTime("updated_at") created_at = Field.DateTime("created_at") email = Field.String("email") name = Field.String("nickname") nickname = Field.String("name") intercom_hash = Field.String("intercom_hash") picture = Field.String("picture") is_viewer = Field.Boolean("is_viewer") is_external_user = Field.Boolean("is_external_user") # Relationships organization = Relationship.ToOne("Organization") created_tasks = Relationship.ToMany("Task", False, "created_tasks") projects = Relationship.ToMany("Project", False) org_role = Relationship.ToOne("OrgRole", False) def update_org_role(self, role: Role): """ Updated the `User`s organization role. See client.get_roles() to get all valid roles If you a user is converted from project level permissions to org level permissions and then convert back, their permissions will remain for each individual project Args: role (Role): The role that you want to set for this user. """ user_id_param = "userId" role_id_param = "roleId" query_str = """mutation SetOrganizationRolePyApi($%s: ID!, $%s: ID!) { setOrganizationRole(data: {userId: $userId, roleId: $roleId}) { id name }} """ % (user_id_param, role_id_param) self.client.execute(query_str, { user_id_param: self.uid, role_id_param: role.uid }) def remove_from_project(self, project: Project): """ Removes a User from a project. Only used for project based users. Project based user means their org role is "NONE" Args: project (Project): Project to remove user from """ self.upsert_project_role(project, self.client.get_roles()['NONE']) def upsert_project_role(self, project: Project, role: Role): """ Updates or replaces a User's role in a project. Args: project (Project): The project to update the users permissions for role (Role): The role to assign to this user in this project. """ org_role = self.org_role() if org_role.name.upper() != 'NONE': raise ValueError( "User is not project based and has access to all projects") project_id_param = "projectId" user_id_param = "userId" role_id_param = "roleId" query_str = """mutation SetProjectMembershipPyApi($%s: ID!, $%s: ID!, $%s: ID!) { setProjectMembership(data: {%s: $userId, roleId: $%s, projectId: $%s}) {id}} """ % (user_id_param, role_id_param, project_id_param, user_id_param, role_id_param, project_id_param) self.client.execute( query_str, { project_id_param: project.uid, user_id_param: self.uid, role_id_param: role.uid })