quota_notifier.notify

Handling of user notifications and notification history.

The notify module provides logic for checking if users have pending notifications and issuing those notifications via email.

Module Contents

class quota_notifier.notify.EmailTemplate(quotas: Collection[AbstractQuota])[source]

A formattable email template to notify users about their disk quota usage

email_subject = 'CRC Disk Usage Alert'
email_from = 'no-reply@domain.com'
email_template = '<p>\n  This is an automated notification concerning your storage quota.\n  One or more of your quotas has recently surpassed a usage threshold triggering an automated notification.\n  Your storage usage is as follows:\n</p>\n<p>\n  {usage_summary}\n</p>\n<p>\n  Sincerely,\n</p>\n<p>\n  The CRC Quota Bot\n</p>\n'
__init__(quotas: Collection[AbstractQuota]) None[source]

Generate a formatted instance of the email template

Parameters:

quotas – Disk quotas to mention in the email

send_to_user(user: User, smtp: SMTP | None = None) EmailMessage[source]

Send the formatted email to the given username

Parameters:
  • user – Name of the user to send to

  • smtp – Optionally use a custom SMTP server

send(address: str, smtp: SMTP | None = None) EmailMessage[source]

Send the formatted email to the given email address

The default smtp server is determined via the current application settings.

Parameters:
  • address – Destination email address

  • smtp – Optionally use a custom SMTP server

class quota_notifier.notify.UserNotifier[source]

Issue and manage user quota notifications

classmethod get_users() Iterable[User][source]

Return a collection of users to check quotas for

Returns:

An iterable collection of User objects

static get_user_quotas(user: User) List[AbstractQuota][source]

Return a tuple of quotas assigned to a given user

Parameters:

user – The user to fetch quotas for

Returns:

An iterable collection of quota objects

static get_last_threshold(session: Session, quota: AbstractQuota) int | None[source]

Return the last threshold a user was notified for

If no previous notification history can be found, the return value is None

Parameters:
  • session – Active database session for performing select queries

  • quota – The quota to get a threshold for

Returns:

The last notification or None if there was no notification

static get_next_threshold(quota: AbstractQuota) int | None[source]

Return the next threshold a user should be notified for

The return value will be less than or equal to the current quota usage. If there is no notification threshold less than the current usage, the return value is None.

Parameters:

quota – The quota to get a threshold for

Returns:

The largest notification threshold that is less than the current usage or None

notify_user(user: User) None[source]

Send any pending email notifications the given user

Parameters:

user – The user to send a notification to

send_notifications() None[source]

Send email notifications to any users who have exceeded a notification threshold