From 4f6cfcca28108aac538c8c0be3cd2ff782466337 Mon Sep 17 00:00:00 2001 From: Yulya Artyukhina Date: Wed, 5 Jul 2023 08:11:56 +0200 Subject: [PATCH] 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) --- engine/apps/mobile_app/auth.py | 6 ++++++ engine/apps/user_management/middlewares.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/engine/apps/mobile_app/auth.py b/engine/apps/mobile_app/auth.py index 72d0646a..5b1d2497 100644 --- a/engine/apps/mobile_app/auth.py +++ b/engine/apps/mobile_app/auth.py @@ -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 diff --git a/engine/apps/user_management/middlewares.py b/engine/apps/user_management/middlewares.py index 528111e3..d9b65d08 100644 --- a/engine/apps/user_management/middlewares.py +++ b/engine/apps/user_management/middlewares.py @@ -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):