Skip to content

Commit ee77c63

Browse files
committed
portico: Use /help/ style pages for displaying policies.
This replaces the TERMS_OF_SERVICE and PRIVACY_POLICY settings with just a POLICIES_DIRECTORY setting, in order to support settings (like Zulip Cloud) where there's more policies than just those two. With minor changes by Eeshan Garg.
1 parent 95854d9 commit ee77c63

27 files changed

+205
-190
lines changed

docs/overview/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ log][commit-log] for an up-to-date list of raw changes.
3434
- This release contains a migration, `0009_confirmation_expiry_date_backfill`,
3535
that can take several minutes to run on a server with millions of
3636
messages of history.
37+
- The `TERMS_OF_SERVICE` and `PRIVACY_POLICY` settings have been
38+
removed in favor of a system that supports additional policy
39+
documents, such as a code of conduct. See the [updated
40+
documentation](../production/settings.md) for the new system.
3741

3842
#### Full feature changelog
3943

docs/production/authentication-methods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ prefills that value in the new account creation form, but gives the
850850
user the opportunity to edit it before submitting. When `True`, Zulip
851851
assumes the name is correct, and new users will not be presented with
852852
a registration form unless they need to accept Terms of Service for
853-
the server (i.e. `TERMS_OF_SERVICE=True`).
853+
the server (i.e. `TERMS_OF_SERVICE_VERSION` is set).
854854

855855
## Adding more authentication backends
856856

docs/production/settings.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,25 @@ and configure this service.
8686
### Terms of Service and Privacy policy
8787

8888
Zulip allows you to configure your server's Terms of Service and
89-
Privacy Policy pages (`/terms` and `/privacy`, respectively). You can
90-
use the `TERMS_OF_SERVICE` and `PRIVACY_POLICY` settings to configure
91-
the path to your server's policies. The syntax is Markdown (with
92-
support for included HTML). A good approach is to use paths like
93-
`/etc/zulip/terms.md`, so that it's easy to back up your policy
94-
configuration along with your other Zulip server configuration.
89+
Privacy Policy pages (`/terms` and `/privacy`, respectively).
90+
91+
You can configure this using the `POLICIES_DIRECTORY` setting. We
92+
recommend using `/etc/zulip/policies`, so that your policies are
93+
naturally backed up with the server's other configuration. Just place
94+
Markdown files named `terms.md` and `privacy.md` in that directory,
95+
and set `TERMS_OF_SERVICE_VERSION` to `1.0` to enable this feature.
96+
97+
You can place additional files in this directory to document
98+
additional policies; if you do so, you may want to:
99+
100+
- Create a Markdown file `sidebar_index.md` listing the pages in your
101+
policies site; this generates the policies site navigation.
102+
- Create a Markdown file `missing.md` with custom content for 404s in
103+
this directory.
104+
105+
Please make clear in these pages what organization is hosting your
106+
Zulip server, so that nobody could be confused that your policies are
107+
the policies for Zulip Cloud.
95108

96109
### Miscellaneous server settings
97110

templates/corporate/policies/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Terms and policies
2+
3+
* [Terms of Service](/policies/terms)
4+
* [Privacy Policy](/policies/privacy)
5+
* [Rules of Use](/policies/rules)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No such page.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## [Terms of Service](/policies/terms)
2+
## [Privacy Policy](/policies/privacy)
File renamed without changes.

templates/zerver/documentation_main.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@
1010
<div class="app help terms-page inline-block{% if page_is_help_center %} help-center{% endif %}{% if page_is_api_center %} api-center{% endif %}">
1111
<div class="sidebar">
1212
<div class="content">
13+
{% if not page_is_policy_center %}
1314
<h1><a href="https://zulip.com" class="no-underline">Zulip homepage</a></h1>
1415
<h1><a href="{{ doc_root }}" class="no-underline">{{ doc_root_title }} home</a></h1>
16+
{% endif %}
17+
18+
{% if page_is_policy_center %}
19+
{{ render_markdown_path(sidebar_index, pure_markdown=True) }}
20+
{% else %}
1521
{{ render_markdown_path(sidebar_index, api_uri_context) }}
22+
{% endif %}
23+
24+
{% if not page_is_policy_center %}
1625
<h1 class="home-link"><a href="/" class="no-underline">Back to Zulip</a></h1>
26+
{% endif %}
1727
</div>
1828
</div>
1929

@@ -23,7 +33,11 @@ <h1 class="home-link"><a href="/" class="no-underline">Back to Zulip</a></h1>
2333

2434
<div class="markdown">
2535
<div class="content">
36+
{% if page_is_policy_center %}
37+
{{ render_markdown_path(article, pure_markdown=True) }}
38+
{% else %}
2639
{{ render_markdown_path(article, api_uri_context) }}
40+
{% endif %}
2741

2842
<div id="footer" class="documentation-footer">
2943
<hr />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This server is an installation of [Zulip](https://zulip.com), open
2+
source software for team collaboration.
3+
4+
This installation of Zulip has not been configured to display its
5+
policies. You can contact its administrators using the email address
6+
displayed below.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## No policies configured

templates/zerver/portico-header.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
{% if page_is_api_center %}
1818
<span class="light"> | <a href="{{ root_domain_uri }}/api/">{{ doc_root_title }}</a></span>
1919
{% endif %}
20+
{% if page_is_policy_center %}
21+
<span class="light"> | <a href="{{ root_domain_uri }}/policies/">{{ doc_root_title }}</a></span>
22+
{% endif %}
2023
</div>
2124
{% endif %}
2225
</div>

templates/zerver/privacy.html

Lines changed: 0 additions & 38 deletions
This file was deleted.

templates/zerver/terms.html

Lines changed: 0 additions & 35 deletions
This file was deleted.

zerver/context_processors.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ def get_apps_page_url() -> str:
8181
return "https://zulip.com/apps/"
8282

8383

84+
def is_isolated_page(request: HttpRequest) -> bool:
85+
"""Accept a GET param `?nav=no` to render an isolated, navless page."""
86+
return request.GET.get("nav") == "no"
87+
88+
8489
def zulip_default_context(request: HttpRequest) -> Dict[str, Any]:
8590
"""Context available to all Zulip Jinja2 templates that have a request
8691
passed in. Designed to provide the long list of variables at the
@@ -145,8 +150,7 @@ def zulip_default_context(request: HttpRequest) -> Dict[str, Any]:
145150
"custom_logo_url": settings.CUSTOM_LOGO_URL,
146151
"register_link_disabled": register_link_disabled,
147152
"login_link_disabled": login_link_disabled,
148-
"terms_of_service": settings.TERMS_OF_SERVICE,
149-
"privacy_policy": settings.PRIVACY_POLICY,
153+
"terms_of_service": settings.TERMS_OF_SERVICE_VERSION is not None,
150154
"login_url": settings.HOME_NOT_LOGGED_IN,
151155
"only_sso": settings.ONLY_SSO,
152156
"external_host": settings.EXTERNAL_HOST,
@@ -172,6 +176,7 @@ def zulip_default_context(request: HttpRequest) -> Dict[str, Any]:
172176
"platform": RequestNotes.get_notes(request).client_name,
173177
"allow_search_engine_indexing": allow_search_engine_indexing,
174178
"landing_page_navbar_message": settings.LANDING_PAGE_NAVBAR_MESSAGE,
179+
"is_isolated_page": is_isolated_page(request),
175180
"default_page_params": default_page_params,
176181
}
177182

zerver/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
126126
del kwargs["realm_creation"]
127127

128128
super().__init__(*args, **kwargs)
129-
if settings.TERMS_OF_SERVICE:
129+
if settings.TERMS_OF_SERVICE_VERSION is not None:
130130
self.fields["terms"] = forms.BooleanField(required=True)
131131
self.fields["realm_name"] = forms.CharField(
132132
max_length=Realm.MAX_REALM_NAME_LENGTH, required=self.realm_creation

zerver/tests/test_auth_backends.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ def stage_two_of_registration(
14161416

14171417
self.assertFalse(user_profile.has_usable_password())
14181418

1419-
@override_settings(TERMS_OF_SERVICE=None)
1419+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
14201420
def test_social_auth_registration(self) -> None:
14211421
"""If the user doesn't exist yet, social auth can be used to register an account"""
14221422
@@ -1431,7 +1431,7 @@ def test_social_auth_registration(self) -> None:
14311431
result, realm, subdomain, email, name, name, self.BACKEND_CLASS.full_name_validated
14321432
)
14331433

1434-
@override_settings(TERMS_OF_SERVICE=None)
1434+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
14351435
def test_social_auth_mobile_registration(self) -> None:
14361436
14371437
name = "Full Name"
@@ -1458,7 +1458,7 @@ def test_social_auth_mobile_registration(self) -> None:
14581458
mobile_flow_otp=mobile_flow_otp,
14591459
)
14601460

1461-
@override_settings(TERMS_OF_SERVICE=None)
1461+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
14621462
def test_social_auth_desktop_registration(self) -> None:
14631463
14641464
name = "Full Name"
@@ -1485,7 +1485,7 @@ def test_social_auth_desktop_registration(self) -> None:
14851485
desktop_flow_otp=desktop_flow_otp,
14861486
)
14871487

1488-
@override_settings(TERMS_OF_SERVICE=None)
1488+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
14891489
def test_social_auth_registration_invitation_exists(self) -> None:
14901490
"""
14911491
This tests the registration flow in the case where an invitation for the user
@@ -1507,7 +1507,7 @@ def test_social_auth_registration_invitation_exists(self) -> None:
15071507
result, realm, subdomain, email, name, name, self.BACKEND_CLASS.full_name_validated
15081508
)
15091509

1510-
@override_settings(TERMS_OF_SERVICE=None)
1510+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
15111511
def test_social_auth_with_invalid_multiuse_invite(self) -> None:
15121512
15131513
name = "Full Name"
@@ -1528,7 +1528,7 @@ def test_social_auth_with_invalid_multiuse_invite(self) -> None:
15281528
self.assertEqual(result.status_code, 404)
15291529
self.assert_in_response("Whoops. The confirmation link is malformed.", result)
15301530

1531-
@override_settings(TERMS_OF_SERVICE=None)
1531+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
15321532
def test_social_auth_registration_using_multiuse_invite(self) -> None:
15331533
"""If the user doesn't exist yet, social auth can be used to register an account"""
15341534
@@ -1628,7 +1628,7 @@ def test_social_auth_registration_without_is_signup_closed_realm(self) -> None:
16281628
result,
16291629
)
16301630

1631-
@override_settings(TERMS_OF_SERVICE=None)
1631+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
16321632
def test_social_auth_with_ldap_populate_registration_from_confirmation(self) -> None:
16331633
self.init_default_ldap_database()
16341634
@@ -1691,7 +1691,7 @@ def test_social_auth_with_ldap_populate_registration_from_confirmation(self) ->
16911691
log_warn.output, [f"WARNING:root:New account email {email} could not be found in LDAP"]
16921692
)
16931693

1694-
@override_settings(TERMS_OF_SERVICE=None)
1694+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
16951695
def test_social_auth_with_ldap_auth_registration_from_confirmation(self) -> None:
16961696
"""
16971697
This test checks that in configurations that use the LDAP authentication backend
@@ -1784,7 +1784,7 @@ def test_social_auth_complete_when_base_exc_is_raised(self) -> None:
17841784
self.assertEqual(result.status_code, 302)
17851785
self.assertIn("login", result.url)
17861786

1787-
@override_settings(TERMS_OF_SERVICE=None)
1787+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
17881788
def test_social_auth_invited_as_admin_but_expired(self) -> None:
17891789
iago = self.example_user("iago")
17901790
email = self.nonreg_email("alice")
@@ -2167,7 +2167,7 @@ def test_saml_auth_enabled(self) -> None:
21672167
result,
21682168
)
21692169

2170-
@override_settings(TERMS_OF_SERVICE=None)
2170+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
21712171
def test_social_auth_registration_auto_signup(self) -> None:
21722172
"""
21732173
Verify that with SAML auto signup enabled, a user coming from the /login page
@@ -3335,7 +3335,7 @@ def get_account_data_dict(self, email: str, name: str) -> Dict[str, Any]:
33353335
family_name=name.split(" ")[1],
33363336
)
33373337

3338-
@override_settings(TERMS_OF_SERVICE=None)
3338+
@override_settings(TERMS_OF_SERVICE_VERSION=None)
33393339
def test_social_auth_registration_auto_signup(self) -> None:
33403340
"""
33413341
The analogue of the auto_signup test for SAML.

0 commit comments

Comments
 (0)