kopia lustrzana https://github.com/simonw/datasette
Redirect /-/config to /-/settings, closes #1103
rodzic
3159263f05
commit
2a3d5b720b
|
@ -66,6 +66,7 @@ from .utils.asgi import (
|
|||
Forbidden,
|
||||
NotFound,
|
||||
Request,
|
||||
Response,
|
||||
asgi_static,
|
||||
asgi_send,
|
||||
asgi_send_html,
|
||||
|
@ -884,8 +885,16 @@ class Datasette:
|
|||
r"/-/plugins(?P<as_format>(\.json)?)$",
|
||||
)
|
||||
add_route(
|
||||
JsonDataView.as_view(self, "config.json", lambda: self._config),
|
||||
r"/-/config(?P<as_format>(\.json)?)$",
|
||||
JsonDataView.as_view(self, "settings.json", lambda: self._config),
|
||||
r"/-/settings(?P<as_format>(\.json)?)$",
|
||||
)
|
||||
add_route(
|
||||
permanent_redirect("/-/settings.json"),
|
||||
r"/-/config.json",
|
||||
)
|
||||
add_route(
|
||||
permanent_redirect("/-/settings"),
|
||||
r"/-/config",
|
||||
)
|
||||
add_route(
|
||||
JsonDataView.as_view(self, "threads.json", self._threads),
|
||||
|
@ -1224,6 +1233,13 @@ def wrap_view(view_fn, datasette):
|
|||
return async_view_fn
|
||||
|
||||
|
||||
def permanent_redirect(path):
|
||||
return wrap_view(
|
||||
lambda request, send: Response.redirect(path, status=301),
|
||||
datasette=None,
|
||||
)
|
||||
|
||||
|
||||
_curly_re = re.compile(r"(\{.*?\})")
|
||||
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ def menu_links(datasette, actor):
|
|||
"label": "Metadata",
|
||||
},
|
||||
{
|
||||
"href": datasette.urls.path("/-/config"),
|
||||
"label": "Config",
|
||||
"href": datasette.urls.path("/-/settings"),
|
||||
"label": "Settings",
|
||||
},
|
||||
{
|
||||
"href": datasette.urls.path("/-/permissions"),
|
||||
|
|
|
@ -89,10 +89,10 @@ Add ``?all=1`` to include details of the default plugins baked into Datasette.
|
|||
|
||||
.. _JsonDataView_config:
|
||||
|
||||
/-/config
|
||||
---------
|
||||
/-/settings
|
||||
-----------
|
||||
|
||||
Shows the :ref:`config` options for this instance of Datasette. `Config example <https://fivethirtyeight.datasettes.com/-/config>`_:
|
||||
Shows the :ref:`config` options for this instance of Datasette. `Settings example <https://fivethirtyeight.datasettes.com/-/settings>`_:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
|
@ -110,7 +110,7 @@ Shows the :ref:`config` options for this instance of Datasette. `Config example
|
|||
/-/databases
|
||||
------------
|
||||
|
||||
Shows currently attached databases. `Databases example <https://latest.datasette.io/-/config>`_:
|
||||
Shows currently attached databases. `Databases example <https://latest.datasette.io/-/databases>`_:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
|
|
|
@ -1324,8 +1324,8 @@ def test_versions_json(app_client):
|
|||
assert "compile_options" in response.json["sqlite"]
|
||||
|
||||
|
||||
def test_config_json(app_client):
|
||||
response = app_client.get("/-/config.json")
|
||||
def test_settings_json(app_client):
|
||||
response = app_client.get("/-/settings.json")
|
||||
assert {
|
||||
"default_page_size": 50,
|
||||
"default_facet_size": 30,
|
||||
|
@ -1350,6 +1350,19 @@ def test_config_json(app_client):
|
|||
} == response.json
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"path,expected_redirect",
|
||||
(
|
||||
("/-/config.json", "/-/settings.json"),
|
||||
("/-/config", "/-/settings"),
|
||||
),
|
||||
)
|
||||
def test_config_redirects_to_settings(app_client, path, expected_redirect):
|
||||
response = app_client.get(path, allow_redirects=False)
|
||||
assert response.status == 301
|
||||
assert response.headers["Location"] == expected_redirect
|
||||
|
||||
|
||||
def test_page_size_matching_max_returned_rows(
|
||||
app_client_returned_rows_matches_page_size,
|
||||
):
|
||||
|
|
|
@ -177,7 +177,7 @@ def test_version():
|
|||
def test_setting(ensure_eventloop):
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
cli, ["--setting", "default_page_size", "5", "--get", "/-/config.json"]
|
||||
cli, ["--setting", "default_page_size", "5", "--get", "/-/settings.json"]
|
||||
)
|
||||
assert result.exit_code == 0, result.output
|
||||
assert json.loads(result.output)["default_page_size"] == 5
|
||||
|
@ -194,7 +194,7 @@ def test_config_deprecated(ensure_eventloop):
|
|||
# The --config option should show a deprecation message
|
||||
runner = CliRunner(mix_stderr=False)
|
||||
result = runner.invoke(
|
||||
cli, ["--config", "allow_download:off", "--get", "/-/config.json"]
|
||||
cli, ["--config", "allow_download:off", "--get", "/-/settings.json"]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert not json.loads(result.output)["allow_download"]
|
||||
|
|
|
@ -86,7 +86,7 @@ def test_metadata(config_dir_client):
|
|||
|
||||
|
||||
def test_config(config_dir_client):
|
||||
response = config_dir_client.get("/-/config.json")
|
||||
response = config_dir_client.get("/-/settings.json")
|
||||
assert 200 == response.status
|
||||
assert 60 == response.json["default_cache_ttl"]
|
||||
|
||||
|
|
|
@ -378,7 +378,7 @@ def view_instance_client():
|
|||
"/-/metadata",
|
||||
"/-/versions",
|
||||
"/-/plugins",
|
||||
"/-/config",
|
||||
"/-/settings",
|
||||
"/-/threads",
|
||||
"/-/databases",
|
||||
"/-/actor",
|
||||
|
|
Ładowanie…
Reference in New Issue