oncall-engine/engine/apps/grafana_plugin/views/sync_organization.py
Michael Derynck 0dfa882a06
Return API URL as part of status (#2791)
# What this PR does
- Provide API URL when returning status to inform plugin or mobile app
if it should be talking to a different backend in case of migration.
- Add MobileAppAuthTokenAuthentication to status endpoint so that the
app can use it.
- Split PluginAuthentication (Checks user) and BasePluginAuthentication
(Does not check user) and use BasePluginAuthentication in grafana-plugin
app when getting status.
- Removed PluginTokenVerified since it can be handled by
BasePluginAuthentication.
- Removed deprecated endpoints from grafana-plugin app. 

## Which issue(s) this PR fixes

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
2023-08-22 17:17:26 +00:00

25 lines
925 B
Python

from contextlib import suppress
from rest_framework import status
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView
from apps.auth_token.auth import BasePluginAuthentication
from apps.user_management.models import Organization
from apps.user_management.sync import sync_organization
from common.api_helpers.mixins import GrafanaHeadersMixin
class SyncOrganizationView(GrafanaHeadersMixin, APIView):
authentication_classes = (BasePluginAuthentication,)
def post(self, request: Request) -> Response:
stack_id = self.instance_context["stack_id"]
org_id = self.instance_context["org_id"]
with suppress(Organization.DoesNotExist):
organization = Organization.objects.get(stack_id=stack_id, org_id=org_id)
sync_organization(organization)
return Response(status=status.HTTP_200_OK)