2020-09-12 04:18:53 +02:00
|
|
|
from typing import Optional
|
2022-05-12 06:27:31 +02:00
|
|
|
from urllib.parse import urlencode
|
2020-09-12 04:18:53 +02:00
|
|
|
|
2020-08-07 01:09:47 +02:00
|
|
|
import orjson
|
2020-01-29 20:41:23 +01:00
|
|
|
from django.conf import settings
|
2020-09-15 03:04:07 +02:00
|
|
|
from django.contrib.auth.views import redirect_to_login
|
2020-01-29 20:41:23 +01:00
|
|
|
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
2020-05-08 06:37:58 +02:00
|
|
|
from django.template.response import TemplateResponse
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
from zerver.context_processors import get_realm_from_request, latest_info_context
|
2020-09-15 03:04:07 +02:00
|
|
|
from zerver.decorator import add_google_analytics
|
2020-10-22 13:39:55 +02:00
|
|
|
from zerver.lib.github import InvalidPlatform, get_latest_github_release_download_link_for_platform
|
2021-06-10 03:59:43 +02:00
|
|
|
from zerver.lib.subdomains import is_subdomain_root_or_alias
|
2020-01-29 20:41:23 +01:00
|
|
|
from zerver.models import Realm
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
2020-09-12 04:18:53 +02:00
|
|
|
def apps_view(request: HttpRequest, platform: Optional[str] = None) -> HttpResponse:
|
2020-01-29 20:41:23 +01:00
|
|
|
if settings.ZILENCER_ENABLED:
|
2020-05-08 06:37:58 +02:00
|
|
|
return TemplateResponse(
|
|
|
|
request,
|
2021-02-12 08:20:45 +01:00
|
|
|
"zerver/apps.html",
|
2020-05-08 06:37:58 +02:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
return HttpResponseRedirect("https://zulip.com/apps/", status=301)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-10-22 13:39:55 +02:00
|
|
|
def app_download_link_redirect(request: HttpRequest, platform: str) -> HttpResponse:
|
|
|
|
try:
|
|
|
|
download_link = get_latest_github_release_download_link_for_platform(platform)
|
|
|
|
return HttpResponseRedirect(download_link, status=302)
|
|
|
|
except InvalidPlatform:
|
|
|
|
return TemplateResponse(request, "404.html", status=404)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
2020-01-29 20:41:23 +01:00
|
|
|
def plans_view(request: HttpRequest) -> HttpResponse:
|
|
|
|
realm = get_realm_from_request(request)
|
2020-05-14 18:21:23 +02:00
|
|
|
free_trial_days = settings.FREE_TRIAL_DAYS
|
2020-06-09 12:24:32 +02:00
|
|
|
sponsorship_pending = False
|
2021-06-10 03:59:43 +02:00
|
|
|
sponsorship_url = "/upgrade#sponsorship"
|
|
|
|
if is_subdomain_root_or_alias(request):
|
|
|
|
# If we're on the root domain, we make this link first ask you which organization.
|
2022-05-12 06:27:31 +02:00
|
|
|
sponsorship_url = f"/accounts/go/?{urlencode({'next': sponsorship_url})}"
|
2020-10-08 16:22:59 +02:00
|
|
|
realm_on_free_trial = False
|
2020-06-09 12:24:32 +02:00
|
|
|
|
2020-01-29 20:41:23 +01:00
|
|
|
if realm is not None:
|
2021-10-18 23:28:17 +02:00
|
|
|
if realm.plan_type == Realm.PLAN_TYPE_SELF_HOSTED and settings.PRODUCTION:
|
2021-02-12 08:20:45 +01:00
|
|
|
return HttpResponseRedirect("https://zulip.com/plans")
|
2020-01-29 20:41:23 +01:00
|
|
|
if not request.user.is_authenticated:
|
2021-06-15 22:23:45 +02:00
|
|
|
return redirect_to_login(next="/plans")
|
2020-07-15 22:18:32 +02:00
|
|
|
if request.user.is_guest:
|
|
|
|
return TemplateResponse(request, "404.html", status=404)
|
2020-06-09 12:24:32 +02:00
|
|
|
if settings.CORPORATE_ENABLED:
|
2020-10-08 16:22:59 +02:00
|
|
|
from corporate.lib.stripe import is_realm_on_free_trial
|
2020-06-09 12:24:32 +02:00
|
|
|
from corporate.models import get_customer_by_realm
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-06-09 12:24:32 +02:00
|
|
|
customer = get_customer_by_realm(realm)
|
|
|
|
if customer is not None:
|
|
|
|
sponsorship_pending = customer.sponsorship_pending
|
2020-10-08 16:22:59 +02:00
|
|
|
realm_on_free_trial = is_realm_on_free_trial(realm)
|
2020-06-09 12:24:32 +02:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
return TemplateResponse(
|
|
|
|
request,
|
|
|
|
"zerver/plans.html",
|
2021-02-12 08:19:30 +01:00
|
|
|
context={
|
2020-10-08 12:33:49 +02:00
|
|
|
"realm": realm,
|
2021-02-12 08:20:45 +01:00
|
|
|
"free_trial_days": free_trial_days,
|
2020-10-08 16:22:59 +02:00
|
|
|
"realm_on_free_trial": realm_on_free_trial,
|
2021-02-12 08:20:45 +01:00
|
|
|
"sponsorship_pending": sponsorship_pending,
|
2021-06-10 03:59:43 +02:00
|
|
|
"sponsorship_url": sponsorship_url,
|
2021-02-12 08:19:30 +01:00
|
|
|
},
|
2020-05-08 06:37:58 +02:00
|
|
|
)
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
2020-01-29 20:41:23 +01:00
|
|
|
def team_view(request: HttpRequest) -> HttpResponse:
|
2020-04-07 19:27:07 +02:00
|
|
|
if not settings.ZILENCER_ENABLED:
|
2021-02-12 08:20:45 +01:00
|
|
|
return HttpResponseRedirect("https://zulip.com/team/", status=301)
|
2020-04-07 19:27:07 +02:00
|
|
|
|
|
|
|
try:
|
2020-08-07 01:09:47 +02:00
|
|
|
with open(settings.CONTRIBUTOR_DATA_FILE_PATH, "rb") as f:
|
|
|
|
data = orjson.loads(f.read())
|
2020-04-07 19:27:07 +02:00
|
|
|
except FileNotFoundError:
|
2021-02-12 08:20:45 +01:00
|
|
|
data = {"contributors": {}, "date": "Never ran."}
|
2020-01-29 20:41:23 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
return TemplateResponse(
|
2020-01-29 20:41:23 +01:00
|
|
|
request,
|
2021-02-12 08:20:45 +01:00
|
|
|
"zerver/team.html",
|
2020-01-29 20:41:23 +01:00
|
|
|
context={
|
2021-02-12 08:20:45 +01:00
|
|
|
"page_params": {
|
|
|
|
"contributors": data["contributors"],
|
2020-01-29 20:41:23 +01:00
|
|
|
},
|
2021-02-12 08:20:45 +01:00
|
|
|
"date": data["date"],
|
2020-01-29 20:41:23 +01:00
|
|
|
},
|
|
|
|
)
|
2020-01-29 00:05:06 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
|
|
|
def landing_view(request: HttpRequest, template_name: str) -> HttpResponse:
|
2021-10-16 01:12:43 +02:00
|
|
|
return TemplateResponse(request, template_name, latest_info_context())
|
2020-05-08 06:37:58 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-05-08 06:37:58 +02:00
|
|
|
@add_google_analytics
|
|
|
|
def hello_view(request: HttpRequest) -> HttpResponse:
|
2021-02-12 08:20:45 +01:00
|
|
|
return TemplateResponse(request, "zerver/hello.html", latest_info_context())
|