Email and phone limits now environment variable (#1219)

# What this PR does
Email and phone limits now environment variables:
EMAIL_NOTIFICATIONS_LIMIT=200, PHONE_NOTIFICATIONS_LIMIT=200

## Which issue(s) this PR fixes
#1010

## Checklist

- [ ] Tests updated
- [x] Documentation added
- [x] `CHANGELOG.md` updated

---------

Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
This commit is contained in:
ak0nst 2023-03-07 14:48:05 +04:00 committed by GitHub
parent a50ec8fed2
commit 44e93b6ab4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)]

View file

@ -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 }}