# 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)
26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
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 InstallView(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"]
|
|
|
|
organization = Organization.objects_with_deleted.filter(stack_id=stack_id, org_id=org_id).first()
|
|
# If we receive install request to the deleted org - just restore it.
|
|
organization.deleted_at = None
|
|
organization.api_token = self.instance_context["grafana_token"]
|
|
organization.save(update_fields=["api_token", "deleted_at"])
|
|
|
|
sync_organization(organization)
|
|
return Response(status=status.HTTP_204_NO_CONTENT)
|