zulip/templates/zerver
Steve Howell d9740045a5 refactor: Eliminate checks in build_stream_dict_for_sub.
We eliminate some redundant checks.

We also consistently provide a `subscribers` field
in our stream data with `[]`, even if our users
can't access subscribers.  We therefore bump
the API version and tweak the docs.  (See further
down for a detailed justification of the change.)

Even though it is sometimes fine to have redundant code
that is defensive in nature, some upcoming changes are gonna
move subscriber-related logic out of build_stream_dict_for_sub
for certain codepaths as part of our effort to streamline
the payload for subscribers within page_params.

So we can't rely on the code that I removed here
inside of build_stream_dict_for_sub.

Anyway, it makes more sense to do these checks explicitly
in the validate function.

The code in build_stream_dict_for_sub was almost effectively
a noop, since the validation function was already preventing
us from getting subscriber info.  The only difference it
made was sometimes converting `[]` to `None`, and then
subsequently omitting the subscribers field.

Neither ZT nor the webapp make any distinction between
`[]` or <missing key> for the `subscribers` data in
`page_params`.

The webapp has had this code for a long time (and now
equivalent code elsewhere in this PR):

    if (!Object.prototype.hasOwnProperty.call(sub, "subscribers")) {
        sub.subscribers = new LazySet([]);
    }

The webapp calculates access based on booleans, anyway:

    sub.can_access_subscribers =
        page_params.is_admin || sub.subscribed ||
        (!page_params.is_guest && !sub.invite_only);

And ZT would choke if `subscribers` were missing, except that
it never gets to the relevant code due to other checks:

    def get_other_subscribers_in_stream(<snip>):
        assert stream_id is not None or stream_name is not None

        if stream_id:
            assert self.is_user_subscribed_to_stream(stream_id)

            return [sub
                    for sub in self.stream_dict[stream_id]['subscribers']
                    if sub != self.user_id]
        else:
            return [sub
                    for _, stream in self.stream_dict.items()
                    for sub in stream['subscribers']
                    if stream['name'] == stream_name
                    if sub != self.user_id]

You could make a semantic argument that we should prefer
<missing key> to `[]` when subscribers aren't even available, but
we have precedent from the way that `bulk_get_subscriber_user_ids`
has traditionally populated its result:

    result: Dict[int, List[int]] =
        {stream["id"]: [] for stream in stream_dicts}

If we changed `stream_dicts` to `target_stream_dicts` we
would faciliate a move toward `None`, but it would just cause
headaches for other server code as well as the frontends
(which, to reiterate, already prefer the empty array
for convenience).
2021-01-21 15:04:07 -08:00
..
api refactor: Eliminate checks in build_stream_dict_for_sub. 2021-01-21 15:04:07 -08:00
app markdown_help: Make spoiler-button work by changing its tag. 2021-01-21 14:32:13 -08:00
archive templates: Fix missing quoting of attributes in HTML templates. 2020-06-16 23:35:39 -07:00
emails emails: Pass help link as variable in password reset email. 2020-10-30 11:50:30 -07:00
for docs: Recommend Matterbridge for integration with IRC/Matrix/Slack. 2020-12-01 14:12:05 -08:00
help slack-import: Explain current implementation about threads. 2021-01-12 10:21:32 -08:00
include portico: Add return to login button to password reset end. 2019-11-18 12:21:40 -08:00
integrations docs: Fix more capitalization issues. 2020-10-23 11:46:55 -07:00
tests/markdown
accounts_accept_terms.html urls: Remove unused URL names and shorten others. 2020-09-22 10:46:28 -07:00
accounts_home.html auth: Make apple log in and sign up buttons consistent with others. 2020-06-18 13:06:10 -07:00
accounts_send_confirm.html
apple-error.md docs: Add auth backend configuration is optional. 2020-12-17 18:11:28 -08:00
apps.html CVE-2020-14194: Use noopener/noreferrer for external links. 2020-06-16 23:35:39 -07:00
base.html meta tags: Use open graph titles/descriptions. 2020-08-14 10:58:18 -07:00
billing_nav.html logo: Update Zulip logo. 2020-07-16 01:37:08 -07:00
close_window.html compose: Rewrite Zoom video call integration to use OAuth. 2020-06-03 16:39:12 -07:00
compare.html plans: Address some frequently asked questions. 2020-01-28 14:07:28 -08:00
config_error.html auth: Render config error page on configuration error. 2020-09-25 16:16:17 -07:00
confirm_continue_registration.html templates: Use `<hr>` and `<br>` consistently. 2020-04-28 17:05:48 -07:00
confirmation_link_expired_error.html invitations: Revoke remaining invitations after user registers. 2020-05-27 15:37:16 -07:00
create_realm.html docs: Remove HipChat migration guide. 2020-12-23 15:43:13 +05:30
deactivated.html accounts/deactivated: Show deactivated_redirect url if present 2020-12-14 21:04:52 -08:00
desktop_login.html desktop-login: Use zulip design styles for desktop-login. 2020-05-10 23:05:19 -07:00
desktop_redirect.html desktop-login: Use zulip design styles for desktop-login. 2020-05-10 23:05:19 -07:00
dev-not-supported-error.md
dev_env_email_access_details.html
dev_login.html urls: Remove unused URL names and shorten others. 2020-09-22 10:46:28 -07:00
dev_tools.html dev_tools: Fix dev-secrets.conf path. 2020-12-08 18:11:14 -08:00
digest_base.html templates: Use just one webpack entry point per page. 2019-10-28 15:53:15 -07:00
documentation_main.html docs: Fix more capitalization issues. 2020-10-23 11:46:55 -07:00
email.html email_log: Show reply_to address if present. 2020-07-14 00:36:31 -07:00
email_log.html docs: Clean up email testing docs a bit more. 2020-10-30 12:15:27 -07:00
faq.html plans: Mention the request sponsorship feature. 2020-08-24 18:31:48 -07:00
features.html hipchat_import: Remove tool from codebase. 2020-12-23 08:28:49 -08:00
find_account.html HTML validation: Fix login page HTML errors. 2019-07-18 11:56:15 -07:00
footer.html help: Add article for how to get support. 2020-05-04 09:38:36 -07:00
for-companies.html portico: Typographical nitpicking. 2020-03-17 16:53:46 -07:00
for-open-source.html docs: Capitalize Markdown consistently. 2020-08-11 10:23:06 -07:00
for-research.html portico: Add first a quote to /for/research. 2020-05-20 17:47:01 -07:00
for-working-groups-and-communities.html portico: Typographical nitpicking. 2020-03-17 16:53:46 -07:00
github-error.md docs: Add auth backend configuration is optional. 2020-12-17 18:11:28 -08:00
gitlab-error.md docs: Add auth backend configuration is optional. 2020-12-17 18:11:28 -08:00
google-error.md docs: Add auth backend configuration is optional. 2020-12-17 18:11:28 -08:00
gradients.html
hello.html docs: Remove HipChat migration guide. 2020-12-23 15:43:13 +05:30
history.html docs: Fix various capitalization errors. 2020-08-11 10:25:52 -07:00
insecure_desktop_app.html CVE-2020-14194: Use noopener/noreferrer for external links. 2020-06-16 23:35:39 -07:00
invalid_email.html
invalid_realm.html templates: Use `<hr>` and `<br>` consistently. 2020-04-28 17:05:48 -07:00
landing_nav.html logo: Update Zulip logo. 2020-07-16 01:37:08 -07:00
log_into_subdomain_token_invalid.html auth: Show a user-facing page when wrong token given to /subdomain/. 2020-04-05 12:29:09 -07:00
login.html Revert "login: Fix alignment of error message in login form." 2020-10-18 14:06:20 -07:00
meta_tags.html meta tags: Use open graph titles/descriptions. 2020-08-14 10:58:18 -07:00
plans.html billing: Add option to request a sponsorship in /upgrade. 2020-07-01 16:45:38 -07:00
portico-header-dropdown.html
portico-header.html docs: Fix more capitalization issues. 2020-10-23 11:46:55 -07:00
portico-help.html
portico.html portico: Add `isolated_page` context flag, to suppress site nav. 2020-01-29 11:32:27 -08:00
portico_signup.html templates: Use just one webpack entry point per page. 2019-10-28 15:53:15 -07:00
privacy.html templates: Use just one webpack entry point per page. 2019-10-28 15:53:15 -07:00
realm_creation_failed.html i18n: Don't hardcode zulip.com URLs in translation tags. 2020-06-11 11:09:42 -07:00
realm_reactivation.html
realm_reactivation_link_error.html
realm_redirect.html CVE-2020-14194: Use noopener/noreferrer for external links. 2020-06-16 23:35:39 -07:00
register.html urls: Remove unused URL names and shorten others. 2020-09-22 10:46:28 -07:00
reset.html urls: Remove unused URL names and shorten others. 2020-09-22 10:46:28 -07:00
reset_confirm.html reset_password: Change reset password page heading. 2020-09-25 16:24:18 -07:00
reset_done.html urls: Remove unused URL names and shorten others. 2020-09-22 10:46:28 -07:00
reset_emailed.html portico: Add return to login button to password reset end. 2019-11-18 12:21:40 -08:00
security.html templates: Use just one webpack entry point per page. 2019-10-28 15:53:15 -07:00
security.md docs: Link session length and idle timeouts to GitHub search. 2020-11-05 10:07:43 -08:00
social_auth_select_email.html docs: Correct “login” as a verb to “log in”. 2020-08-11 10:25:53 -07:00
team.html js: Replace underscore with lodash and remove it from globals. 2020-07-26 16:12:06 -07:00
terms.html templates: Use just one webpack entry point per page. 2019-10-28 15:53:15 -07:00
unsubscribe_link_error.html
unsubscribe_success.html
unsupported_browser.html i18n: Don't hardcode zulip.com URLs in translation tags. 2020-06-11 11:09:42 -07:00
why-zulip.html templates: Use just one webpack entry point per page. 2019-10-28 15:53:15 -07:00
why-zulip.md hipchat_import: Remove tool from codebase. 2020-12-23 08:28:49 -08:00
zulipchat_migration_tos.html docs: Update most remaining references to zulipchat.com. 2020-06-08 18:10:45 -07:00