diff --git a/course/auth.py b/course/auth.py index fe10efe4aec5adc55ff1e23c1dfb9e3859a57eeb..70e3ba2cc0db1fbe92ba9bc1d0f3558e30f1c1bd 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 25d933366a13610e9e8a49ef1dc8f25ed465bfd8..f16d5936946d976613187600ce67f98a1386c120 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 9c77b46221949668328e4e8bf3a4e71a1064deb9..c6a72e273214be2a9ced30aba924ce810bb86d17 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 }}).