Skip to content
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

Remove captcha field on WagtailCaptcha and uses AbstractEmailForm to … #2

Merged
merged 4 commits into from
Oct 16, 2016

Conversation

matheusbrat
Copy link
Contributor

…process form

…process form

- Added constant with captcha field name on WagtailCaptchaFormBuilder
- Using constant from WagtailCaptchaFormBuilder on Model to check if it is necessary to remove the field
- Fix #1
Copy link

@unexceptable unexceptable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good, but see comments.

Also there are unused imports you can remove.

def __init__(self, fields):
super(WagtailCaptchaFormBuilder, self).__init__(fields)
# Add wagtailcaptcha to FIELD_TYPES declaration
self.FIELD_TYPES.update({'wagtailcaptcha': self.create_wagtailcaptcha_field})
self.FIELD_TYPES.update({self.CAPTCHA_FIELD_NAME: self.create_wagtailcaptcha_field})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to do the same at line 21:
fields['wagtailcaptcha'] = ReCaptchaField(label='')
to:
fields[self.CAPTCHA_FIELD_NAME] = ReCaptchaField(label='')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. I will fix it when I get to my computer.

if WagtailCaptchaFormBuilder.CAPTCHA_FIELD_NAME in form.fields.keys():
form.fields.pop(WagtailCaptchaFormBuilder.CAPTCHA_FIELD_NAME)

return super(WagtailCaptchaEmailForm, self).process_form_submission(form)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that the captcha doesn't propagate to database, please also add this exact same function to WagtailCaptchaForm.

Copy link
Contributor Author

@matheusbrat matheusbrat Oct 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong about this.

def process_form_submission(self, form):
        FormSubmission.objects.create(
            form_data=json.dumps(form.cleaned_data, cls=DjangoJSONEncoder),
            page=self,
        )

Parent's class uses form.cleaned_data, so removing the field from form.fields will not remove the wagtailcaptcha (captcha field & value) from database. It will only remove from the e-mail sent. Based on this, we don't need to propagate it to WagtailCaptchaForm.

Do you agree @Adrian-Turjak and @thibaudcolas ?

Copy link

@unexceptable unexceptable Oct 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the django-recaptcha code, looks like it will still propagate the captcha challenge. It doesn't matter too much if that data is in the db, but if we want it not stored we can always instead just do:

     def process_form_submission(self, form):
        if WagtailCaptchaFormBuilder.CAPTCHA_FIELD_NAME in form.cleaned_data.keys():
             form.cleaned_data.pop(WagtailCaptchaFormBuilder.CAPTCHA_FIELD_NAME)

         return super(WagtailCaptchaEmailForm, self).process_form_submission(form)

At least that way the code isn't entirely duplicated. Although now I'm curious why AbstractEmailForm isn't using cleaned_data...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we really care about the captcha being saved or not. I created the discussion about saving/not saving the captcha code on the database because I thought the refactoring would change the current behaviour but it doesn't. Therefore the to_address not being correctly handle is solved and the behaviour is preserved, I think we are good to go, but I would like your opinion as well.

In my opinion the discussion about saving/not saving the captcha on the database should be done in a different Issue/PR.

PS: Yes, I'm also curious about why wagtail used fields data directly instead of using cleaned_data.

@thibaudcolas thibaudcolas removed their assignment Oct 3, 2016
@thibaudcolas
Copy link
Contributor

Adrian's suggestions look very sensible. I do not know this codebase at all so un-assigning myself for now.

There doesn't seem to be any tests in this repo so I guess we could use https://github.com/springload/madewithwagtail as our test case before releasing the new version.

@unexceptable
Copy link

Based on discussion, patch looks good to merge. Can test later today against my own project to confirm, but it's a simple and small enough change.

@thibaudcolas probably want to test against madewithwagtail to confirm it doesn't break anything just in case.

@thibaudcolas
Copy link
Contributor

thibaudcolas commented Oct 4, 2016

I'm a noob with python dependencies, would one of you mind explaining me how to install this from GitHub / from a local checkout in an existing virtualenv? Or pointing to a good resource about that topic.

@matheusbrat
Copy link
Contributor Author

matheusbrat commented Oct 4, 2016

Not on my machine but installing it on your machine with virtualenv enabled
with following command should work:

pip install git+git://github.com/springload/wagtail-django-recaptcha.git@bug/send-email

http://stackoverflow.com/questions/8247605/configuring-so-that-pip-install-can-work-from-github
http://stackoverflow.com/questions/20101834/pip-install-from-github-repo-branch

@thibaudcolas
Copy link
Contributor

thibaudcolas commented Oct 10, 2016

I'm expecting to take care of this sometime this week, will merge and then release an update on pypi once it's tested.

@thibaudcolas thibaudcolas self-assigned this Oct 16, 2016
@thibaudcolas thibaudcolas merged commit b0c92ab into master Oct 16, 2016
@thibaudcolas
Copy link
Contributor

Tested on madewithwagtail locally, published as 0.2, and madewithwagtail is now running in production with this version.

🎉 ! Thank you!

@thibaudcolas thibaudcolas deleted the bug/send-email branch October 16, 2016 17:29
haydngreatnews pushed a commit that referenced this pull request Jan 26, 2024
* Update README for latest Wagtail versions (#25)

* Updated tests and documentations

* Fixed Wagtail version until 4.1 for this PR, updated django url to re_path

* Ran updatemodulepaths, isort

* Linting

* Silence warnings

* Added migration file from upgrade

* Fix failing tests

* Linting

* Silence more warnings

* Add github actions

* Fixed .travis.yml to reflect updated tox.ini

* Remove SessionAuthenticationMiddleware

https://docs.djangoproject.com/en/2.0/releases/2.0/#miscellaneous

---------

Co-authored-by: benoitvogel <benoit.vogel@gmail.com>
Co-authored-by: Katherine Domingo <katherine.domingo@torchbox.com>
Co-authored-by: Nick Moreton <nick.moreton@torchbox.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants