api.py 887 B

123456789101112131415161718192021222324252627
  1. from django.shortcuts import aget_object_or_404
  2. from ninja import Router
  3. from apps.organizations_ext.models import Organization, OrganizationUserRole
  4. from glitchtip.api.authentication import AuthHttpRequest
  5. from glitchtip.api.permissions import has_permission
  6. from .importer import GlitchTipImporter
  7. from .schema import ImportIn
  8. router = Router()
  9. @router.post("import/")
  10. @has_permission(["org:admin"])
  11. async def importer(request: AuthHttpRequest, payload: ImportIn):
  12. organization = await aget_object_or_404(
  13. Organization,
  14. slug=payload.organization_slug,
  15. users=request.auth.user_id,
  16. organization_users__role__gte=OrganizationUserRole.ADMIN,
  17. )
  18. importer = GlitchTipImporter(
  19. str(payload.url), payload.auth_token, payload.organization_slug
  20. )
  21. await importer.check_auth()
  22. await importer.run(organization_id=organization.id)