mirror of https://github.com/zulip/zulip.git
decorator: Move self_hosting_management_endpoint wrapper to corporate.
This commit is contained in:
parent
c79d116f8c
commit
354330d81b
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue