From fbab903e992ec524d6f904426555eccb5e0fd306 Mon Sep 17 00:00:00 2001 From: Alexei Mochalov Date: Thu, 19 Dec 2024 18:56:00 +0500 Subject: [PATCH] quilt3.admin.tabulator: get/set open query (#4260) Co-authored-by: Sergey Fedoseev --- api/python/quilt3-admin/queries.graphql | 14 ++++++ .../quilt3/admin/_graphql_client/__init__.py | 11 +++++ .../quilt3/admin/_graphql_client/client.py | 46 +++++++++++++++++++ .../tabulator_get_open_query.py | 17 +++++++ .../tabulator_set_open_query.py | 24 ++++++++++ api/python/quilt3/admin/tabulator.py | 14 ++++++ api/python/tests/test_admin_api.py | 17 +++++++ docs/CHANGELOG.md | 6 +++ docs/advanced-features/tabulator.md | 4 +- docs/api-reference/Admin.md | 10 ++++ 10 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 api/python/quilt3/admin/_graphql_client/tabulator_get_open_query.py create mode 100644 api/python/quilt3/admin/_graphql_client/tabulator_set_open_query.py diff --git a/api/python/quilt3-admin/queries.graphql b/api/python/quilt3-admin/queries.graphql index 0fb50433554..872fef0a6c3 100644 --- a/api/python/quilt3-admin/queries.graphql +++ b/api/python/quilt3-admin/queries.graphql @@ -241,3 +241,17 @@ mutation bucketTabulatorTableRename($bucketName: String!, $tableName: String!, $ } } } + +query tabulatorGetOpenQuery { + admin { + tabulatorOpenQuery + } +} + +mutation tabulatorSetOpenQuery($enabled: Boolean!) { + admin { + setTabulatorOpenQuery(enabled: $enabled) { + tabulatorOpenQuery + } + } +} diff --git a/api/python/quilt3/admin/_graphql_client/__init__.py b/api/python/quilt3/admin/_graphql_client/__init__.py index 717f43537df..30a00d0566f 100644 --- a/api/python/quilt3/admin/_graphql_client/__init__.py +++ b/api/python/quilt3/admin/_graphql_client/__init__.py @@ -50,6 +50,12 @@ SsoConfigSetAdminSetSsoConfigOperationError, SsoConfigSetAdminSetSsoConfigSsoConfig, ) +from .tabulator_get_open_query import TabulatorGetOpenQuery, TabulatorGetOpenQueryAdmin +from .tabulator_set_open_query import ( + TabulatorSetOpenQuery, + TabulatorSetOpenQueryAdmin, + TabulatorSetOpenQueryAdminSetTabulatorOpenQuery, +) from .users_add_roles import ( UsersAddRoles, UsersAddRolesAdmin, @@ -172,6 +178,11 @@ "SsoConfigSetAdminSetSsoConfigInvalidInput", "SsoConfigSetAdminSetSsoConfigOperationError", "SsoConfigSetAdminSetSsoConfigSsoConfig", + "TabulatorGetOpenQuery", + "TabulatorGetOpenQueryAdmin", + "TabulatorSetOpenQuery", + "TabulatorSetOpenQueryAdmin", + "TabulatorSetOpenQueryAdminSetTabulatorOpenQuery", "UnmanagedRoleSelection", "Upload", "UserInput", diff --git a/api/python/quilt3/admin/_graphql_client/client.py b/api/python/quilt3/admin/_graphql_client/client.py index e4ef1dac7e7..857225e1937 100644 --- a/api/python/quilt3/admin/_graphql_client/client.py +++ b/api/python/quilt3/admin/_graphql_client/client.py @@ -34,6 +34,8 @@ SsoConfigSetAdminSetSsoConfigOperationError, SsoConfigSetAdminSetSsoConfigSsoConfig, ) +from .tabulator_get_open_query import TabulatorGetOpenQuery +from .tabulator_set_open_query import TabulatorSetOpenQuery from .users_add_roles import UsersAddRoles, UsersAddRolesAdminUserMutate from .users_create import ( UsersCreate, @@ -1164,3 +1166,47 @@ def bucket_tabulator_table_rename( return BucketTabulatorTableRename.model_validate( data ).admin.bucket_rename_tabulator_table + + def tabulator_get_open_query(self, **kwargs: Any) -> bool: + query = gql( + """ + query tabulatorGetOpenQuery { + admin { + tabulatorOpenQuery + } + } + """ + ) + variables: Dict[str, object] = {} + response = self.execute( + query=query, + operation_name="tabulatorGetOpenQuery", + variables=variables, + **kwargs + ) + data = self.get_data(response) + return TabulatorGetOpenQuery.model_validate(data).admin.tabulator_open_query + + def tabulator_set_open_query(self, enabled: bool, **kwargs: Any) -> bool: + query = gql( + """ + mutation tabulatorSetOpenQuery($enabled: Boolean!) { + admin { + setTabulatorOpenQuery(enabled: $enabled) { + tabulatorOpenQuery + } + } + } + """ + ) + variables: Dict[str, object] = {"enabled": enabled} + response = self.execute( + query=query, + operation_name="tabulatorSetOpenQuery", + variables=variables, + **kwargs + ) + data = self.get_data(response) + return TabulatorSetOpenQuery.model_validate( + data + ).admin.set_tabulator_open_query.tabulator_open_query diff --git a/api/python/quilt3/admin/_graphql_client/tabulator_get_open_query.py b/api/python/quilt3/admin/_graphql_client/tabulator_get_open_query.py new file mode 100644 index 00000000000..295223ccb13 --- /dev/null +++ b/api/python/quilt3/admin/_graphql_client/tabulator_get_open_query.py @@ -0,0 +1,17 @@ +# Generated by ariadne-codegen +# Source: queries.graphql + +from pydantic import Field + +from .base_model import BaseModel + + +class TabulatorGetOpenQuery(BaseModel): + admin: "TabulatorGetOpenQueryAdmin" + + +class TabulatorGetOpenQueryAdmin(BaseModel): + tabulator_open_query: bool = Field(alias="tabulatorOpenQuery") + + +TabulatorGetOpenQuery.model_rebuild() diff --git a/api/python/quilt3/admin/_graphql_client/tabulator_set_open_query.py b/api/python/quilt3/admin/_graphql_client/tabulator_set_open_query.py new file mode 100644 index 00000000000..7bd8518062e --- /dev/null +++ b/api/python/quilt3/admin/_graphql_client/tabulator_set_open_query.py @@ -0,0 +1,24 @@ +# Generated by ariadne-codegen +# Source: queries.graphql + +from pydantic import Field + +from .base_model import BaseModel + + +class TabulatorSetOpenQuery(BaseModel): + admin: "TabulatorSetOpenQueryAdmin" + + +class TabulatorSetOpenQueryAdmin(BaseModel): + set_tabulator_open_query: "TabulatorSetOpenQueryAdminSetTabulatorOpenQuery" = Field( + alias="setTabulatorOpenQuery" + ) + + +class TabulatorSetOpenQueryAdminSetTabulatorOpenQuery(BaseModel): + tabulator_open_query: bool = Field(alias="tabulatorOpenQuery") + + +TabulatorSetOpenQuery.model_rebuild() +TabulatorSetOpenQueryAdmin.model_rebuild() diff --git a/api/python/quilt3/admin/tabulator.py b/api/python/quilt3/admin/tabulator.py index e6e2188a3d6..c1a6e1991f7 100644 --- a/api/python/quilt3/admin/tabulator.py +++ b/api/python/quilt3/admin/tabulator.py @@ -27,3 +27,17 @@ def rename_table(bucket_name: str, table_name: str, new_table_name: str) -> None """ result = util.get_client().bucket_tabulator_table_rename(bucket_name, table_name, new_table_name) util.handle_errors(result) + + +def get_open_query() -> bool: + """ + Get the **open query** status. + """ + return util.get_client().tabulator_get_open_query() + + +def set_open_query(enabled: bool) -> None: + """ + Set the **open query** status. + """ + util.get_client().tabulator_set_open_query(enabled) diff --git a/api/python/tests/test_admin_api.py b/api/python/tests/test_admin_api.py index 0a444b506e0..f2675d8d3d1 100644 --- a/api/python/tests/test_admin_api.py +++ b/api/python/tests/test_admin_api.py @@ -423,3 +423,20 @@ def test_tabulator_rename(data, result): admin.tabulator.rename_table("test", "table", "new_table") else: assert admin.tabulator.rename_table("test", "table", "new_table") == result + + +def test_tabulator_get_open_query(): + with mock_client( + _make_nested_dict("admin.tabulator_open_query", True), + "tabulatorGetOpenQuery", + ): + assert admin.tabulator.get_open_query() is True + + +def test_tabulator_set_open_query(): + with mock_client( + _make_nested_dict("admin.set_tabulator_open_query.tabulator_open_query", True), + "tabulatorSetOpenQuery", + variables={"enabled": True}, + ): + assert admin.tabulator.set_open_query(True) is None diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 35bf0218afb..79f56de4484 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,6 +13,12 @@ Entries inside each section should be ordered by type: ## CLI !--> +# unreleased - YYYY-MM-DD + +## Python API + +* [Added] `quilt3.admin.tabulator`: `get_open_query()` and `set_open_query()` functions for managing Tabulator open query mode ([#4260](https://github.com/quiltdata/quilt/pull/4260)) + # 6.1.1 - 2024-11-21 ## Python API diff --git a/docs/advanced-features/tabulator.md b/docs/advanced-features/tabulator.md index d8c28f26119..147d5e3dfe3 100644 --- a/docs/advanced-features/tabulator.md +++ b/docs/advanced-features/tabulator.md @@ -212,7 +212,9 @@ Tabulator. ### 1. Enable Open Query -An admin can enable open query via the Admin UI: +An admin can enable open query via the `quilt3.admin.tabulator.set_open_query()` +[API](../api-reference/Admin.md#set_open_query) +or Admin UI: ![Tabulator Settings](../imgs/admin-tabulator-settings.png) diff --git a/docs/api-reference/Admin.md b/docs/api-reference/Admin.md index 2474948cbbb..f6352e15819 100644 --- a/docs/api-reference/Admin.md +++ b/docs/api-reference/Admin.md @@ -165,3 +165,13 @@ Set the tabulator table configuration. Pass `None` to remove the table. Rename tabulator table. + +## get\_open\_query() -> bool {#get\_open\_query} + +Get the **open query** status. + + +## set\_open\_query(enabled: bool) -> None {#set\_open\_query} + +Set the **open query** status. +