wagtail/wagtail-ai

The proccess view should use form validation

Closed this issue · 5 comments

tm-kn commented

Right now we don't do any validation on the process endpoint. A massive ick as it does not feel like an adequate user/external input validation.

text = request.POST.get("text")
if not text:
return JsonResponse(
{
"error": "No text provided - please enter some text before using AI \
features"
},
status=400,
)
prompt_id = request.POST.get("prompt")
try:
prompt = Prompt.objects.get(uuid=prompt_id)
except Prompt.DoesNotExist:
return JsonResponse({"error": "Invalid prompt provided"}, status=400)

We want to replace the HttpRequest.POST references and replace it with a Django form validation.

We should wrap this into a Django form to benefit from any Django defaults and put good practice in place for the future.

kituuu commented

Can I work on this @tm-kn ?

Hi @kituuu - thanks for offering to contribute!

Feel free to work on this one if you'd like to.

kituuu commented

Hey, @tomusher, can you tell me where I can find contribution instructions and dev environment setup instructions?
Current contribution.md is empty... (https://github.com/wagtail/wagtail-ai/blob/main/CONTRIBUTING.md)

@kituuu sorry, I ended up sorting this out in #48.

Thank you for point out that CONTRIBUTION.md is empty. Will try to add something

kituuu commented

@kituuu sorry, I ended up sorting this out in #48.

Thank you for point out that CONTRIBUTION.md is empty. Will try to add something

Np, if there are any other issues. Pls let me know.