decorator: Move self_hosting_management_endpoint wrapper to corporate.

This commit is contained in:
Aman Agrawal 2023-11-26 17:29:51 +00:00 committed by Tim Abbott
parent c79d116f8c
commit 354330d81b
4 changed files with 29 additions and 22 deletions

View File

@ -0,0 +1,26 @@
from functools import wraps
from typing import Callable, TypeVar
from django.conf import settings
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from typing_extensions import Concatenate, ParamSpec
from zerver.lib.subdomains import get_subdomain
ParamT = ParamSpec("ParamT")
def self_hosting_management_endpoint(
view_func: Callable[Concatenate[HttpRequest, ParamT], HttpResponse]
) -> Callable[Concatenate[HttpRequest, ParamT], HttpResponse]: # nocoverage
@wraps(view_func)
def _wrapped_view_func(
request: HttpRequest, /, *args: ParamT.args, **kwargs: ParamT.kwargs
) -> HttpResponse:
subdomain = get_subdomain(request)
if not settings.DEVELOPMENT or subdomain != settings.SELF_HOSTING_MANAGEMENT_SUBDOMAIN:
return render(request, "404.html", status=404)
return view_func(request, *args, **kwargs)
return _wrapped_view_func

View File

@ -10,11 +10,11 @@ from django.utils.translation import gettext as _
from django.views.decorators.csrf import csrf_exempt
from pydantic import Json
from corporate.lib.decorator import self_hosting_management_endpoint
from corporate.lib.remote_billing_util import (
RemoteBillingIdentityDict,
get_identity_dict_from_session,
)
from zerver.decorator import self_hosting_management_endpoint
from zerver.lib.exceptions import JsonableError, MissingRemoteRealmError
from zerver.lib.remote_server import RealmDataForAnalytics, UserDataForRemoteBilling
from zerver.lib.response import json_success

View File

@ -8,6 +8,7 @@ from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from pydantic import Json
from corporate.lib.decorator import self_hosting_management_endpoint
from corporate.lib.remote_billing_util import get_remote_realm_from_session
from corporate.lib.stripe import (
VALID_BILLING_MODALITY_VALUES,
@ -22,11 +23,7 @@ from corporate.lib.stripe import (
from corporate.lib.support import get_support_url
from corporate.models import CustomerPlan, ZulipSponsorshipRequest
from zerver.actions.users import do_change_is_billing_admin
from zerver.decorator import (
require_organization_member,
self_hosting_management_endpoint,
zulip_login_required,
)
from zerver.decorator import require_organization_member, zulip_login_required
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.send_email import FromAddress, send_email

View File

@ -65,7 +65,6 @@ from zerver.models import UserProfile, get_client, get_user_profile_by_api_key
if TYPE_CHECKING:
from django.http.request import _ImmutableQueryDict
from django.shortcuts import render
webhook_logger = logging.getLogger("zulip.zerver.webhooks")
webhook_unsupported_events_logger = logging.getLogger("zulip.zerver.webhooks.unsupported")
@ -75,21 +74,6 @@ ParamT = ParamSpec("ParamT")
ReturnT = TypeVar("ReturnT")
def self_hosting_management_endpoint(
view_func: Callable[Concatenate[HttpRequest, ParamT], HttpResponse]
) -> Callable[Concatenate[HttpRequest, ParamT], HttpResponse]: # nocoverage
@wraps(view_func)
def _wrapped_view_func(
request: HttpRequest, /, *args: ParamT.args, **kwargs: ParamT.kwargs
) -> HttpResponse:
subdomain = get_subdomain(request)
if not settings.DEVELOPMENT or subdomain != settings.SELF_HOSTING_MANAGEMENT_SUBDOMAIN:
return render(request, "404.html", status=404)
return view_func(request, *args, **kwargs)
return _wrapped_view_func
def update_user_activity(
request: HttpRequest, user_profile: UserProfile, query: Optional[str]
) -> None: