* Add cloud connection statuses on user page * Add fixes for oncall hobby docker-compose installation * Fix for links and for cloud user status at User settings * Delete cloud api token on cloud disconnect * Merge branch 'dev' into cloud_connection_statuses_on_user_page * Fix cloud statuses for users * Fix usagestats service * Fix phone verification message in users table * added request after syncing user * Add endpoint to create CloudHeartbeat and polish code * Fix imports * Check token and heartbeat setting in setup_hertbeat_integration * Add macthed_users_count in cloud users * Sync users on token change * Fix query param * Fix tests * Heartbit button logic, tab width fix, coount users fix * Solve problem of existent cloud heartbeat integration * Solve problem of existent cloud heartbeat integration 2 * Solve problem of existent cloud heartbeat integration 3 * fix build * build fix, styles for env variables description Co-authored-by: Ildar Iskhakov <ildar.iskhakov@grafana.com> Co-authored-by: Yulia Shanyrova <yulia.shanyrova@grafana.com>
39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
from rest_framework import status
|
|
from rest_framework.permissions import IsAuthenticated
|
|
from rest_framework.response import Response
|
|
from rest_framework.views import APIView
|
|
|
|
from apps.api.permissions import IsAdmin
|
|
from apps.auth_token.auth import PluginAuthentication
|
|
from apps.base.models import LiveSetting
|
|
from apps.base.utils import live_settings
|
|
from apps.oss_installation.cloud_heartbeat import get_heartbeat_link
|
|
from apps.oss_installation.models import CloudConnector, CloudHeartbeat
|
|
|
|
|
|
class CloudConnectionView(APIView):
|
|
authentication_classes = (PluginAuthentication,)
|
|
permission_classes = (IsAuthenticated, IsAdmin)
|
|
|
|
def get(self, request):
|
|
connector = CloudConnector.objects.first()
|
|
heartbeat = CloudHeartbeat.objects.first()
|
|
response = {
|
|
"cloud_connection_status": connector is not None,
|
|
"cloud_notifications_enabled": live_settings.GRAFANA_CLOUD_NOTIFICATIONS_ENABLED,
|
|
"cloud_heartbeat_enabled": live_settings.GRAFANA_CLOUD_ONCALL_HEARTBEAT_ENABLED,
|
|
"cloud_heartbeat_link": get_heartbeat_link(connector, heartbeat),
|
|
"cloud_heartbeat_status": heartbeat is not None and heartbeat.success,
|
|
}
|
|
return Response(response)
|
|
|
|
def delete(self, request):
|
|
s = LiveSetting.objects.filter(name="GRAFANA_CLOUD_ONCALL_TOKEN").first()
|
|
if s is not None:
|
|
s.value = None
|
|
s.save()
|
|
connector = CloudConnector.objects.first()
|
|
if connector is None:
|
|
return Response(status=status.HTTP_404_NOT_FOUND)
|
|
connector.remove_sync()
|
|
return Response(status=status.HTTP_204_NO_CONTENT)
|