Co-authored-by: Eve832 <eve.meelan@grafana.com>
Co-authored-by: Francisco Montes de Oca <nevermind89x@gmail.com>
Co-authored-by: Ildar Iskhakov <ildar.iskhakov@grafana.com>
Co-authored-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
Co-authored-by: Julia <ferril.darkdiver@gmail.com>
Co-authored-by: maskin25 <kengurek@gmail.com>
Co-authored-by: Matias Bordese <mbordese@gmail.com>
Co-authored-by: Matvey Kukuy <motakuk@gmail.com>
Co-authored-by: Michael Derynck <michael.derynck@grafana.com>
Co-authored-by: Richard Hartmann <richih@richih.org>
Co-authored-by: Robby Milo <robbymilo@fastmail.com>
Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com>
Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
Co-authored-by: Yulia Shanyrova <yulia.shanyrova@grafana.com>
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
from django.apps import apps
|
|
from django.conf import settings
|
|
from rest_framework.response import Response
|
|
from rest_framework.views import APIView
|
|
|
|
from apps.auth_token.auth import PluginAuthentication
|
|
|
|
FEATURE_SLACK = "slack"
|
|
FEATURE_TELEGRAM = "telegram"
|
|
FEATURE_LIVE_SETTINGS = "live_settings"
|
|
MOBILE_APP_PUSH_NOTIFICATIONS = "mobile_app"
|
|
|
|
|
|
class FeaturesAPIView(APIView):
|
|
"""
|
|
Return whitelist of enabled features.
|
|
It is needed to disable features for On-prem installations.
|
|
"""
|
|
|
|
authentication_classes = (PluginAuthentication,)
|
|
|
|
def get(self, request):
|
|
return Response(self._get_enabled_features(request))
|
|
|
|
def _get_enabled_features(self, request):
|
|
enabled_features = []
|
|
|
|
if settings.FEATURE_SLACK_INTEGRATION_ENABLED:
|
|
enabled_features.append(FEATURE_SLACK)
|
|
|
|
if settings.FEATURE_TELEGRAM_INTEGRATION_ENABLED:
|
|
enabled_features.append(FEATURE_TELEGRAM)
|
|
|
|
if settings.FEATURE_LIVE_SETTINGS_ENABLED:
|
|
enabled_features.append(FEATURE_LIVE_SETTINGS)
|
|
|
|
if settings.MOBILE_APP_PUSH_NOTIFICATIONS_ENABLED:
|
|
DynamicSetting = apps.get_model("base", "DynamicSetting")
|
|
mobile_app_settings = DynamicSetting.objects.get_or_create(
|
|
name="mobile_app_settings",
|
|
defaults={
|
|
"json_value": {
|
|
"org_ids": [],
|
|
}
|
|
},
|
|
)[0]
|
|
|
|
if request.auth.organization.pk in mobile_app_settings.json_value["org_ids"]:
|
|
enabled_features.append(MOBILE_APP_PUSH_NOTIFICATIONS)
|
|
|
|
return enabled_features
|