diff --git a/CHANGELOG.md b/CHANGELOG.md index ce4e3096..9450b820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Show permission error for accessing Telegram as Viewer ([1273](https://github.com/grafana/oncall/issues/1273)) +### Changed + +- Pass email and phone limits as environment variables ([1219](https://github.com/grafana/oncall/pull/1219)) + ## v1.1.32 (2023-03-01) ### Fixed diff --git a/docs/sources/open-source/_index.md b/docs/sources/open-source/_index.md index f5f541ea..bd389f64 100644 --- a/docs/sources/open-source/_index.md +++ b/docs/sources/open-source/_index.md @@ -224,6 +224,14 @@ the following env variables with your SMTP server credentials: After enabling the email integration, it will be possible to use the `Notify by email` notification step in user settings. +## Limits + +By default, Grafana OnCall limits email and phone notifications (calls, SMS) to 200 per user per day. +The limit can be changed using env variables: + +- `PHONE_NOTIFICATIONS_LIMIT` (default is `200`) - phone notifications per user +- `EMAIL_NOTIFICATIONS_LIMIT` (default is `200`) - emails per user + ## Mobile application set up >**Note**: This application is currently in beta diff --git a/engine/apps/user_management/subscription_strategy/free_public_beta_subscription_strategy.py b/engine/apps/user_management/subscription_strategy/free_public_beta_subscription_strategy.py index dcd0be9f..db92ce37 100644 --- a/engine/apps/user_management/subscription_strategy/free_public_beta_subscription_strategy.py +++ b/engine/apps/user_management/subscription_strategy/free_public_beta_subscription_strategy.py @@ -1,4 +1,5 @@ from django.apps import apps +from django.conf import settings from django.utils import timezone from apps.email.models import EmailMessage @@ -13,9 +14,6 @@ class FreePublicBetaSubscriptionStrategy(BaseSubscriptionStrategy): User management and limitations happens on grafana side. """ - PHONE_NOTIFICATIONS_LIMIT = 200 - EMAILS_LIMIT = 200 - def phone_calls_left(self, user): return self._calculate_phone_notifications_left(user) @@ -76,8 +74,8 @@ class FreePublicBetaSubscriptionStrategy(BaseSubscriptionStrategy): @property def _phone_notifications_limit(self): - return self.PHONE_NOTIFICATIONS_LIMIT + return settings.PHONE_NOTIFICATIONS_LIMIT @property def _emails_limit(self): - return self.EMAILS_LIMIT + return settings.EMAIL_NOTIFICATIONS_LIMIT diff --git a/engine/settings/base.py b/engine/settings/base.py index 3ff5d37a..904ae277 100644 --- a/engine/settings/base.py +++ b/engine/settings/base.py @@ -69,6 +69,7 @@ TWILIO_ACCOUNT_SID = os.environ.get("TWILIO_ACCOUNT_SID") TWILIO_AUTH_TOKEN = os.environ.get("TWILIO_AUTH_TOKEN") TWILIO_NUMBER = os.environ.get("TWILIO_NUMBER") TWILIO_VERIFY_SERVICE_SID = os.environ.get("TWILIO_VERIFY_SERVICE_SID") +PHONE_NOTIFICATIONS_LIMIT = getenv_integer("PHONE_NOTIFICATIONS_LIMIT", 200) TELEGRAM_WEBHOOK_HOST = os.environ.get("TELEGRAM_WEBHOOK_HOST", BASE_URL) TELEGRAM_TOKEN = os.environ.get("TELEGRAM_TOKEN") @@ -608,6 +609,7 @@ EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD") EMAIL_PORT = getenv_integer("EMAIL_PORT", 587) EMAIL_USE_TLS = getenv_boolean("EMAIL_USE_TLS", True) EMAIL_FROM_ADDRESS = os.getenv("EMAIL_FROM_ADDRESS") +EMAIL_NOTIFICATIONS_LIMIT = getenv_integer("EMAIL_NOTIFICATIONS_LIMIT", 200) if FEATURE_EMAIL_INTEGRATION_ENABLED: EXTRA_MESSAGING_BACKENDS += [("apps.email.backend.EmailBackend", 8)] diff --git a/helm/oncall/templates/_env.tpl b/helm/oncall/templates/_env.tpl index b0b98302..71e69fb9 100644 --- a/helm/oncall/templates/_env.tpl +++ b/helm/oncall/templates/_env.tpl @@ -137,6 +137,10 @@ MIRAGE_SECRET_KEY - name: TWILIO_API_KEY_SECRET value: {{ .apiKeySecret | quote }} {{- end -}} +{{- if .limitPhone }} +- name: PHONE_NOTIFICATIONS_LIMIT + value: {{ .limitPhone | quote }} +{{- end -}} {{- end -}} {{- end -}} @@ -431,6 +435,8 @@ rabbitmq-password value: {{ .Values.oncall.smtp.tls | default true | toString | title | quote }} - name: EMAIL_FROM_ADDRESS value: {{ .Values.oncall.smtp.fromEmail | quote }} +- name: EMAIL_NOTIFICATIONS_LIMIT + value: {{ .Values.oncall.smtp.limitEmail | default "200" | quote }} {{- else -}} - name: FEATURE_EMAIL_INTEGRATION_ENABLED value: {{ .Values.oncall.smtp.enabled | toString | title | quote }}