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

Warn expiring users #56

Closed
wants to merge 24 commits into from
Closed

Warn expiring users #56

wants to merge 24 commits into from

Conversation

missytake
Copy link
Contributor

@missytake missytake commented Oct 1, 2022

closes #21

the idea is to warn users a certain timespan before their accounts run out:

  • if their token is 1year or longer, a month, a week, and a day before expiration date
  • if their token is 1month or longer, a week and a day before expiration date
  • if their token is 1week or longer, a day before expiration date
  • if it's shorter than that, after 3/4 of the expiration notice, they get told how much they have left either in minutes or hours.

right now, the expiration warnings are triggered by the prune loop; this is a bit unfortunate as it means that we have to initialize another deltachat.account object for the mailadm bot, and can't reuse the bot object. Maybe that's fine, it just complicates the handling a bit.

I tried it out manually, works so far. There are 2 tests, one of them could be more minimal I guess.

Does the database migration need a test?

src/mailadm/conn.py Outdated Show resolved Hide resolved
src/mailadm/db.py Outdated Show resolved Hide resolved
@missytake
Copy link
Contributor Author

missytake commented Oct 1, 2022

Screenshot_2022-10-01_20-20-41

That's how it looks so far - it would be reeeeally nice to have this in a legit "provider chat" in the future <3

There is #57 to make this a bit nicer already :)

@missytake missytake changed the title WIP: Warn expiring users Warn expiring users Oct 1, 2022
@missytake
Copy link
Contributor Author

We called and decided that we will not support the use case of running mailadm without a bot; the prune thread will only be started as soon as we have a working bot account object.

src/mailadm/app.py Outdated Show resolved Hide resolved
src/mailadm/conn.py Outdated Show resolved Hide resolved
src/mailadm/app.py Outdated Show resolved Hide resolved
src/mailadm/conn.py Outdated Show resolved Hide resolved
tests/test_conn.py Outdated Show resolved Hide resolved
tests/test_conn.py Outdated Show resolved Hide resolved
tests/test_conn.py Outdated Show resolved Hide resolved
Copy link
Contributor

@hpk42 hpk42 left a comment

Choose a reason for hiding this comment

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

thanks for the nice work and tests. It's a bit intricate if the policy (when to warn) changes to change all the tests but that's ok for now i guess.
Having the prune_loop re-use the bot account would be good and removing the redundancy as commented. thanks!

@missytake missytake requested a review from hpk42 October 5, 2022 09:39
src/mailadm/conn.py Outdated Show resolved Hide resolved
Comment on lines +247 to +253
if user.ttl >= year:
if user.warned == 0 and user.date + user.ttl < sysdate + month:
timeleft = "30 days"
elif user.warned == 1 and user.date + user.ttl < sysdate + week:
timeleft = "7 days"
elif user.warned == 2 and user.date + user.ttl < sysdate + day:
timeleft = "1 day"
Copy link
Contributor

Choose a reason for hiding this comment

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

only occurs to me now (sorry) but what if for some reason the bot doesn't run for a few days, and then performs this expiry check? Will we not send a message "expired in 7 days" but it might only be "4 days" actually?
We are only ever warning about "X days" so maybe there can be helper function that computers the number of remaining days irrespective how often expiry-checking is performed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the message should be "You account will expire at UTC-DATE, about N days from now."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. Problem: imo we can't expect users to know in which timezone they are. Maybe we can avoid timezone specifics? for most users a date would be enough, and if the time is shorter, just saying how many hours it will take should be enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, we are anyway missing localization as well.


def __init__(self, addr, date, ttl, token_name):
def __init__(self, addr, date, ttl, token_name, warned=0):
Copy link
Contributor

Choose a reason for hiding this comment

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

why does it need a default of 0 here?

src/mailadm/conn.py Outdated Show resolved Hide resolved
tests/test_conn.py Outdated Show resolved Hide resolved
Comment on lines +121 to +131
def test_users_to_warn(conn, monkeypatch):
yeartoken = conn.add_token("1y", token="asd1", expiry="1y", prefix="tmp.")
monthtoken = conn.add_token("1m", token="asd2", expiry="1m", prefix="tmp.")
weektoken = conn.add_token("1w", token="asd3", expiry="1w", prefix="tmp.")
daytoken = conn.add_token("1d", token="asd4", expiry="1d", prefix="tmp.")

yearuser = conn.add_email_account(yeartoken)
monthuser = conn.add_email_account(monthtoken)
weekuser = conn.add_email_account(weektoken)
dayuser = conn.add_email_account(daytoken)
Copy link
Contributor

Choose a reason for hiding this comment

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

a bit skeptical of this test_users_to_warn functions -- a bit intricate to follow and a lot of boilerplate. When we change the logic/ warning rhythm it might also break easily. but not sure it's worth to refactor now. The other point (of having a get_users_to_warn that produces messages fitting tot he current time) is probably more important.

Copy link
Contributor

@hpk42 hpk42 left a comment

Choose a reason for hiding this comment

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

better improve the warnings to be less timing (downtime) sensitive

@missytake
Copy link
Contributor Author

This needs to be done again, but it only makes sense after we decided on #78.

@missytake missytake closed this Jan 7, 2023
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.

Users aren't notified that their account is running out
2 participants