api.py 931 B

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