From 6ec1336f6872b15cff5e55aee5c32215e0d6e512 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 14 Sep 2016 11:14:10 -0500 Subject: [PATCH] Make fake facility and impersonation page headers optional --- course/auth.py | 12 ++++++++++++ course/views.py | 16 +++++++++++++++- relate/templates/base-page-top.html | 4 ++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/course/auth.py b/course/auth.py index fe10efe4..70e3ba2c 100644 --- a/course/auth.py +++ b/course/auth.py @@ -159,6 +159,14 @@ class ImpersonateForm(StyledForm): widget=UserSearchWidget(), label=_("User")) + self.fields["add_impersonation_header"] = forms.BooleanField( + required=False, + initial=True, + label=_("Add impersonation header"), + help_text=_("Add impersonation header to every page rendered " + "while impersonating, as a reminder that impersonation " + "is in progress.")) + self.helper.add_input(Submit("submit", _("Impersonate"))) @@ -177,6 +185,8 @@ def impersonate(request): if may_impersonate(cast(User, request.user), cast(User, impersonee)): request.session['impersonate_id'] = impersonee.id + request.session['relate_impersonation_header'] = form.cleaned_data[ + "add_impersonation_header"] # Because we'll likely no longer have access to this page. return redirect("relate-home") @@ -229,6 +239,8 @@ def impersonation_context_processor(request): return { "currently_impersonating": hasattr(request, "relate_impersonate_original_user"), + "add_impersonation_header": + request.session.get("relate_impersonation_header", True), } # }}} diff --git a/course/views.py b/course/views.py index 25d93336..f16d5936 100644 --- a/course/views.py +++ b/course/views.py @@ -474,6 +474,14 @@ class FakeFacilityForm(StyledForm): help_text=_("More (non-predefined) facility names, separated " "by commas, which would like to pretend to be in")) + self.fields["add_pretend_facilities_header"] = forms.BooleanField( + required=False, + initial=True, + label=_("Add fake facililities header"), + help_text=_("Add a page header to every page rendered " + "while pretending to be in a facility, as a reminder " + "that this pretending is in progress.")) + self.helper.add_input( # Translators: "set" fake facility. Submit("set", _("Set"))) @@ -499,6 +507,8 @@ def set_pretend_facilities(request): if s.strip()]) request.session["relate_pretend_facilities"] = pretend_facilities + request.session["relate_pretend_facilities_header"] = \ + form.cleaned_data["add_pretend_facilities_header"] else: request.session.pop("relate_pretend_facilities", None) @@ -507,7 +517,9 @@ def set_pretend_facilities(request): form = FakeFacilityForm({ "facilities": [], "custom_facilities": ",".join( - request.session["relate_pretend_facilities"]) + request.session["relate_pretend_facilities"]), + "add_pretend_facilities_header": + request.session["relate_pretend_facilities_header"], }) else: form = FakeFacilityForm() @@ -522,6 +534,8 @@ def pretend_facilities_context_processor(request): return { "pretend_facilities": request.session.get( "relate_pretend_facilities", []), + "add_pretend_facilities_header": + request.session.get("relate_pretend_facilities_header", True), } # }}} diff --git a/relate/templates/base-page-top.html b/relate/templates/base-page-top.html index 9c77b462..c6a72e27 100644 --- a/relate/templates/base-page-top.html +++ b/relate/templates/base-page-top.html @@ -43,7 +43,7 @@ {% endif %} -{% if pretend_facilities %} +{% if pretend_facilities and add_pretend_facilities_header %}
{% blocktrans trimmed with facilities=pretend_facilities|join:", " %} @@ -57,7 +57,7 @@
{% endif %} -{% if currently_impersonating %} +{% if currently_impersonating and add_impersonation_header %}
{% trans "Now impersonating" %} {{ user.get_full_name }} ({{ user.username }} - {{ user.email }}). -- GitLab