|
6 | 6 | from labelbox.orm.db_object import DbObject, query, Entity |
7 | 7 | from labelbox.orm.model import Field, Relationship |
8 | 8 | from labelbox.schema.invite import InviteLimit |
| 9 | +from labelbox.schema.resource_tag import ResourceTag |
9 | 10 |
|
10 | 11 | if TYPE_CHECKING: |
11 | 12 | from labelbox import Role, User, ProjectRole, Invite, InviteLimit, IAMIntegration |
@@ -43,6 +44,7 @@ def __init__(self, *args, **kwargs): |
43 | 44 | users = Relationship.ToMany("User", False) |
44 | 45 | projects = Relationship.ToMany("Project", True) |
45 | 46 | webhooks = Relationship.ToMany("Webhook", False) |
| 47 | + resourceTags = Relationship.ToMany("ResourceTag", False) |
46 | 48 |
|
47 | 49 | def invite_user( |
48 | 50 | self, |
@@ -127,13 +129,42 @@ def remove_user(self, user: "User") -> None: |
127 | 129 | updateUser(where: {id: $%s}, data: {deleted: true}) { id deleted } |
128 | 130 | }""" % (user_id_param, user_id_param), {user_id_param: user.uid}) |
129 | 131 |
|
130 | | - def get_resource_tags(self) -> List["ResourceTag"]: |
| 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]: |
131 | 158 | """ |
132 | 159 | Returns all resource tags for an organization |
133 | 160 | """ |
134 | | - res = self.client.execute("""query GetOrganizationResourceTagsPyApi{organization{resourceTag{id,text,color}}}""") |
| 161 | + query_str = """query GetOrganizationResourceTagsPyApi{organization{resourceTag{%s}}}""" % ( |
| 162 | + query.results_query_part(ResourceTag)) |
135 | 163 |
|
136 | | - return res['organization']['resourceTag'] |
| 164 | + return [ |
| 165 | + ResourceTag(self.client, resourceTag) |
| 166 | + for resourceTag in res['createResourceTag'] |
| 167 | + ] |
137 | 168 |
|
138 | 169 | def get_iam_integrations(self) -> List["IAMIntegration"]: |
139 | 170 | """ |
|
0 commit comments