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

Annual limit sending validation + budget component on ready to send screen #2010

Merged
merged 43 commits into from
Dec 9, 2024

Conversation

andrewleith
Copy link
Member

@andrewleith andrewleith commented Dec 4, 2024

Summary | Résumé

This PR adds validation at notification send time to ensure:

  1. the service has not gone over their annual limit
  2. the send doesn't put the service over their limit

It also updates the ready to send page to:

  1. show the budgeting component to help users understand how many daily and annual messages are remaining
  2. Hide the sending buttons when they have no remaining messages today or this year

Related cards

Screenshots

Error messages for annual limit

image

Changes to template page

Budget component - capacity left

image

Budget component - running out of capacity

image

Budget component - no more left this year

image

Test instructions | Instructions pour tester la modification

Error messages

** Note that is not possible to have the message shown when remaining messages = 0, because the send buttons are now hidden in that case.

Appropriate error message shown when:

  • User attempts to send more EMAILS than DAILY limit allows
  • User attempts to send more EMAILS than ANNUAL limit allows
  • User attempts to send more EMAILS than BOTH limits allows
  • User attempts to send more SMS than DAILY limit allows
  • User attempts to send more SMS than ANNUAL limit allows
  • User attempts to send more SMS than BOTH limit allows

Copy link

github-actions bot commented Dec 4, 2024

@jzbahrai jzbahrai force-pushed the feat/validate-annual-limit-2 branch from 0aeecf7 to e3b67c1 Compare December 5, 2024 17:11
@andrewleith andrewleith marked this pull request as ready for review December 6, 2024 13:52
@andrewleith andrewleith changed the title Feat/validate annual limit 2 Annual limit sending validation + budget component on ready to send screen Dec 6, 2024
from app.models.service import Service


class NotificationCounts:
Copy link
Contributor

Choose a reason for hiding this comment

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

this class 👏🏽

@@ -125,6 +126,31 @@ def get_char_limit_error_msg():
return _("Too many characters")


def get_limit_stats(notification_type):
Copy link
Contributor

Choose a reason for hiding this comment

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

This function feels like a replica for notification_counts_client.get_limit_stats which you call underneath on l#131. Can we just rename it to format_limit_stats? Just so in the future the caller knows this is being set elsewhere

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this is just transforming the data for easy use in this case. I can rename.



# TODO: consolidate this function and other functions that transform the results of template_statistics_client calls
def _aggregate_notifications_stats(template_statistics):
Copy link
Contributor

Choose a reason for hiding this comment

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

what is template_statistics? a dict being set from where?

Copy link
Member Author

Choose a reason for hiding this comment

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

template_statistics is the return structure from the API. Ideally these methods would be closer to that API (i.e. in the template_statistics_client - but it seemed like a big lift for here.

return [s for s in template_statistics if s["status"] != "cancelled"]


def _aggregate_stats_from_service_api(stats):
Copy link
Contributor

Choose a reason for hiding this comment

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

same q as above

Copy link
Member Author

Choose a reason for hiding this comment

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

Same sort of thing. These methods were taken from various controllers and act on the return value of the API calls. It is quite messy.

Copy link
Contributor

Choose a reason for hiding this comment

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

any chance you can add that to the documentation for this class?

@andrewleith andrewleith merged commit 51b10a9 into main Dec 9, 2024
11 checks passed
@andrewleith andrewleith deleted the feat/validate-annual-limit-2 branch December 9, 2024 15:01
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.

3 participants