diff --git a/.dockerignore b/.dockerignore index 1a9721c..fdb7437 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,6 +6,9 @@ .pre-commit-config.yaml .venv /fly.* +/static-collected +/takahe/local_settings.py +__pycache__/ media notes.md venv diff --git a/api/views/apps.py b/api/views/apps.py index ebb883e..758aa49 100644 --- a/api/views/apps.py +++ b/api/views/apps.py @@ -1,28 +1,27 @@ import secrets -from hatchway import Schema, api_view +from hatchway import QueryOrBody, api_view from .. import schemas from ..models import Application -class CreateApplicationSchema(Schema): - client_name: str - redirect_uris: str - scopes: None | str = None - website: None | str = None - - @api_view.post -def add_app(request, details: CreateApplicationSchema) -> schemas.Application: +def add_app( + request, + client_name: QueryOrBody[str], + redirect_uris: QueryOrBody[str], + scopes: QueryOrBody[None | str] = None, + website: QueryOrBody[None | str] = None, +) -> schemas.Application: client_id = "tk-" + secrets.token_urlsafe(16) client_secret = secrets.token_urlsafe(40) application = Application.objects.create( - name=details.client_name, - website=details.website, + name=client_name, + website=website, client_id=client_id, client_secret=client_secret, - redirect_uris=details.redirect_uris, - scopes=details.scopes or "read", + redirect_uris=redirect_uris, + scopes=scopes or "read", ) return schemas.Application.from_orm(application) diff --git a/api/views/instance.py b/api/views/instance.py index e1a7d49..f539fbd 100644 --- a/api/views/instance.py +++ b/api/views/instance.py @@ -47,6 +47,12 @@ def instance_info_v1(request): "image_size_limit": (1024**2) * 10, "image_matrix_limit": 2000 * 2000, }, + "polls": { + "max_options": 4, + "max_characters_per_option": 50, + "min_expiration": 300, + "max_expiration": 2629746, + }, }, "contact_account": None, "rules": [], diff --git a/tests/api/test_apps.py b/tests/api/test_apps.py index f4cfbb7..eac212c 100644 --- a/tests/api/test_apps.py +++ b/tests/api/test_apps.py @@ -4,10 +4,8 @@ import pytest @pytest.mark.django_db def test_create(api_client): """ - Tests creating an app + Tests creating an app with mixed query/body params (some clients do this) """ - response = api_client.post( - "/api/v1/apps", {"client_name": "test", "redirect_uris": ""} - ) + response = api_client.post("/api/v1/apps?client_name=test", {"redirect_uris": ""}) assert response.status_code == 200 assert response.json()["name"] == "test"