Add organization moved exception to mobile app auth (#2422)

# What this PR does

Add organization moved exception to mobile app auth to redirect requests
to correct region

## Which issue(s) this PR fixes

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated
- [ ] Documentation added (or `pr:no public docs` PR label added if not
required)
- [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required)
This commit is contained in:
Yulya Artyukhina 2023-07-05 08:11:56 +02:00 committed by GitHub
parent aeb35009be
commit 4f6cfcca28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -4,6 +4,7 @@ from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication, get_authorization_header
from apps.auth_token.exceptions import InvalidToken
from apps.user_management.exceptions import OrganizationDeletedException, OrganizationMovedException
from apps.user_management.models import User
from .models import MobileAppAuthToken, MobileAppVerificationToken
@ -42,4 +43,9 @@ class MobileAppAuthTokenAuthentication(BaseAuthentication):
except InvalidToken:
return None, None
if auth_token.organization.is_moved:
raise OrganizationMovedException(auth_token.organization)
if auth_token.organization.deleted_at:
raise OrganizationDeletedException(auth_token.organization)
return auth_token.user, auth_token

View file

@ -46,6 +46,8 @@ class OrganizationMovedMiddleware(MiddlewareMixin):
return requests.delete(url, headers=headers)
elif method == "OPTIONS":
return requests.options(url, headers=headers)
elif method == "PATCH":
return requests.patch(url, data=body, headers=headers)
class OrganizationDeletedMiddleware(MiddlewareMixin):