From b473ff54ce05b6e9871eee3ce374e349b4c63b05 Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Thu, 24 Aug 2017 12:58:44 +0500 Subject: [PATCH] Show realm deactivation notice for login/register. Fixes #6247 --- zerver/views/auth.py | 6 +++++- zerver/views/registration.py | 16 ++++++++++++++++ zproject/urls.py | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/zerver/views/auth.py b/zerver/views/auth.py index fdf1ff70c9..0c77cf8a63 100644 --- a/zerver/views/auth.py +++ b/zerver/views/auth.py @@ -32,7 +32,7 @@ from zerver.lib.validator import validate_login_email from zerver.models import PreregistrationUser, UserProfile, remote_user_to_email, Realm, \ get_realm from zerver.views.registration import create_preregistration_user, get_realm_from_request, \ - redirect_and_log_into_subdomain + redirect_and_log_into_subdomain, redirect_to_deactivation_notice from zerver.signals import email_on_new_login from zproject.backends import password_auth_enabled, dev_auth_enabled, \ github_auth_enabled, google_auth_enabled, ldap_auth_enabled @@ -465,6 +465,10 @@ def login_page(request, **kwargs): redirect_url = reverse('zerver.views.registration.find_my_team') return HttpResponseRedirect(redirect_url) + realm = get_realm_from_request(request) + if realm and realm.deactivated: + return redirect_to_deactivation_notice() + extra_context = kwargs.pop('extra_context', {}) if dev_auth_enabled(): if 'new_realm' in request.POST: diff --git a/zerver/views/registration.py b/zerver/views/registration.py index 323ea57bb4..044d540e2e 100644 --- a/zerver/views/registration.py +++ b/zerver/views/registration.py @@ -340,9 +340,25 @@ def get_realm_from_request(request): realm_str = None return get_realm(realm_str) +def show_deactivation_notice(request): + # type: (HttpRequest) -> HttpResponse + realm = get_realm_from_request(request) + if realm and realm.deactivated: + return render(request, "zerver/deactivated.html", + context={"deactivated_domain_name": realm.name}) + + return HttpResponseRedirect(reverse('zerver.views.auth.login_page')) + +def redirect_to_deactivation_notice(): + # type: () -> HttpResponse + return HttpResponseRedirect(reverse('zerver.views.registration.show_deactivation_notice')) + def accounts_home(request): # type: (HttpRequest) -> HttpResponse realm = get_realm_from_request(request) + if realm and realm.deactivated: + return redirect_to_deactivation_notice() + if request.method == 'POST': form = HomepageForm(request.POST, realm=realm) if form.is_valid(): diff --git a/zproject/urls.py b/zproject/urls.py index 9fe727b7c6..de81a28e2a 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -95,6 +95,9 @@ i18n_urls = [ name='django.contrib.auth.views.password_reset_confirm'), url(r'^accounts/password/done/$', password_reset_complete, {'template_name': 'zerver/reset_done.html'}), + url(r'^accounts/deactivated/', + zerver.views.registration.show_deactivation_notice, + name='zerver.views.registration.show_deactivation_notice'), # Avatar url(r'^avatar/(?P[\S]+)?/(?P[\S]+)?', zerver.views.users.avatar, name='zerver.views.users.avatar'),