-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Validate url from webhook notification #4983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate url from webhook notification #4983
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4983 +/- ##
==========================================
- Coverage 77.04% 76.86% -0.19%
==========================================
Files 158 158
Lines 10108 9947 -161
Branches 1274 1245 -29
==========================================
- Hits 7788 7646 -142
+ Misses 1989 1968 -21
- Partials 331 333 +2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this.
I suggested a different approach for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good.
I'd like a rework on the view to keep it simple (similar as it was). After this change is done, we can merge it.
I like the tests 💯
) | ||
return HttpResponseRedirect(project_dashboard) | ||
if 'email' in request.POST.keys(): | ||
email_form = EmailHookForm(data=request.POST, project=project) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave the all this code as it was, but calling the is_valid
method on the right form only after checking request.POST.keys
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the flow to me:
if 'url' in request.POST.keys() and webhook_form.is_valid():
webhook_form.save()
if 'email' in request.POST.keys() and email_form.is_valid():
email_form.save()
The rest of the code should be as it was before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also give rise to the same situation (tried on local server).
This is what is happening
>>> from readthedocs.projects.forms import WebHookForm
>>> from readthedocs.projects.models import Project
>>> proj = Project.objects.get(slug='pikachu-demo')
>>> data = {'url': ''}
>>> form = WebHookForm(data=data, project=proj)
>>> form
<WebHookForm bound=True, valid=Unknown, fields=(url)>
>>> form.errors
{'url': ['This field is required.']}
>>> form
<WebHookForm bound=True, valid=False, fields=(url)>
So with these lines
email_form = EmailHookForm(data=request.POST or None, project=project)
webhook_form = WebHookForm(data=request.POST or None, project=project)
even the user hasn't submitted the email_form, the error will rise and will be shown in the templates even if the is_valid()
method is not run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even the user hasn't submitted the email_form, the error will rise and will be shown in the templates even if the
is_valid()
method is not run
Really?! Wow! I didn't know that and it's an unexpected behavior to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, it's because email form will then accept data=request.POST
,
but yeahh.. it's unexpected the error is generated without calling is_valid()
method
I suppose that we can manually delete these from .org db once this PR gets merged,
These are useless and just produce our code to fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are fine merging this once conflicts are solved and all the tests pass.
@humitos Edit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. 👍
No. I want to probably turn that check off, it's annoying :/ |
Fixes #4981