|
| 1 | +import json |
1 | 2 | from typing import TYPE_CHECKING, List, Optional |
2 | 3 |
|
3 | 4 | from labelbox.exceptions import LabelboxError |
4 | 5 | from labelbox import utils |
5 | 6 | from labelbox.orm.db_object import DbObject, query, Entity |
6 | 7 | from labelbox.orm.model import Field, Relationship |
7 | 8 | from labelbox.schema.invite import InviteLimit |
| 9 | +from labelbox.schema.resource_tag import ResourceTag |
8 | 10 |
|
9 | 11 | if TYPE_CHECKING: |
10 | 12 | from labelbox import Role, User, ProjectRole, Invite, InviteLimit, IAMIntegration |
@@ -42,6 +44,7 @@ def __init__(self, *args, **kwargs): |
42 | 44 | users = Relationship.ToMany("User", False) |
43 | 45 | projects = Relationship.ToMany("Project", True) |
44 | 46 | webhooks = Relationship.ToMany("Webhook", False) |
| 47 | + resource_tags = Relationship.ToMany("ResourceTags", False) |
45 | 48 |
|
46 | 49 | def invite_user( |
47 | 50 | self, |
@@ -126,6 +129,43 @@ def remove_user(self, user: "User") -> None: |
126 | 129 | updateUser(where: {id: $%s}, data: {deleted: true}) { id deleted } |
127 | 130 | }""" % (user_id_param, user_id_param), {user_id_param: user.uid}) |
128 | 131 |
|
| 132 | + def create_resource_tag(self, tag=None) -> ResourceTag: |
| 133 | + """ |
| 134 | + Creates a resource tag. |
| 135 | + >>> tag = {'text': 'tag-1', 'color': 'ffffff'} |
| 136 | +
|
| 137 | + Args: |
| 138 | + tag (dict): A resource tag {'text': 'tag-1', 'color': 'fffff'} |
| 139 | + Returns: |
| 140 | + The created resource tag. |
| 141 | + """ |
| 142 | + tag_text_param = "text" |
| 143 | + tag_color_param = "color" |
| 144 | + |
| 145 | + query_str = """mutation CreateResourceTagPyApi($text:String!,$color:String!) { |
| 146 | + createResourceTag(input:{text:$%s,color:$%s}) {%s}} |
| 147 | + """ % (tag_text_param, tag_color_param, |
| 148 | + query.results_query_part(ResourceTag)) |
| 149 | + |
| 150 | + params = { |
| 151 | + tag_text_param: tag.get("text", ""), |
| 152 | + tag_color_param: tag.get("color", "") |
| 153 | + } |
| 154 | + res = self.client.execute(query_str, params) |
| 155 | + return ResourceTag(self.client, res['createResourceTag']) |
| 156 | + |
| 157 | + def get_resource_tags(self) -> List[ResourceTag]: |
| 158 | + """ |
| 159 | + Returns all resource tags for an organization |
| 160 | + """ |
| 161 | + query_str = """query GetOrganizationResourceTagsPyApi{organization{resourceTag{%s}}}""" % ( |
| 162 | + query.results_query_part(ResourceTag)) |
| 163 | + |
| 164 | + return [ |
| 165 | + ResourceTag(self.client, tag) for tag in self.client.execute( |
| 166 | + query_str)['organization']['resourceTag'] |
| 167 | + ] |
| 168 | + |
129 | 169 | def get_iam_integrations(self) -> List["IAMIntegration"]: |
130 | 170 | """ |
131 | 171 | Returns all IAM Integrations for an organization |
|
0 commit comments