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

sponsor_renew_request not redirecting after sending mail #841

Closed
lentinj opened this issue Apr 26, 2024 · 4 comments · Fixed by #845
Closed

sponsor_renew_request not redirecting after sending mail #841

lentinj opened this issue Apr 26, 2024 · 4 comments · Fixed by #845

Comments

@lentinj
Copy link
Collaborator

lentinj commented Apr 26, 2024

The controller isn't redirecting back to a GET version of the page:

def sponsor_renew_request():
"""
Request a renewal link emailed to you.
"""
form = FORM(
LABEL("E-mail or Username"),
INPUT(_name='user_identifier', _class="uk-input uk-margin-bottom"),
INPUT(_type='submit', _class="oz-pill pill-leaf"))
if form.accepts(request.vars, session=None):
response.flash = sponsor_renew_request_logic(
form.vars.user_identifier.strip(),
mailer=ozmail.get_mailer()
)
return dict(
form=form,
)

It should have a redirect() on success, kinda like: http://web2py.com/books/default/chapter/34/07/forms-and-validators#Forms-and-redirection, so a reload of the page doesn't send another e-mail.

@hyanwong this isn't necessarily the root of your late night email avalanche, I've no idea why a browser would try and reload 8 times, but if it does it again then there should be no problems in doing so.

@hyanwong
Copy link
Member

Ah, that's great. Thanks @lentinj. Shall I add the redirect() or do you want to.

Do we need a "unit" test for this behaviour? I'm guessing that's a bit tricky with the current setup.

@jrosindell
Copy link
Member

I've done a bit of testing here. The first time I requested I got two e-mails because after clicking the 'submit' button nothing was obviously happening and so I clicked it again. A little while later I tested it with what was consciously a single click and I got a single e-mail.

@lentinj
Copy link
Collaborator Author

lentinj commented Apr 28, 2024

Shall I add the redirect() or do you want to.

I'll have a look if I've time Monday.

Do we need a "unit" test for this behaviour? I'm guessing that's a bit tricky with the current setup.

It's straying into unit-test-configuration territory, but it's still worthwhile.

The main faff with the unit test setup is mocking the mailer. We could probably achieve that with something similar to https://github.com/OneZoom/OZtree/blob/2f51d56262182e70c09fe30ce62c44d9b423e74c/tests/unit/test_controllers_default_sponsor.py.

But worst case, we don't actually care here. As long as we use an example.com address we'll have no side effects, even if the site configuration specifies a working mailer. All we care about is we managed to call sponsor_renew_request_logic and got some kind of flash message back.

@hyanwong
Copy link
Member

That would be great. Thanks @lentinj

lentinj added a commit that referenced this issue Apr 30, 2024
To avoid potential resent emails on refresh, send a 303 redirect to the
current page after successful e-mail send.

This means we need to store the flash message in the session, which
isn't ideal, but is already on our radar anyway.
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 a pull request may close this issue.

3 participants